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