]>
jfr.im git - yt-dlp.git/blob - yt_dlp/extractor/lastfm.py
3 from .common
import InfoExtractor
4 from ..utils
import int_or_none
, format_field
7 class LastFMPlaylistBaseIE(InfoExtractor
):
8 def _entries(self
, url
, playlist_id
):
9 webpage
= self
._download
_webpage
(url
, playlist_id
)
10 start_page_number
= int_or_none(self
._search
_regex
(
11 r
'\bpage=(\d+)', url
, 'page', default
=None)) or 1
12 last_page_number
= int_or_none(self
._search
_regex
(
13 r
'>(\d+)</a>[^<]*</li>[^<]*<li[^>]+class="pagination-next', webpage
, 'last_page', default
=None))
15 for page_number
in range(start_page_number
, (last_page_number
or start_page_number
) + 1):
16 webpage
= self
._download
_webpage
(
18 note
='Downloading page %d%s' % (page_number
, format_field(last_page_number
, None, ' of %d')),
19 query
={'page': page_number}
)
21 self
.url_result(player_url
, 'Youtube')
22 for player_url
in set(re
.findall(r
'data-youtube-url="([^"]+)"', webpage
))
25 for e
in page_entries
:
28 def _real_extract(self
, url
):
29 playlist_id
= self
._match
_id
(url
)
30 return self
.playlist_result(self
._entries
(url
, playlist_id
), playlist_id
)
33 class LastFMPlaylistIE(LastFMPlaylistBaseIE
):
34 _VALID_URL
= r
'https?://(?:www\.)?last\.fm/(music|tag)/(?P<id>[^/]+)(?:/[^/]+)?/?(?:[?#]|$)'
36 'url': 'https://www.last.fm/music/Oasis/(What%27s+the+Story)+Morning+Glory%3F',
42 'url': 'https://www.last.fm/music/Oasis',
43 'only_matching': True,
45 'url': 'https://www.last.fm/music/Oasis/',
46 'only_matching': True,
48 'url': 'https://www.last.fm/music/Oasis?top_tracks_date_preset=ALL#top-tracks',
49 'only_matching': True,
51 'url': 'https://www.last.fm/music/Oasis/+tracks',
52 'only_matching': True,
54 'url': 'https://www.last.fm/music/Oasis/+tracks?page=2',
55 'only_matching': True,
57 'url': 'https://www.last.fm/music/Oasis/+tracks?date_preset=LAST_90_DAYS#top-tracks',
58 'only_matching': True,
60 'url': 'https://www.last.fm/tag/rock',
61 'only_matching': True,
63 'url': 'https://www.last.fm/tag/rock/tracks',
64 'only_matching': True,
68 class LastFMUserIE(LastFMPlaylistBaseIE
):
69 _VALID_URL
= r
'https?://(?:www\.)?last\.fm/user/[^/]+/playlists/(?P<id>[^/#?]+)'
71 'url': 'https://www.last.fm/user/mehq/playlists/12319471',
79 class LastFMIE(InfoExtractor
):
80 _VALID_URL
= r
'https?://(?:www\.)?last\.fm/music(?:/[^/]+){2}/(?P<id>[^/#?]+)'
82 'url': 'https://www.last.fm/music/Oasis/_/Wonderwall',
83 'md5': '9c4a70c2e84c03d54fe24229b9e13b7b',
87 'title': 'Oasis - Wonderwall (Official Video)',
88 'thumbnail': r
're:^https?://i.ytimg.com/.*\.jpg$',
89 'description': 'md5:0848669853c10687cc28e88b5756738f',
91 'uploader_id': 'oasisinetofficial',
92 'upload_date': '20080207',
93 'album': '(What\'s The Story) Morning Glory? (Remastered)',
94 'track': 'Wonderwall (Remastered)',
95 'channel_id': 'UCUDVBtnOQi4c7E8jebpjc9Q',
97 'live_status': 'not_live',
98 'channel_url': 'https://www.youtube.com/channel/UCUDVBtnOQi4c7E8jebpjc9Q',
101 'uploader_url': 're:^https?://www.youtube.com/user/oasisinetofficial',
103 'alt_title': 'Wonderwall (Remastered)',
106 'channel_follower_count': int,
107 'categories': ['Music'],
108 'availability': 'public',
110 'playable_in_embed': True,
113 'add_ie': ['Youtube'],
115 'url': 'https://www.last.fm/music/Oasis/_/Don%27t+Look+Back+In+Anger+-+Remastered/',
116 'only_matching': True,
118 'url': 'https://www.last.fm/music/Guns+N%27+Roses/_/Sweet+Child+o%27+Mine',
119 'only_matching': True,
122 def _real_extract(self
, url
):
123 video_id
= self
._match
_id
(url
)
124 webpage
= self
._download
_webpage
(url
, video_id
)
125 player_url
= self
._search
_regex
(r
'(?s)class="header-new-playlink"\s+href="([^"]+)"', webpage
, 'player_url')
126 return self
.url_result(player_url
, 'Youtube')