sspiff / lms-plugin-pyrrha

Pyrrha - Daughter of Pandora
GNU General Public License v2.0
13 stars 4 forks source link

Station sort order #2

Closed ZubaZ21 closed 6 months ago

ZubaZ21 commented 6 months ago

With the understanding that this is a work in progress . . .

My wife is likely happy because some of the stations I've added to my account are at the top, but the list is not sorted alphabetically, nor by recently played.

Perhaps it's in the order of most recently created?

If so, that might not be optimal.

pyrrha_104419

sspiff commented 6 months ago

Currently, the plugin just populates the station list in the order they are received from the API. I agree that it is not optimal, but probably need to offer some options? Alpha, last played, any other possible sort modes?

ZubaZ21 commented 6 months ago

Pandora provides for alpha and most recent and those would be more than sufficient I think. After those options, the only thing I might focus on is drag and drop sorting.

sspiff commented 6 months ago

I also like the idea of an option to shove the service-created/recommended stations (quickmix, thumbprint) to the bottom as I never play those.

ZubaZ21 commented 6 months ago

After being a Pandora subscriber since 2006 and pretty finely tuning my stations, I LOVE quickmix (but never use thumbprint). My solution is to have Quickmix pinned to the LMS favorites so I am mostly unconcerned where they land in Pyrrha's list.

I support options though!

sspiff commented 6 months ago

Looks like the older API that Pyrrha is using does not provide a last played date. We may be stuck with alpha by station name and station creation date for now.

nabertrand commented 6 months ago

It looks like Pandora added some bot-detection protection to the REST API, so logging in programmatically no longer works. However, you are still able to use the JWT provided by the JSON API to interact with the REST API. You still need to get and set some cookies and headers before you can use the REST API, but once you do that the /v1/station/getStations REST API endpoint does return the lastPlayed time:

{
  "totalStations": 54,
  "sortedBy": "lastPlayedTime",
  "index": 0,
  "stations": [
    {
      "stationId": "3714709736804441063",
      "stationFactoryPandoraId": "SF:18245:1382",
      "pandoraId": "ST:0:3714709736804441063",
      "name": "Indie 500 Radio",
      "art": [
        {
          "url": "https://content-images.p-cdn.com/images/df/26/79/d2/ac784a56971e13e4a42d80dd/_90W_90H.jpg",
          "size": 90
        },
        {
          "url": "https://content-images.p-cdn.com/images/df/26/79/d2/ac784a56971e13e4a42d80dd/_130W_130H.jpg",
          "size": 130
        },
        {
          "url": "https://content-images.p-cdn.com/images/df/26/79/d2/ac784a56971e13e4a42d80dd/_500W_500H.jpg",
          "size": 500
        },
        {
          "url": "https://content-images.p-cdn.com/images/df/26/79/d2/ac784a56971e13e4a42d80dd/_640W_640H.jpg",
          "size": 640
        },
        {
          "url": "https://content-images.p-cdn.com/images/df/26/79/d2/ac784a56971e13e4a42d80dd/_1080W_1080H.jpg",
          "size": 1080
        }
      ],
      "dateCreated": "2017-08-21T18:55:46.534Z",
      "lastPlayed": "2024-02-15T14:34:13.013Z",
nabertrand commented 6 months ago

Here's a bash POC snippet:

#!/bin/bash
API_BASE=https://www.pandora.com/api/v1
AUTH_TOKEN="<token from JSON API login>"
curl --cookie-jar cookies.txt \
     --url "https://www.pandora.com" \
     --head
CSRF_TOKEN=$(grep csrftoken cookies.txt|awk '{print $7}')
curl --request POST \
     --url "${API_BASE}/station/getStations" \
     --header "X-CsrfToken: ${CSRF_TOKEN}" \
     --header "X-AuthToken: ${AUTH_TOKEN}" \
     --header 'Content-Type: application/json;charset=utf-8' \
     --cookie cookies.txt \
     --cookie-jar cookies.txt \
     --verbose | jq .
sspiff commented 6 months ago

That's some fine work!

nabertrand commented 6 months ago

I have a basic REST API getStations POC at https://github.com/sspiff/lms-plugin-pyrrha/compare/asyncio...nabertrand:lms-plugin-pyrrha:restapi?expand=1. Would you like me to continue investigating adding the ability to sort stations?

sspiff commented 6 months ago

I have a basic REST API getStations POC at https://github.com/sspiff/lms-plugin-pyrrha/compare/asyncio...nabertrand:lms-plugin-pyrrha:restapi?expand=1. Would you like me to continue investigating adding the ability to sort stations?

Yeah, that'd be great! Here are some notes I took previously on this:

nabertrand commented 6 months ago

See https://github.com/sspiff/lms-plugin-pyrrha/pull/20