mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-11-27 06:10:12 +01:00
Merge cc974e7b83
into f919729538
This commit is contained in:
commit
1da41b2287
|
@ -929,6 +929,7 @@
|
||||||
)
|
)
|
||||||
from .jiosaavn import (
|
from .jiosaavn import (
|
||||||
JioSaavnAlbumIE,
|
JioSaavnAlbumIE,
|
||||||
|
JioSaavnArtistIE,
|
||||||
JioSaavnPlaylistIE,
|
JioSaavnPlaylistIE,
|
||||||
JioSaavnSongIE,
|
JioSaavnSongIE,
|
||||||
)
|
)
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
clean_html,
|
clean_html,
|
||||||
int_or_none,
|
int_or_none,
|
||||||
make_archive_id,
|
make_archive_id,
|
||||||
|
parse_duration,
|
||||||
smuggle_url,
|
smuggle_url,
|
||||||
unsmuggle_url,
|
unsmuggle_url,
|
||||||
url_basename,
|
url_basename,
|
||||||
|
@ -172,14 +173,14 @@ class JioSaavnPlaylistIE(JioSaavnBaseIE):
|
||||||
'id': 'DVR,pFUOwyXqIp77B1JF,A__',
|
'id': 'DVR,pFUOwyXqIp77B1JF,A__',
|
||||||
'title': 'Mood Hindi',
|
'title': 'Mood Hindi',
|
||||||
},
|
},
|
||||||
'playlist_mincount': 801,
|
'playlist_mincount': 750,
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.jiosaavn.com/featured/taaza-tunes/Me5RridRfDk_',
|
'url': 'https://www.jiosaavn.com/featured/taaza-tunes/Me5RridRfDk_',
|
||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'Me5RridRfDk_',
|
'id': 'Me5RridRfDk_',
|
||||||
'title': 'Taaza Tunes',
|
'title': 'Taaza Tunes',
|
||||||
},
|
},
|
||||||
'playlist_mincount': 301,
|
'playlist_mincount': 50,
|
||||||
}]
|
}]
|
||||||
_PAGE_SIZE = 50
|
_PAGE_SIZE = 50
|
||||||
|
|
||||||
|
@ -199,3 +200,83 @@ def _real_extract(self, url):
|
||||||
return self.playlist_result(InAdvancePagedList(
|
return self.playlist_result(InAdvancePagedList(
|
||||||
functools.partial(self._entries, display_id, playlist_data),
|
functools.partial(self._entries, display_id, playlist_data),
|
||||||
total_pages, self._PAGE_SIZE), display_id, traverse_obj(playlist_data, ('listname', {str})))
|
total_pages, self._PAGE_SIZE), display_id, traverse_obj(playlist_data, ('listname', {str})))
|
||||||
|
|
||||||
|
|
||||||
|
class JioSaavnArtistIE(JioSaavnBaseIE):
|
||||||
|
IE_NAME = 'jiosaavn:artist'
|
||||||
|
_VALID_URL = r'https?://(?:www\.)?(?:jio)?saavn\.com/artist/[^/?#]+/(?P<id>[^/?#]+)'
|
||||||
|
_TESTS = [{
|
||||||
|
'url': 'https://www.jiosaavn.com/artist/krsna-songs/rYLBEve2z3U_',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'rYLBEve2z3U_',
|
||||||
|
'title': 'KR$NA',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 99,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.jiosaavn.com/artist/sanam-puri-songs/SkNEv3qRhDE_',
|
||||||
|
'info_dict': {
|
||||||
|
'id': 'SkNEv3qRhDE_',
|
||||||
|
'title': 'Sanam Puri',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 55,
|
||||||
|
}]
|
||||||
|
_PAGE_SIZE = 50
|
||||||
|
|
||||||
|
def _fetch_page(self, token, page):
|
||||||
|
return self._call_api('artist', token, f'artist page {page}', {
|
||||||
|
'p': page, 'n_song': self._PAGE_SIZE, 'n_album': self._PAGE_SIZE, 'sub_type': '',
|
||||||
|
'includeMetaTags': '', 'api_version': '4', 'category': 'alphabetical', 'sort_order': 'asc'})
|
||||||
|
|
||||||
|
def _extract_song(self, song_data, url=None):
|
||||||
|
info = traverse_obj(song_data, {
|
||||||
|
'id': ('id', {str}),
|
||||||
|
'title': ('title', {clean_html}),
|
||||||
|
'album': ('more_info', 'album', {clean_html}),
|
||||||
|
'thumbnail': ('image', {clean_html}),
|
||||||
|
'duration': ('more_info', 'duration', {parse_duration}),
|
||||||
|
'release_year': ('year', {int_or_none}),
|
||||||
|
'artists': ('more_info', 'artistMap', 'primary_artists', {lambda x: x['name']}),
|
||||||
|
'webpage_url': ('perma_url', {url_or_none}),
|
||||||
|
})
|
||||||
|
if webpage_url := info.get('webpage_url') or url:
|
||||||
|
info['display_id'] = url_basename(webpage_url)
|
||||||
|
info['_old_archive_ids'] = [make_archive_id(JioSaavnSongIE, info['display_id'])]
|
||||||
|
|
||||||
|
return info
|
||||||
|
|
||||||
|
def _yield_songs(self, playlist_data):
|
||||||
|
for song_data in traverse_obj(playlist_data, ('topSongs')):
|
||||||
|
song_info = self._extract_song(song_data)
|
||||||
|
url = smuggle_url(song_info['webpage_url'], {
|
||||||
|
'id': song_data['id'],
|
||||||
|
'encrypted_media_url': song_data['more_info']['encrypted_media_url'],
|
||||||
|
})
|
||||||
|
yield self.url_result(url, JioSaavnSongIE, url_transparent=True, **song_info)
|
||||||
|
|
||||||
|
def _entries(self, token, page):
|
||||||
|
page_data = self._first_page if page == 0 else self._fetch_page(token, page)
|
||||||
|
yield from self._yield_songs(page_data)
|
||||||
|
|
||||||
|
def _generate_result(self, token):
|
||||||
|
# note:
|
||||||
|
# 1. the total number of songs in a page result is not constant
|
||||||
|
# 2. end of list is identified by 'topSongs' array being empty
|
||||||
|
page = 0
|
||||||
|
result = []
|
||||||
|
|
||||||
|
# added static page count limit to avoid potential infinite loop
|
||||||
|
while page < 20000:
|
||||||
|
entries = list(self._entries(token, page))
|
||||||
|
if len(entries) == 0:
|
||||||
|
break
|
||||||
|
result.extend(entries)
|
||||||
|
page += 1
|
||||||
|
return result
|
||||||
|
|
||||||
|
def _real_extract(self, url):
|
||||||
|
display_id = self._match_id(url)
|
||||||
|
self._first_page = self._fetch_page(display_id, 0)
|
||||||
|
entries = self._generate_result(display_id)
|
||||||
|
name = self._first_page.get('name')
|
||||||
|
|
||||||
|
return self.playlist_result(entries, display_id, name)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user