- url_data = self._VALID_URL_RE.match(url)
- track_id = url_data.group('id')
- display_id = url_data.group('display_id')
- webpage = self._download_webpage(url, display_id)
-
- thumbnail = self._html_search_meta(
- 'image', webpage, 'thumbnail', fatal=False)
- title = self._html_search_meta('name', webpage, 'title')
-
- url_template = 'https://%s.jamendo.com/?trackid=%s&format=%s&from=app-97dab294'
- format_data = [
- FormatData(
- format_id='mp31', sub_domain='mp3l', ext='mp3', quality=0),
- FormatData(
- format_id='mp32', sub_domain='mp3d', ext='mp3', quality=1),
- FormatData(
- format_id='ogg1', sub_domain='ogg', ext='ogg', quality=2),
- FormatData(
- format_id='flac', sub_domain='flac', ext='flac', quality=3),
- ]
- formats = [
- {
- 'format_id': fd.format_id,
- 'url': url_template % (fd.sub_domain, track_id, fd.format_id),
- 'ext': fd.ext,
- 'quality': fd.quality
- }
- for fd in format_data
- ]
- self._check_formats(formats, video_id=display_id)
+ track_id, display_id = self._VALID_URL_RE.match(url).groups()
+ webpage = self._download_webpage(
+ 'https://www.jamendo.com/track/' + track_id, track_id)
+ models = self._parse_json(self._html_search_regex(
+ r"data-bundled-models='([^']+)",
+ webpage, 'bundled models'), track_id)
+ track = models['track']['models'][0]
+ title = track_name = track['name']
+ get_model = lambda x: try_get(models, lambda y: y[x]['models'][0], dict) or {}
+ artist = get_model('artist')
+ artist_name = artist.get('name')
+ if artist_name:
+ title = '%s - %s' % (artist_name, title)
+ album = get_model('album')
+
+ formats = [{
+ 'url': 'https://%s.jamendo.com/?trackid=%s&format=%s&from=app-97dab294'
+ % (sub_domain, track_id, format_id),
+ 'format_id': format_id,
+ 'ext': ext,
+ 'quality': quality,
+ } for quality, (format_id, sub_domain, ext) in enumerate((
+ ('mp31', 'mp3l', 'mp3'),
+ ('mp32', 'mp3d', 'mp3'),
+ ('ogg1', 'ogg', 'ogg'),
+ ('flac', 'flac', 'flac'),
+ ))]
+ self._sort_formats(formats)
+
+ urls = []
+ thumbnails = []
+ for _, covers in track.get('cover', {}).items():
+ for cover_id, cover_url in covers.items():
+ if not cover_url or cover_url in urls:
+ continue
+ urls.append(cover_url)
+ size = int_or_none(cover_id.lstrip('size'))
+ thumbnails.append({
+ 'id': cover_id,
+ 'url': cover_url,
+ 'width': size,
+ 'height': size,
+ })
+
+ tags = []
+ for tag in track.get('tags', []):
+ tag_name = tag.get('name')
+ if not tag_name:
+ continue
+ tags.append(tag_name)
+
+ stats = track.get('stats') or {}
+