]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/lastfm.py
[ie/youtube] Suppress "Unavailable videos are hidden" warning (#10159)
[yt-dlp.git] / yt_dlp / extractor / lastfm.py
CommitLineData
02643571 1import itertools
b8f2f8f6 2import re
3
4from .common import InfoExtractor
02643571 5from ..utils import int_or_none, parse_qs, traverse_obj
b8f2f8f6 6
7
8class LastFMPlaylistBaseIE(InfoExtractor):
9 def _entries(self, url, playlist_id):
02643571
HTL
10 single_page = traverse_obj(parse_qs(url), ('page', -1, {int_or_none}))
11 for page in itertools.count(single_page or 1):
b8f2f8f6 12 webpage = self._download_webpage(
02643571
HTL
13 url, playlist_id, f'Downloading page {page}', query={'page': page})
14 videos = re.findall(r'data-youtube-url="([^"]+)"', webpage)
15 yield from videos
16 if single_page or not videos:
17 return
b8f2f8f6 18
19 def _real_extract(self, url):
20 playlist_id = self._match_id(url)
02643571 21 return self.playlist_from_matches(self._entries(url, playlist_id), playlist_id, ie='Youtube')
b8f2f8f6 22
23
24class LastFMPlaylistIE(LastFMPlaylistBaseIE):
25 _VALID_URL = r'https?://(?:www\.)?last\.fm/(music|tag)/(?P<id>[^/]+)(?:/[^/]+)?/?(?:[?#]|$)'
26 _TESTS = [{
27 'url': 'https://www.last.fm/music/Oasis/(What%27s+the+Story)+Morning+Glory%3F',
28 'info_dict': {
29 'id': 'Oasis',
30 },
02643571 31 'playlist_mincount': 11,
b8f2f8f6 32 }, {
33 'url': 'https://www.last.fm/music/Oasis',
34 'only_matching': True,
35 }, {
36 'url': 'https://www.last.fm/music/Oasis/',
37 'only_matching': True,
38 }, {
39 'url': 'https://www.last.fm/music/Oasis?top_tracks_date_preset=ALL#top-tracks',
40 'only_matching': True,
41 }, {
42 'url': 'https://www.last.fm/music/Oasis/+tracks',
43 'only_matching': True,
44 }, {
45 'url': 'https://www.last.fm/music/Oasis/+tracks?page=2',
46 'only_matching': True,
47 }, {
48 'url': 'https://www.last.fm/music/Oasis/+tracks?date_preset=LAST_90_DAYS#top-tracks',
49 'only_matching': True,
50 }, {
51 'url': 'https://www.last.fm/tag/rock',
52 'only_matching': True,
53 }, {
54 'url': 'https://www.last.fm/tag/rock/tracks',
55 'only_matching': True,
56 }]
57
58
59class LastFMUserIE(LastFMPlaylistBaseIE):
60 _VALID_URL = r'https?://(?:www\.)?last\.fm/user/[^/]+/playlists/(?P<id>[^/#?]+)'
61 _TESTS = [{
62 'url': 'https://www.last.fm/user/mehq/playlists/12319471',
63 'info_dict': {
64 'id': '12319471',
65 },
66 'playlist_count': 30,
02643571
HTL
67 }, {
68 'url': 'https://www.last.fm/user/naamloos1/playlists/12543760',
69 'info_dict': {
70 'id': '12543760',
71 },
72 'playlist_mincount': 80,
73 }, {
74 'url': 'https://www.last.fm/user/naamloos1/playlists/12543760?page=3',
75 'info_dict': {
76 'id': '12543760',
77 },
78 'playlist_count': 32,
b8f2f8f6 79 }]
80
81
82class LastFMIE(InfoExtractor):
83 _VALID_URL = r'https?://(?:www\.)?last\.fm/music(?:/[^/]+){2}/(?P<id>[^/#?]+)'
84 _TESTS = [{
85 'url': 'https://www.last.fm/music/Oasis/_/Wonderwall',
86 'md5': '9c4a70c2e84c03d54fe24229b9e13b7b',
87 'info_dict': {
88 'id': '6hzrDeceEKc',
89 'ext': 'mp4',
90 'title': 'Oasis - Wonderwall (Official Video)',
91 'thumbnail': r're:^https?://i.ytimg.com/.*\.jpg$',
92 'description': 'md5:0848669853c10687cc28e88b5756738f',
93 'uploader': 'Oasis',
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',
99 'view_count': int,
100 'live_status': 'not_live',
101 'channel_url': 'https://www.youtube.com/channel/UCUDVBtnOQi4c7E8jebpjc9Q',
102 'tags': 'count:39',
103 'creator': 'Oasis',
104 'uploader_url': 're:^https?://www.youtube.com/user/oasisinetofficial',
105 'duration': 279,
106 'alt_title': 'Wonderwall (Remastered)',
107 'age_limit': 0,
108 'channel': 'Oasis',
109 'channel_follower_count': int,
110 'categories': ['Music'],
111 'availability': 'public',
112 'like_count': int,
113 'playable_in_embed': True,
114 'artist': 'Oasis',
115 },
116 'add_ie': ['Youtube'],
117 }, {
118 'url': 'https://www.last.fm/music/Oasis/_/Don%27t+Look+Back+In+Anger+-+Remastered/',
119 'only_matching': True,
120 }, {
121 'url': 'https://www.last.fm/music/Guns+N%27+Roses/_/Sweet+Child+o%27+Mine',
122 'only_matching': True,
123 }]
124
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')