diff --git a/ytmusicapi/helpers.py b/ytmusicapi/helpers.py index f1b77c0..807324a 100644 --- a/ytmusicapi/helpers.py +++ b/ytmusicapi/helpers.py @@ -3,6 +3,7 @@ import json from http.cookies import SimpleCookie from hashlib import sha1 import time +from datetime import date from functools import wraps import locale from ytmusicapi.constants import * @@ -102,6 +103,10 @@ def get_authorization(auth): return "SAPISIDHASH " + unix_timestamp + "_" + sha_1.hexdigest() +def get_datestamp(): + return (date.today() - date.fromtimestamp(0)).days + + def to_int(string): number_string = string.split(' ')[0] try: diff --git a/ytmusicapi/mixins/browsing.py b/ytmusicapi/mixins/browsing.py index 3a156a7..5ede872 100644 --- a/ytmusicapi/mixins/browsing.py +++ b/ytmusicapi/mixins/browsing.py @@ -542,11 +542,13 @@ class BrowsingMixin: 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. :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. Example:: @@ -702,10 +704,13 @@ class BrowsingMixin: """ endpoint = 'player' + if not signatureTimestamp: + signatureTimestamp = get_datestamp() - 1 + params = { "playbackContext": { "contentPlaybackContext": { - "signatureTimestamp": 18766 + "signatureTimestamp": signatureTimestamp } }, "video_id": videoId