Skip to content

Commit

Permalink
get_song: fix signatureTimestamp (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigma67 committed May 21, 2021
1 parent 8c4b857 commit 5d59a09
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ytmusicapi/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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 *
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 7 additions & 2 deletions ytmusicapi/mixins/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,11 +542,13 @@ def get_album(self, browseId: str) -> Dict:

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::
Expand Down Expand Up @@ -702,10 +704,13 @@ def get_song(self, videoId: str) -> Dict:
"""
endpoint = 'player'
if not signatureTimestamp:
signatureTimestamp = get_datestamp() - 1

params = {
"playbackContext": {
"contentPlaybackContext": {
"signatureTimestamp": 18766
"signatureTimestamp": signatureTimestamp
}
},
"video_id": videoId
Expand Down

0 comments on commit 5d59a09

Please sign in to comment.