Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scrobbling to youtube music not reflected in Recent History #58

Open
kmac opened this issue May 16, 2022 · 8 comments
Open

Scrobbling to youtube music not reflected in Recent History #58

kmac opened this issue May 16, 2022 · 8 comments

Comments

@kmac
Copy link
Contributor

kmac commented May 16, 2022

The scrobbling code seems to be working as implemented, however nothing shows up in Recent History.

We get a 204 from /api/stats/playback:

DEBUG    2022-05-16 14:06:56,735 [1822438:YTMusicBackend-7 (_actor_loop)] mopidy_ytmusic 204 code from
'https://s.youtube.com/api/stats/playback?cl=...&docid=...&ei=...&fexp=...&ns=y│t&list=...&el=detailpage&len=643&of=-...&cpn=.&
referrer=https%3A%2F%2Fmusic.youtube.com&ver=2'

I suppose it's possible the API/mechanism changed for updating? Are others seeing the same thing?

@dionorgua
Copy link

@impliedchaos
Copy link
Collaborator

impliedchaos commented Sep 16, 2022

@kmac - A 204 is probably what we should get back. I've been swamped with work and haven't had a chance to look at this. I'll see if I can soon.

@dionorgua - the pass in the function lets the function in backend.py handle it. It's a weirdly confusing way to do it, but it's how it was done in the Google Play Music backend that I was stealing logic from, so I left it. 😅
https://github.com/OzymandiasTheGreat/mopidy-ytmusic/blob/master/mopidy_ytmusic/backend.py#L161

@impliedchaos
Copy link
Collaborator

Also, if I do manage to get it working again (or someone beats me to it 🙏), we should probably discuss with @sigma67 to put it in ytmusicapi instead. There're other history manipulation functions in there already.

@sigma67
Copy link

sigma67 commented Sep 19, 2022

Very much open to a PR, this one's just flown under the radar a bit.

impliedchaos added a commit that referenced this issue Nov 29, 2022
@impliedchaos
Copy link
Collaborator

This should finally be fixed in 0.3.8

@sigma67
Copy link

sigma67 commented Nov 30, 2022

So I've looked at the code and thought about how to implement this in ytmusicapi, but it seems it's pretty much identical to get_song. The only thing that's missing is the CPN in the request?

@impliedchaos
Copy link
Collaborator

impliedchaos commented Nov 30, 2022

The CPN doesn't even matter for the player API call (just the tracking URL call). I only wrote it like this so I could get the playbackTracking object that get_song skips. If it was added to the list of keys in get_song, then this could be much simpler like:

import random
import requests
from ytmusicapi import YTMusic

YTMAPI = YTMusic("auth.json")

videoId = "xZdj3LM5X1M"  # Lizzo - Good as Hell
song = YTMAPI.get_song(videoId)

CPNA = ("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_")
cpn = "".join( ( CPNA[random.randint(0, 256) & 63] for _ in range(0, 16) ) )
response = requests.get(
    song["playbackTracking"]["videostatsPlaybackUrl"]["baseUrl"],
    params={
        "ver": 2,
        "c": "WEB_REMIX",
        "cpn": cpn,
    },
    headers=YTMAPI.headers,
    proxies=YTMAPI.proxies,
)
if (response.status_code == 204):
    print("\"%s\" added to history." % song["videoDetails"]["title"])

And the correct signatureTimestamp doesn't even need to be used to get back the correct urls in playbackTracking.

@sigma67
Copy link

sigma67 commented Nov 30, 2022

Ah alright, that's a very simple change. There's no reason to exclude that key apart from excluding non-useful data. Which playbackTracking obviously isn't as you just provided a use-case. Will implement shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants