mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-01 02:37:29 +01:00
[extractor/LastFM] Rewrite playlist extraction (#6379)
Authored by: hatienl0i261299, pukkandan Closes #5975
This commit is contained in:
parent
0181b9a1b3
commit
026435714c
@ -1,33 +1,24 @@
|
|||||||
|
import itertools
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
from ..utils import int_or_none, format_field
|
from ..utils import int_or_none, parse_qs, traverse_obj
|
||||||
|
|
||||||
|
|
||||||
class LastFMPlaylistBaseIE(InfoExtractor):
|
class LastFMPlaylistBaseIE(InfoExtractor):
|
||||||
def _entries(self, url, playlist_id):
|
def _entries(self, url, playlist_id):
|
||||||
webpage = self._download_webpage(url, playlist_id)
|
single_page = traverse_obj(parse_qs(url), ('page', -1, {int_or_none}))
|
||||||
start_page_number = int_or_none(self._search_regex(
|
for page in itertools.count(single_page or 1):
|
||||||
r'\bpage=(\d+)', url, 'page', default=None)) or 1
|
|
||||||
last_page_number = int_or_none(self._search_regex(
|
|
||||||
r'>(\d+)</a>[^<]*</li>[^<]*<li[^>]+class="pagination-next', webpage, 'last_page', default=None))
|
|
||||||
|
|
||||||
for page_number in range(start_page_number, (last_page_number or start_page_number) + 1):
|
|
||||||
webpage = self._download_webpage(
|
webpage = self._download_webpage(
|
||||||
url, playlist_id,
|
url, playlist_id, f'Downloading page {page}', query={'page': page})
|
||||||
note='Downloading page %d%s' % (page_number, format_field(last_page_number, None, ' of %d')),
|
videos = re.findall(r'data-youtube-url="([^"]+)"', webpage)
|
||||||
query={'page': page_number})
|
yield from videos
|
||||||
page_entries = [
|
if single_page or not videos:
|
||||||
self.url_result(player_url, 'Youtube')
|
return
|
||||||
for player_url in set(re.findall(r'data-youtube-url="([^"]+)"', webpage))
|
|
||||||
]
|
|
||||||
|
|
||||||
for e in page_entries:
|
|
||||||
yield e
|
|
||||||
|
|
||||||
def _real_extract(self, url):
|
def _real_extract(self, url):
|
||||||
playlist_id = self._match_id(url)
|
playlist_id = self._match_id(url)
|
||||||
return self.playlist_result(self._entries(url, playlist_id), playlist_id)
|
return self.playlist_from_matches(self._entries(url, playlist_id), playlist_id, ie='Youtube')
|
||||||
|
|
||||||
|
|
||||||
class LastFMPlaylistIE(LastFMPlaylistBaseIE):
|
class LastFMPlaylistIE(LastFMPlaylistBaseIE):
|
||||||
@ -37,7 +28,7 @@ class LastFMPlaylistIE(LastFMPlaylistBaseIE):
|
|||||||
'info_dict': {
|
'info_dict': {
|
||||||
'id': 'Oasis',
|
'id': 'Oasis',
|
||||||
},
|
},
|
||||||
'playlist_count': 11,
|
'playlist_mincount': 11,
|
||||||
}, {
|
}, {
|
||||||
'url': 'https://www.last.fm/music/Oasis',
|
'url': 'https://www.last.fm/music/Oasis',
|
||||||
'only_matching': True,
|
'only_matching': True,
|
||||||
@ -73,6 +64,18 @@ class LastFMUserIE(LastFMPlaylistBaseIE):
|
|||||||
'id': '12319471',
|
'id': '12319471',
|
||||||
},
|
},
|
||||||
'playlist_count': 30,
|
'playlist_count': 30,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.last.fm/user/naamloos1/playlists/12543760',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '12543760',
|
||||||
|
},
|
||||||
|
'playlist_mincount': 80,
|
||||||
|
}, {
|
||||||
|
'url': 'https://www.last.fm/user/naamloos1/playlists/12543760?page=3',
|
||||||
|
'info_dict': {
|
||||||
|
'id': '12543760',
|
||||||
|
},
|
||||||
|
'playlist_count': 32,
|
||||||
}]
|
}]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user