add duration_seconds key to items with duration (closes #215)
This commit is contained in:
parent
221cce92ae
commit
3436f2dcc4
9 changed files with 200 additions and 197 deletions
|
|
@ -105,6 +105,20 @@ def to_int(string):
|
||||||
return int_value
|
return int_value
|
||||||
|
|
||||||
|
|
||||||
|
def parse_duration(duration):
|
||||||
|
if duration is None:
|
||||||
|
return duration
|
||||||
|
mapped_increments = zip([1, 60, 3600], reversed(duration.split(":")))
|
||||||
|
seconds = sum(multiplier * int(time) for multiplier, time in mapped_increments)
|
||||||
|
return seconds
|
||||||
|
|
||||||
|
|
||||||
|
def sum_total_duration(item):
|
||||||
|
return sum(
|
||||||
|
[track['duration_seconds'] if 'duration_seconds' in track else 0 for track in item['tracks']]
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def i18n(method):
|
def i18n(method):
|
||||||
@wraps(method)
|
@wraps(method)
|
||||||
def _impl(self, *method_args, **method_kwargs):
|
def _impl(self, *method_args, **method_kwargs):
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ class BrowsingMixin:
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"views": "1.4M",
|
"views": "1.4M",
|
||||||
"duration": "4:38"
|
"duration": "4:38",
|
||||||
|
"duration_seconds": 278
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "Songs",
|
"category": "Songs",
|
||||||
|
|
@ -67,6 +68,7 @@ class BrowsingMixin:
|
||||||
"id": "MPREb_9nqEki4ZDpp"
|
"id": "MPREb_9nqEki4ZDpp"
|
||||||
},
|
},
|
||||||
"duration": "4:19",
|
"duration": "4:19",
|
||||||
|
"duration_seconds": 259
|
||||||
"isExplicit": false,
|
"isExplicit": false,
|
||||||
"feedbackTokens": {
|
"feedbackTokens": {
|
||||||
"add": null,
|
"add": null,
|
||||||
|
|
@ -103,7 +105,8 @@ class BrowsingMixin:
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"views": "386M",
|
"views": "386M",
|
||||||
"duration": "4:38"
|
"duration": "4:38",
|
||||||
|
"duration_seconds": 278
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"category": "Artists",
|
"category": "Artists",
|
||||||
|
|
@ -121,7 +124,8 @@ class BrowsingMixin:
|
||||||
endpoint = 'search'
|
endpoint = 'search'
|
||||||
search_results = []
|
search_results = []
|
||||||
filters = [
|
filters = [
|
||||||
'albums', 'artists', 'playlists', 'community_playlists', 'featured_playlists', 'songs', 'videos'
|
'albums', 'artists', 'playlists', 'community_playlists', 'featured_playlists', 'songs',
|
||||||
|
'videos'
|
||||||
]
|
]
|
||||||
if filter and filter not in filters:
|
if filter and filter not in filters:
|
||||||
raise Exception(
|
raise Exception(
|
||||||
|
|
@ -146,7 +150,8 @@ class BrowsingMixin:
|
||||||
|
|
||||||
if 'tabbedSearchResultsRenderer' in response['contents']:
|
if 'tabbedSearchResultsRenderer' in response['contents']:
|
||||||
tab_index = 0 if not scope or filter else scopes.index(scope) + 1
|
tab_index = 0 if not scope or filter else scopes.index(scope) + 1
|
||||||
results = response['contents']['tabbedSearchResultsRenderer']['tabs'][tab_index]['tabRenderer']['content']
|
results = response['contents']['tabbedSearchResultsRenderer']['tabs'][tab_index][
|
||||||
|
'tabRenderer']['content']
|
||||||
else:
|
else:
|
||||||
results = response['contents']
|
results = response['contents']
|
||||||
|
|
||||||
|
|
@ -178,7 +183,8 @@ class BrowsingMixin:
|
||||||
request_func = lambda additionalParams: self._send_request(
|
request_func = lambda additionalParams: self._send_request(
|
||||||
endpoint, body, additionalParams)
|
endpoint, body, additionalParams)
|
||||||
|
|
||||||
parse_func = lambda contents: self.parser.parse_search_results(contents, type, category)
|
parse_func = lambda contents: self.parser.parse_search_results(
|
||||||
|
contents, type, category)
|
||||||
|
|
||||||
search_results.extend(
|
search_results.extend(
|
||||||
get_continuations(res['musicShelfRenderer'], 'musicShelfContinuation',
|
get_continuations(res['musicShelfRenderer'], 'musicShelfContinuation',
|
||||||
|
|
@ -427,36 +433,40 @@ class BrowsingMixin:
|
||||||
|
|
||||||
:param browseId: browseId of the album, for example
|
:param browseId: browseId of the album, for example
|
||||||
returned by :py:func:`search`
|
returned by :py:func:`search`
|
||||||
:return: Dictionary with title, description, artist and tracks.
|
:return: Dictionary with album and track metadata.
|
||||||
|
|
||||||
Each track is in the following format::
|
Each track is in the following format::
|
||||||
|
|
||||||
{
|
{
|
||||||
"title": "Seven",
|
"title": "Revival",
|
||||||
"trackCount": "7",
|
"type": "Album",
|
||||||
"durationMs": "1439579",
|
"thumbnails": [],
|
||||||
"playlistId": "OLAK5uy_kGnhwT08mQMGw8fArBowdtlew3DpgUt9c",
|
"description": "Revival is the ninth studio album by American rapper Eminem. ...",
|
||||||
"releaseDate": {
|
"artists": [{
|
||||||
"year": 2016,
|
"name": "Eminem",
|
||||||
"month": 10,
|
"id": "UCedvOgsKFzcK3hA5taf3KoQ"
|
||||||
"day": 28
|
}],
|
||||||
},
|
"year": "2017",
|
||||||
"description": "Seven is ...",
|
"trackCount": 19,
|
||||||
"thumbnails": [...],
|
"duration": "1 hour, 17 minutes",
|
||||||
"artists": [
|
"duration_seconds": 4657,
|
||||||
{
|
"audioPlaylistId": "OLAK5uy_nMr9h2VlS-2PULNz3M3XVXQj_P3C2bqaY",
|
||||||
"name": "Martin Garrix",
|
|
||||||
"id": "UCqJnSdHjKtfsrHi9aI-9d3g"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"tracks": [
|
"tracks": [
|
||||||
{
|
{
|
||||||
"index": "1",
|
"videoId": "iKLU7z_xdYQ",
|
||||||
"title": "WIEE (feat. Mesto)",
|
"title": "Walk On Water (feat. Beyoncé)",
|
||||||
"artist": "Martin Garrix",
|
"artists": None,
|
||||||
"videoId": "8xMNeXI9wxI",
|
"album": None,
|
||||||
"lengthMs": "203406",
|
"likeStatus": "INDIFFERENT",
|
||||||
"likeStatus": "INDIFFERENT"
|
"thumbnails": None,
|
||||||
|
"isAvailable": True,
|
||||||
|
"isExplicit": True,
|
||||||
|
"duration": "5:03",
|
||||||
|
"feedbackTokens":
|
||||||
|
{
|
||||||
|
"add": "AB9zfpJww...",
|
||||||
|
"remove": "AB9zfpI807..."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
@ -467,6 +477,7 @@ class BrowsingMixin:
|
||||||
album = parse_album_header(response)
|
album = parse_album_header(response)
|
||||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF)
|
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF)
|
||||||
album['tracks'] = parse_playlist_items(results['contents'])
|
album['tracks'] = parse_playlist_items(results['contents'])
|
||||||
|
album['duration_seconds'] = sum_total_duration(album)
|
||||||
|
|
||||||
return album
|
return album
|
||||||
|
|
||||||
|
|
@ -482,151 +493,134 @@ class BrowsingMixin:
|
||||||
Example::
|
Example::
|
||||||
|
|
||||||
{
|
{
|
||||||
"videoDetails": {
|
|
||||||
"allowRatings": true,
|
|
||||||
"author": "Oasis - Topic",
|
|
||||||
"averageRating": 4.5783687,
|
|
||||||
"channelId": "UCmMUZbaYdNH0bEd1PAlAqsA",
|
|
||||||
"isCrawlable": true,
|
|
||||||
"isLiveContent": false,
|
|
||||||
"isOwnerViewing": false,
|
|
||||||
"isPrivate": false,
|
|
||||||
"isUnpluggedCorpus": false,
|
|
||||||
"lengthSeconds": "259",
|
|
||||||
"musicVideoType": "MUSIC_VIDEO_TYPE_ATV",
|
|
||||||
"thumbnail": {
|
|
||||||
"thumbnails": [...]
|
|
||||||
},
|
|
||||||
"title": "Wonderwall",
|
|
||||||
"videoId": "ZrOKjDZOtkA",
|
|
||||||
"viewCount": "27429003"
|
|
||||||
},
|
|
||||||
"microformat": {
|
|
||||||
"microformatDataRenderer": {
|
|
||||||
"androidPackage": "com.google.android.apps.youtube.music",
|
|
||||||
"appName": "YouTube Music",
|
|
||||||
"availableCountries": ["AE",...],
|
|
||||||
"category": "Music",
|
|
||||||
"description": "Provided to YouTube by Ignition Wonderwall · Oasis ...",
|
|
||||||
"familySafe": true,
|
|
||||||
"iosAppArguments": "https://music.youtube.com/watch?v=ZrOKjDZOtkA",
|
|
||||||
"iosAppStoreId": "1017492454",
|
|
||||||
"linkAlternates": [
|
|
||||||
{
|
|
||||||
"hrefUrl": "android-app://com.google.android.youtube/http/youtube.com/watch?v=ZrOKjDZOtkA"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"hrefUrl": "ios-app://544007664/http/youtube.com/watch?v=ZrOKjDZOtkA"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"alternateType": "application/json+oembed",
|
|
||||||
"hrefUrl": "https://www.youtube.com/oembed?format=json&url=...",
|
|
||||||
"title": "Wonderwall (Remastered)"
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"alternateType": "text/xml+oembed",
|
|
||||||
"hrefUrl": "https://www.youtube.com/oembed?format=xml&url=...",
|
|
||||||
"title": "Wonderwall (Remastered)"
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"noindex": false,
|
|
||||||
"ogType": "video.other",
|
|
||||||
"pageOwnerDetails": {
|
|
||||||
"externalChannelId": "UCmMUZbaYdNH0bEd1PAlAqsA",
|
|
||||||
"name": "Oasis - Topic",
|
|
||||||
"youtubeProfileUrl": "http://www.youtube.com/channel/UCmMUZbaYdNH0bEd1PAlAqsA"
|
|
||||||
},
|
|
||||||
"paid": false,
|
|
||||||
"publishDate": "2017-01-25",
|
|
||||||
"schemaDotOrgType": "http://schema.org/VideoObject",
|
|
||||||
"siteName": "YouTube Music",
|
|
||||||
"tags": ["Oasis",...],
|
|
||||||
"thumbnail": {
|
|
||||||
"thumbnails": [
|
|
||||||
{
|
|
||||||
"height": 720,
|
|
||||||
"url": "https://i.ytimg.com/vi/ZrOKjDZOtkA/maxresdefault.jpg",
|
|
||||||
"width": 1280
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"title": "Wonderwall (Remastered) - YouTube Music",
|
|
||||||
"twitterCardType": "player",
|
|
||||||
"twitterSiteHandle": "@YouTubeMusic",
|
|
||||||
"unlisted": false,
|
|
||||||
"uploadDate": "2017-01-25",
|
|
||||||
"urlApplinksAndroid": "vnd.youtube.music://music.youtube.com/watch?v=ZrOKjDZOtkA&feature=applinks",
|
|
||||||
"urlApplinksIos": "vnd.youtube.music://music.youtube.com/watch?v=ZrOKjDZOtkA&feature=applinks",
|
|
||||||
"urlCanonical": "https://music.youtube.com/watch?v=ZrOKjDZOtkA",
|
|
||||||
"urlTwitterAndroid": "vnd.youtube.music://music.youtube.com/watch?v=ZrOKjDZOtkA&feature=twitter-deep-link",
|
|
||||||
"urlTwitterIos": "vnd.youtube.music://music.youtube.com/watch?v=ZrOKjDZOtkA&feature=twitter-deep-link",
|
|
||||||
"videoDetails": {
|
|
||||||
"durationIso8601": "PT4M19S",
|
|
||||||
"durationSeconds": "259",
|
|
||||||
"externalVideoId": "ZrOKjDZOtkA"
|
|
||||||
},
|
|
||||||
"viewCount": "27429003"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"playabilityStatus": {
|
"playabilityStatus": {
|
||||||
"contextParams": "Q0FFU0FnZ0I=",
|
"status": "OK",
|
||||||
|
"playableInEmbed": true,
|
||||||
|
"audioOnlyPlayability": {
|
||||||
|
"audioOnlyPlayabilityRenderer": {
|
||||||
|
"trackingParams": "CAEQx2kiEwiuv9X5i5H1AhWBvlUKHRoZAHk=",
|
||||||
|
"audioOnlyAvailability": "FEATURE_AVAILABILITY_ALLOWED"
|
||||||
|
}
|
||||||
|
},
|
||||||
"miniplayer": {
|
"miniplayer": {
|
||||||
"miniplayerRenderer": {
|
"miniplayerRenderer": {
|
||||||
"playbackMode": "PLAYBACK_MODE_ALLOW"
|
"playbackMode": "PLAYBACK_MODE_ALLOW"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"playableInEmbed": true,
|
"contextParams": "Q0FBU0FnZ0M="
|
||||||
"status": "OK"
|
|
||||||
},
|
},
|
||||||
"streamingData": {
|
"streamingData": {
|
||||||
|
"expiresInSeconds": "21540",
|
||||||
"adaptiveFormats": [
|
"adaptiveFormats": [
|
||||||
{
|
{
|
||||||
"approxDurationMs": "258760",
|
"itag": 140,
|
||||||
"averageBitrate": 178439,
|
"url": "https://rr1---sn-h0jelnez.c.youtube.com/videoplayback?expire=1641080272...",
|
||||||
"bitrate": 232774,
|
"mimeType": "audio/mp4; codecs=\"mp4a.40.2\"",
|
||||||
"contentLength": "5771637",
|
"bitrate": 131007,
|
||||||
"fps": 25,
|
|
||||||
"height": 1080,
|
|
||||||
"indexRange": {
|
|
||||||
"end": "1398",
|
|
||||||
"start": "743"
|
|
||||||
},
|
|
||||||
"initRange": {
|
"initRange": {
|
||||||
"end": "742",
|
"start": "0",
|
||||||
"start": "0"
|
"end": "667"
|
||||||
},
|
},
|
||||||
"itag": 137,
|
"indexRange": {
|
||||||
"lastModified": "1614620567944400",
|
"start": "668",
|
||||||
"mimeType": "video/mp4; codecs=\"avc1.640020\"",
|
"end": "999"
|
||||||
|
},
|
||||||
|
"lastModified": "1620321966927796",
|
||||||
|
"contentLength": "3967382",
|
||||||
|
"quality": "tiny",
|
||||||
"projectionType": "RECTANGULAR",
|
"projectionType": "RECTANGULAR",
|
||||||
"quality": "hd1080",
|
"averageBitrate": 129547,
|
||||||
"qualityLabel": "1080p",
|
"highReplication": true,
|
||||||
"signatureCipher": "s=_xxxOq0QJ8...",
|
"audioQuality": "AUDIO_QUALITY_MEDIUM",
|
||||||
"width": 1078
|
"approxDurationMs": "245000",
|
||||||
}[...]
|
|
||||||
],
|
|
||||||
"expiresInSeconds": "21540",
|
|
||||||
"formats": [
|
|
||||||
{
|
|
||||||
"approxDurationMs": "258809",
|
|
||||||
"audioChannels": 2,
|
|
||||||
"audioQuality": "AUDIO_QUALITY_LOW",
|
|
||||||
"audioSampleRate": "44100",
|
"audioSampleRate": "44100",
|
||||||
"averageBitrate": 179462,
|
"audioChannels": 2,
|
||||||
"bitrate": 179496,
|
"loudnessDb": -1.3000002
|
||||||
"contentLength": "5805816",
|
|
||||||
"fps": 25,
|
|
||||||
"height": 360,
|
|
||||||
"itag": 18,
|
|
||||||
"lastModified": "1614620870611066",
|
|
||||||
"mimeType": "video/mp4; codecs=\"avc1.42001E, mp4a.40.2\"",
|
|
||||||
"projectionType": "RECTANGULAR",
|
|
||||||
"quality": "medium",
|
|
||||||
"qualityLabel": "360p",
|
|
||||||
"signatureCipher": "s=kXXXOq0QJ8...",
|
|
||||||
"width": 360
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"videoDetails": {
|
||||||
|
"videoId": "AjXQiKP5kMs",
|
||||||
|
"title": "Sparks",
|
||||||
|
"lengthSeconds": "245",
|
||||||
|
"channelId": "UCvCk2zFqkCYzpnSgWfx0qOg",
|
||||||
|
"isOwnerViewing": false,
|
||||||
|
"isCrawlable": false,
|
||||||
|
"thumbnail": {
|
||||||
|
"thumbnails": []
|
||||||
|
},
|
||||||
|
"allowRatings": true,
|
||||||
|
"viewCount": "12",
|
||||||
|
"author": "Thomas Bergersen",
|
||||||
|
"isPrivate": true,
|
||||||
|
"isUnpluggedCorpus": false,
|
||||||
|
"musicVideoType": "MUSIC_VIDEO_TYPE_PRIVATELY_OWNED_TRACK",
|
||||||
|
"isLiveContent": false
|
||||||
|
},
|
||||||
|
"microformat": {
|
||||||
|
"microformatDataRenderer": {
|
||||||
|
"urlCanonical": "https://music.youtube.com/watch?v=AjXQiKP5kMs",
|
||||||
|
"title": "Sparks - YouTube Music",
|
||||||
|
"description": "Uploaded to YouTube via YouTube Music Sparks",
|
||||||
|
"thumbnail": {
|
||||||
|
"thumbnails": [
|
||||||
|
{
|
||||||
|
"url": "https://i.ytimg.com/vi/AjXQiKP5kMs/hqdefault.jpg",
|
||||||
|
"width": 480,
|
||||||
|
"height": 360
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"siteName": "YouTube Music",
|
||||||
|
"appName": "YouTube Music",
|
||||||
|
"androidPackage": "com.google.android.apps.youtube.music",
|
||||||
|
"iosAppStoreId": "1017492454",
|
||||||
|
"iosAppArguments": "https://music.youtube.com/watch?v=AjXQiKP5kMs",
|
||||||
|
"ogType": "video.other",
|
||||||
|
"urlApplinksIos": "vnd.youtube.music://music.youtube.com/watch?v=AjXQiKP5kMs&feature=applinks",
|
||||||
|
"urlApplinksAndroid": "vnd.youtube.music://music.youtube.com/watch?v=AjXQiKP5kMs&feature=applinks",
|
||||||
|
"urlTwitterIos": "vnd.youtube.music://music.youtube.com/watch?v=AjXQiKP5kMs&feature=twitter-deep-link",
|
||||||
|
"urlTwitterAndroid": "vnd.youtube.music://music.youtube.com/watch?v=AjXQiKP5kMs&feature=twitter-deep-link",
|
||||||
|
"twitterCardType": "player",
|
||||||
|
"twitterSiteHandle": "@YouTubeMusic",
|
||||||
|
"schemaDotOrgType": "http://schema.org/VideoObject",
|
||||||
|
"noindex": true,
|
||||||
|
"unlisted": true,
|
||||||
|
"paid": false,
|
||||||
|
"familySafe": true,
|
||||||
|
"pageOwnerDetails": {
|
||||||
|
"name": "Music Library Uploads",
|
||||||
|
"externalChannelId": "UCvCk2zFqkCYzpnSgWfx0qOg",
|
||||||
|
"youtubeProfileUrl": "http://www.youtube.com/channel/UCvCk2zFqkCYzpnSgWfx0qOg"
|
||||||
|
},
|
||||||
|
"videoDetails": {
|
||||||
|
"externalVideoId": "AjXQiKP5kMs",
|
||||||
|
"durationSeconds": "246",
|
||||||
|
"durationIso8601": "PT4M6S"
|
||||||
|
},
|
||||||
|
"linkAlternates": [
|
||||||
|
{
|
||||||
|
"hrefUrl": "android-app://com.google.android.youtube/http/youtube.com/watch?v=AjXQiKP5kMs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hrefUrl": "ios-app://544007664/http/youtube.com/watch?v=AjXQiKP5kMs"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hrefUrl": "https://www.youtube.com/oembed?format=json&url=https%3A%2F%2Fmusic.youtube.com%2Fwatch%3Fv%3DAjXQiKP5kMs",
|
||||||
|
"title": "Sparks",
|
||||||
|
"alternateType": "application/json+oembed"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"hrefUrl": "https://www.youtube.com/oembed?format=xml&url=https%3A%2F%2Fmusic.youtube.com%2Fwatch%3Fv%3DAjXQiKP5kMs",
|
||||||
|
"title": "Sparks",
|
||||||
|
"alternateType": "text/xml+oembed"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"viewCount": "12",
|
||||||
|
"publishDate": "1969-12-31",
|
||||||
|
"category": "Music",
|
||||||
|
"uploadDate": "1969-12-31"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -123,18 +123,7 @@ class ExploreMixin:
|
||||||
"id": "UCLusb4T2tW3gOpJS1fJ-A9g"
|
"id": "UCLusb4T2tW3gOpJS1fJ-A9g"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"thumbnails": [
|
"thumbnails": [...],
|
||||||
{
|
|
||||||
"url": "https://lh3.googleusercontent.com/HtT4fwjY_SC7F2reuC1F3pREiq0z5G1XnO_IvhkI0LvCmdz05c8mhuZ6k3MiROvwH52TSJNj33TxnQIo=w60-h60-l90-rj",
|
|
||||||
"width": 60,
|
|
||||||
"height": 60
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"url": "https://lh3.googleusercontent.com/HtT4fwjY_SC7F2reuC1F3pREiq0z5G1XnO_IvhkI0LvCmdz05c8mhuZ6k3MiROvwH52TSJNj33TxnQIo=w120-h120-l90-rj",
|
|
||||||
"width": 120,
|
|
||||||
"height": 120
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"isExplicit": true,
|
"isExplicit": true,
|
||||||
"album": {
|
"album": {
|
||||||
"name": "Outside (Better Days)",
|
"name": "Outside (Better Days)",
|
||||||
|
|
@ -237,9 +226,7 @@ class ExploreMixin:
|
||||||
}
|
}
|
||||||
|
|
||||||
if has_songs:
|
if has_songs:
|
||||||
charts['songs'].update({
|
charts['songs'].update({'items': parse_chart(0, parse_chart_song, MRLIR)})
|
||||||
'items': parse_chart(0, parse_chart_song, MRLIR)
|
|
||||||
})
|
|
||||||
|
|
||||||
charts['videos']['items'] = parse_chart(1, parse_video, MTRIR)
|
charts['videos']['items'] = parse_chart(1, parse_video, MTRIR)
|
||||||
charts['artists']['items'] = parse_chart(2, parse_chart_artist, MRLIR)
|
charts['artists']['items'] = parse_chart(2, parse_chart_artist, MRLIR)
|
||||||
|
|
|
||||||
|
|
@ -109,10 +109,10 @@ class LibraryMixin:
|
||||||
"title": "Beautiful",
|
"title": "Beautiful",
|
||||||
"type": "Album",
|
"type": "Album",
|
||||||
"thumbnails": [...],
|
"thumbnails": [...],
|
||||||
"artists": {
|
"artists": [{
|
||||||
"name": "Project 46",
|
"name": "Project 46",
|
||||||
"id": "UCXFv36m62USAN5rnVct9B4g"
|
"id": "UCXFv36m62USAN5rnVct9B4g"
|
||||||
},
|
}],
|
||||||
"year": "2015"
|
"year": "2015"
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ class PlaylistsMixin:
|
||||||
"author": "sigmatics",
|
"author": "sigmatics",
|
||||||
"year": "2020",
|
"year": "2020",
|
||||||
"duration": "6+ hours",
|
"duration": "6+ hours",
|
||||||
|
"duration_seconds": 52651,
|
||||||
"trackCount": 237,
|
"trackCount": 237,
|
||||||
"tracks": [
|
"tracks": [
|
||||||
{
|
{
|
||||||
|
|
@ -113,6 +114,7 @@ class PlaylistsMixin:
|
||||||
songs_to_get - len(playlist['tracks']), request_func,
|
songs_to_get - len(playlist['tracks']), request_func,
|
||||||
parse_func))
|
parse_func))
|
||||||
|
|
||||||
|
playlist['duration_seconds'] = sum_total_duration(playlist)
|
||||||
return playlist
|
return playlist
|
||||||
|
|
||||||
def get_playlist_suggestions(self, suggestions_token: str) -> Dict:
|
def get_playlist_suggestions(self, suggestions_token: str) -> Dict:
|
||||||
|
|
|
||||||
|
|
@ -167,6 +167,7 @@ class UploadsMixin:
|
||||||
"videoId": "FVo-UZoPygI",
|
"videoId": "FVo-UZoPygI",
|
||||||
"title": "Feel So Close",
|
"title": "Feel So Close",
|
||||||
"duration": "4:15",
|
"duration": "4:15",
|
||||||
|
"duration_seconds": 255,
|
||||||
"artists": None,
|
"artists": None,
|
||||||
"album": {
|
"album": {
|
||||||
"name": "18 Months",
|
"name": "18 Months",
|
||||||
|
|
@ -183,6 +184,7 @@ class UploadsMixin:
|
||||||
album = parse_album_header(response)
|
album = parse_album_header(response)
|
||||||
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF)
|
results = nav(response, SINGLE_COLUMN_TAB + SECTION_LIST_ITEM + MUSIC_SHELF)
|
||||||
album['tracks'] = parse_uploaded_items(results['contents'])
|
album['tracks'] = parse_uploaded_items(results['contents'])
|
||||||
|
album['duration_seconds'] = sum_total_duration(album)
|
||||||
return album
|
return album
|
||||||
|
|
||||||
def upload_song(self, filepath: str) -> Union[str, requests.Response]:
|
def upload_song(self, filepath: str) -> Union[str, requests.Response]:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from .utils import *
|
from .utils import *
|
||||||
|
from ..helpers import parse_duration
|
||||||
from .songs import *
|
from .songs import *
|
||||||
from typing import List
|
from typing import List
|
||||||
|
|
||||||
|
|
@ -77,6 +78,7 @@ def parse_playlist_items(results, menu_entries: List[List] = None):
|
||||||
}
|
}
|
||||||
if duration:
|
if duration:
|
||||||
song['duration'] = duration
|
song['duration'] = duration
|
||||||
|
song['duration_seconds'] = parse_duration(duration)
|
||||||
if setVideoId:
|
if setVideoId:
|
||||||
song['setVideoId'] = setVideoId
|
song['setVideoId'] = setVideoId
|
||||||
if feedback_tokens:
|
if feedback_tokens:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
from .utils import *
|
from .utils import *
|
||||||
|
from ..helpers import parse_duration
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -30,7 +31,8 @@ def parse_song_runs(runs):
|
||||||
if 'navigationEndpoint' in run: # artist or album
|
if 'navigationEndpoint' in run: # artist or album
|
||||||
item = {'name': text, 'id': nav(run, NAVIGATION_BROWSE_ID, True)}
|
item = {'name': text, 'id': nav(run, NAVIGATION_BROWSE_ID, True)}
|
||||||
|
|
||||||
if item['id'] and (item['id'].startswith('MPRE') or "release_detail" in item['id']): # album
|
if item['id'] and (item['id'].startswith('MPRE')
|
||||||
|
or "release_detail" in item['id']): # album
|
||||||
parsed['album'] = item
|
parsed['album'] = item
|
||||||
else: # artist
|
else: # artist
|
||||||
parsed['artists'].append(item)
|
parsed['artists'].append(item)
|
||||||
|
|
@ -42,6 +44,7 @@ def parse_song_runs(runs):
|
||||||
|
|
||||||
elif re.match(r"^(\d+:)*\d+:\d+$", text):
|
elif re.match(r"^(\d+:)*\d+:\d+$", text):
|
||||||
parsed['duration'] = text
|
parsed['duration'] = text
|
||||||
|
parsed['duration_seconds'] = parse_duration(text)
|
||||||
|
|
||||||
elif re.match(r"^\d{4}$", text):
|
elif re.match(r"^\d{4}$", text):
|
||||||
parsed['year'] = text
|
parsed['year'] = text
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,12 @@ def parse_uploaded_items(results):
|
||||||
'videoId': videoId,
|
'videoId': videoId,
|
||||||
'title': title,
|
'title': title,
|
||||||
'duration': duration,
|
'duration': duration,
|
||||||
'artists': None,
|
'duration_seconds': parse_duration(duration),
|
||||||
'album': None,
|
'artists': parse_song_artists(data, 1),
|
||||||
|
'album': parse_song_album(data, 2),
|
||||||
'likeStatus': like,
|
'likeStatus': like,
|
||||||
'thumbnails': thumbnails
|
'thumbnails': thumbnails
|
||||||
}
|
}
|
||||||
song['artists'] = parse_song_artists(data, 1)
|
|
||||||
song['album'] = parse_song_album(data, 2)
|
|
||||||
|
|
||||||
songs.append(song)
|
songs.append(song)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue