2 from __future__ import unicode_literals
7 from ..compat import compat_str
8 from .common import InfoExtractor
16 class JamendoIE(InfoExtractor):
20 licensing\.jamendo\.com/[^/]+|
21 (?:www\.)?jamendo\.com
23 /track/(?P<id>[0-9]+)(?:/(?P<display_id>[^/?#&]+))?
26 'url': 'https://www.jamendo.com/track/196219/stories-from-emona-i',
27 'md5': '6e9e82ed6db98678f171c25a8ed09ffd',
30 'display_id': 'stories-from-emona-i',
32 'title': 'Maya Filipič - Stories from Emona I',
33 'artist': 'Maya Filipič',
34 'track': 'Stories from Emona I',
36 'thumbnail': r're:^https?://.*\.jpg',
37 'timestamp': 1217438117,
38 'upload_date': '20080730',
41 'url': 'https://licensing.jamendo.com/en/track/1496667/energetic-rock',
42 'only_matching': True,
45 def _real_extract(self, url):
46 track_id, display_id = self._VALID_URL_RE.match(url).groups()
47 webpage = self._download_webpage(
48 'https://www.jamendo.com/track/' + track_id, track_id)
49 models = self._parse_json(self._html_search_regex(
50 r"data-bundled-models='([^']+)",
51 webpage, 'bundled models'), track_id)
52 track = models['track']['models'][0]
53 title = track_name = track['name']
54 get_model = lambda x: try_get(models, lambda y: y[x]['models'][0], dict) or {}
55 artist = get_model('artist')
56 artist_name = artist.get('name')
58 title = '%s - %s' % (artist_name, title)
59 album = get_model('album')
62 'url': 'https://%s.jamendo.com/?trackid=%s&format=%s&from=app-97dab294'
63 % (sub_domain, track_id, format_id),
64 'format_id': format_id,
67 } for quality, (format_id, sub_domain, ext) in enumerate((
68 ('mp31', 'mp3l', 'mp3'),
69 ('mp32', 'mp3d', 'mp3'),
70 ('ogg1', 'ogg', 'ogg'),
71 ('flac', 'flac', 'flac'),
73 self._sort_formats(formats)
77 for _, covers in track.get('cover', {}).items():
78 for cover_id, cover_url in covers.items():
79 if not cover_url or cover_url in urls:
81 urls.append(cover_url)
82 size = int_or_none(cover_id.lstrip('size'))
91 for tag in track.get('tags', []):
92 tag_name = tag.get('name')
97 stats = track.get('stats') or {}
101 'display_id': display_id,
102 'thumbnails': thumbnails,
104 'description': track.get('description'),
105 'duration': int_or_none(track.get('duration')),
106 'artist': artist_name,
108 'album': album.get('name'),
110 'license': '-'.join(track.get('licenseCC', [])) or None,
111 'timestamp': int_or_none(track.get('dateCreated')),
112 'view_count': int_or_none(stats.get('listenedAll')),
113 'like_count': int_or_none(stats.get('favorited')),
114 'average_rating': int_or_none(stats.get('averageNote')),
119 class JamendoAlbumIE(InfoExtractor):
120 _VALID_URL = r'https?://(?:www\.)?jamendo\.com/album/(?P<id>[0-9]+)'
122 'url': 'https://www.jamendo.com/album/121486/duck-on-cover',
125 'title': 'Duck On Cover',
126 'description': 'md5:c2920eaeef07d7af5b96d7c64daf1239',
129 'md5': 'e1a2fcb42bda30dfac990212924149a8',
133 'title': 'Shearer - Warmachine',
135 'track': 'Warmachine',
136 'timestamp': 1368089771,
137 'upload_date': '20130509',
140 'md5': '1f358d7b2f98edfe90fd55dac0799d50',
144 'title': 'Shearer - Without Your Ghost',
146 'track': 'Without Your Ghost',
147 'timestamp': 1368089771,
148 'upload_date': '20130509',
156 def _call_api(self, resource, resource_id):
157 path = '/api/%ss' % resource
158 rand = compat_str(random.random())
159 return self._download_json(
160 'https://www.jamendo.com' + path, resource_id, query={
163 'X-Jam-Call': '$%s*%s~' % (hashlib.sha1((path + rand).encode()).hexdigest(), rand)
166 def _real_extract(self, url):
167 album_id = self._match_id(url)
168 album = self._call_api('album', album_id)
169 album_name = album.get('name')
172 for track in album.get('tracks', []):
173 track_id = track.get('id')
176 track_id = compat_str(track_id)
178 '_type': 'url_transparent',
179 'url': 'https://www.jamendo.com/track/' + track_id,
180 'ie_key': JamendoIE.ie_key(),
185 return self.playlist_result(
186 entries, album_id, album_name,
187 clean_html(try_get(album, lambda x: x['description']['en'], compat_str)))