]>
Commit | Line | Data |
---|---|---|
1 | import re | |
2 | ||
3 | from .common import InfoExtractor | |
4 | from ..utils import int_or_none, format_field | |
5 | ||
6 | ||
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)) | |
14 | ||
15 | for page_number in range(start_page_number, (last_page_number or start_page_number) + 1): | |
16 | webpage = self._download_webpage( | |
17 | url, playlist_id, | |
18 | note='Downloading page %d%s' % (page_number, format_field(last_page_number, None, ' of %d')), | |
19 | query={'page': page_number}) | |
20 | page_entries = [ | |
21 | self.url_result(player_url, 'Youtube') | |
22 | for player_url in set(re.findall(r'data-youtube-url="([^"]+)"', webpage)) | |
23 | ] | |
24 | ||
25 | for e in page_entries: | |
26 | yield e | |
27 | ||
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) | |
31 | ||
32 | ||
33 | class LastFMPlaylistIE(LastFMPlaylistBaseIE): | |
34 | _VALID_URL = r'https?://(?:www\.)?last\.fm/(music|tag)/(?P<id>[^/]+)(?:/[^/]+)?/?(?:[?#]|$)' | |
35 | _TESTS = [{ | |
36 | 'url': 'https://www.last.fm/music/Oasis/(What%27s+the+Story)+Morning+Glory%3F', | |
37 | 'info_dict': { | |
38 | 'id': 'Oasis', | |
39 | }, | |
40 | 'playlist_count': 11, | |
41 | }, { | |
42 | 'url': 'https://www.last.fm/music/Oasis', | |
43 | 'only_matching': True, | |
44 | }, { | |
45 | 'url': 'https://www.last.fm/music/Oasis/', | |
46 | 'only_matching': True, | |
47 | }, { | |
48 | 'url': 'https://www.last.fm/music/Oasis?top_tracks_date_preset=ALL#top-tracks', | |
49 | 'only_matching': True, | |
50 | }, { | |
51 | 'url': 'https://www.last.fm/music/Oasis/+tracks', | |
52 | 'only_matching': True, | |
53 | }, { | |
54 | 'url': 'https://www.last.fm/music/Oasis/+tracks?page=2', | |
55 | 'only_matching': True, | |
56 | }, { | |
57 | 'url': 'https://www.last.fm/music/Oasis/+tracks?date_preset=LAST_90_DAYS#top-tracks', | |
58 | 'only_matching': True, | |
59 | }, { | |
60 | 'url': 'https://www.last.fm/tag/rock', | |
61 | 'only_matching': True, | |
62 | }, { | |
63 | 'url': 'https://www.last.fm/tag/rock/tracks', | |
64 | 'only_matching': True, | |
65 | }] | |
66 | ||
67 | ||
68 | class LastFMUserIE(LastFMPlaylistBaseIE): | |
69 | _VALID_URL = r'https?://(?:www\.)?last\.fm/user/[^/]+/playlists/(?P<id>[^/#?]+)' | |
70 | _TESTS = [{ | |
71 | 'url': 'https://www.last.fm/user/mehq/playlists/12319471', | |
72 | 'info_dict': { | |
73 | 'id': '12319471', | |
74 | }, | |
75 | 'playlist_count': 30, | |
76 | }] | |
77 | ||
78 | ||
79 | class LastFMIE(InfoExtractor): | |
80 | _VALID_URL = r'https?://(?:www\.)?last\.fm/music(?:/[^/]+){2}/(?P<id>[^/#?]+)' | |
81 | _TESTS = [{ | |
82 | 'url': 'https://www.last.fm/music/Oasis/_/Wonderwall', | |
83 | 'md5': '9c4a70c2e84c03d54fe24229b9e13b7b', | |
84 | 'info_dict': { | |
85 | 'id': '6hzrDeceEKc', | |
86 | 'ext': 'mp4', | |
87 | 'title': 'Oasis - Wonderwall (Official Video)', | |
88 | 'thumbnail': r're:^https?://i.ytimg.com/.*\.jpg$', | |
89 | 'description': 'md5:0848669853c10687cc28e88b5756738f', | |
90 | 'uploader': 'Oasis', | |
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', | |
96 | 'view_count': int, | |
97 | 'live_status': 'not_live', | |
98 | 'channel_url': 'https://www.youtube.com/channel/UCUDVBtnOQi4c7E8jebpjc9Q', | |
99 | 'tags': 'count:39', | |
100 | 'creator': 'Oasis', | |
101 | 'uploader_url': 're:^https?://www.youtube.com/user/oasisinetofficial', | |
102 | 'duration': 279, | |
103 | 'alt_title': 'Wonderwall (Remastered)', | |
104 | 'age_limit': 0, | |
105 | 'channel': 'Oasis', | |
106 | 'channel_follower_count': int, | |
107 | 'categories': ['Music'], | |
108 | 'availability': 'public', | |
109 | 'like_count': int, | |
110 | 'playable_in_embed': True, | |
111 | 'artist': 'Oasis', | |
112 | }, | |
113 | 'add_ie': ['Youtube'], | |
114 | }, { | |
115 | 'url': 'https://www.last.fm/music/Oasis/_/Don%27t+Look+Back+In+Anger+-+Remastered/', | |
116 | 'only_matching': True, | |
117 | }, { | |
118 | 'url': 'https://www.last.fm/music/Guns+N%27+Roses/_/Sweet+Child+o%27+Mine', | |
119 | 'only_matching': True, | |
120 | }] | |
121 | ||
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') |