get_song: fix signatureTimestamp (#196)

This commit is contained in:
sigma67 2021-05-21 21:44:09 +02:00
commit 5d59a09751
No known key found for this signature in database
GPG key ID: 1545A01D4474BAF0
2 changed files with 12 additions and 2 deletions

View file

@ -3,6 +3,7 @@ import json
from http.cookies import SimpleCookie from http.cookies import SimpleCookie
from hashlib import sha1 from hashlib import sha1
import time import time
from datetime import date
from functools import wraps from functools import wraps
import locale import locale
from ytmusicapi.constants import * from ytmusicapi.constants import *
@ -102,6 +103,10 @@ def get_authorization(auth):
return "SAPISIDHASH " + unix_timestamp + "_" + sha_1.hexdigest() return "SAPISIDHASH " + unix_timestamp + "_" + sha_1.hexdigest()
def get_datestamp():
return (date.today() - date.fromtimestamp(0)).days
def to_int(string): def to_int(string):
number_string = string.split(' ')[0] number_string = string.split(' ')[0]
try: try:

View file

@ -542,11 +542,13 @@ class BrowsingMixin:
return album return album
def get_song(self, videoId: str) -> Dict: def get_song(self, videoId: str, signatureTimestamp: int = None) -> Dict:
""" """
Returns metadata and streaming information about a song or video. Returns metadata and streaming information about a song or video.
:param videoId: Video id :param videoId: Video id
:param signatureTimestamp: Provide the current YouTube signatureTimestamp.
If not provided a default value will be used, which might result in invalid streaming URLs
:return: Dictionary with song metadata. :return: Dictionary with song metadata.
Example:: Example::
@ -702,10 +704,13 @@ class BrowsingMixin:
""" """
endpoint = 'player' endpoint = 'player'
if not signatureTimestamp:
signatureTimestamp = get_datestamp() - 1
params = { params = {
"playbackContext": { "playbackContext": {
"contentPlaybackContext": { "contentPlaybackContext": {
"signatureTimestamp": 18766 "signatureTimestamp": signatureTimestamp
} }
}, },
"video_id": videoId "video_id": videoId