119 lines
3.7 KiB
Python
Raw Normal View History

2016-10-15 23:09:44 +02:00
# coding: utf-8
from __future__ import unicode_literals
import re
from .common import InfoExtractor
from ..compat import compat_urlparse
class JamendoIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?jamendo\.com/track/(?P<id>[0-9]+)/(?P<display_id>[\w-]+)'
_TEST = {
'url': 'https://www.jamendo.com/track/196219/stories-from-emona-i',
2016-10-18 13:11:17 +02:00
'md5': '6e9e82ed6db98678f171c25a8ed09ffd',
2016-10-15 23:09:44 +02:00
'info_dict': {
'id': '196219',
'display_id': 'stories-from-emona-i',
2016-10-18 13:11:17 +02:00
'ext': 'flac',
2016-10-15 23:09:44 +02:00
'title': 'Stories from Emona I',
2016-10-24 17:58:58 +02:00
'thumbnail': 're:^https?://.*\.jpg'
2016-10-15 23:09:44 +02:00
}
}
def _real_extract(self, url):
url_data = self._VALID_URL_RE.match(url)
track_id = url_data.group('id')
2016-10-24 18:01:13 +02:00
display_id = url_data.group('display_id')
webpage = self._download_webpage(url, display_id)
2016-10-15 23:09:44 +02:00
thumbnail = self._html_search_meta(
'image', webpage, 'thumbnail', fatal=False)
title = self._html_search_meta('name', webpage, 'title')
2016-10-18 13:11:17 +02:00
formats = [
{
'format_id': 'mp31',
2016-10-24 17:33:44 +02:00
'url': 'https://mp3l.jamendo.com/?trackid=%s&format=mp31'
2016-10-18 13:11:17 +02:00
% track_id,
'ext': 'mp3'
},
{
'format_id': 'mp32',
2016-10-24 17:33:44 +02:00
'url': 'https://mp3d.jamendo.com/?trackid=%s&format=mp32'
2016-10-18 13:11:17 +02:00
% track_id,
'ext': 'mp3'
},
{
'format_id': 'ogg',
2016-10-24 17:33:44 +02:00
'url': 'https://ogg.jamendo.com/?trackid=%s&format=ogg1'
2016-10-18 13:11:17 +02:00
% track_id,
'ext': 'ogg'
},
{
'format_id': 'flac',
2016-10-24 17:33:44 +02:00
'url': 'https://flac.jamendo.com/?trackid=%s&format=flac'
2016-10-18 13:11:17 +02:00
% track_id,
'ext': 'flac'
}
]
2016-10-24 18:01:13 +02:00
self._check_formats(formats, video_id=display_id)
2016-10-15 23:09:44 +02:00
return {
'id': track_id,
2016-10-24 18:01:13 +02:00
'display_id': display_id,
2016-10-15 23:09:44 +02:00
'thumbnail': thumbnail,
2016-10-18 13:11:17 +02:00
'title': title,
'formats': formats
2016-10-15 23:09:44 +02:00
}
class JamendoAlbumIE(InfoExtractor):
_VALID_URL = r'https?://(?:www\.)?jamendo\.com/album/(?P<id>[0-9]+)/(?P<display_id>[\w-]+)'
_TEST = {
'url': 'https://www.jamendo.com/album/121486/duck-on-cover',
'info_dict': {
'id': '121486',
'title': 'Duck On Cover'
},
'playlist_mincount': 2,
'playlist': [
{
'md5': 'e1a2fcb42bda30dfac990212924149a8',
2016-10-15 23:09:44 +02:00
'info_dict': {
'id': '1032333',
'ext': 'flac',
2016-10-15 23:09:44 +02:00
'title': 'Warmachine'
}
},
{
'md5': '1f358d7b2f98edfe90fd55dac0799d50',
2016-10-15 23:09:44 +02:00
'info_dict': {
'id': '1032330',
'ext': 'flac',
2016-10-15 23:09:44 +02:00
'title': 'Without Your Ghost'
}
}
],
'params': {
'playlistend': 2
}
}
def _real_extract(self, url):
url_data = self._VALID_URL_RE.match(url)
album_id = url_data.group('id')
2016-10-24 18:01:13 +02:00
webpage = self._download_webpage(url, url_data.group('display_id'))
2016-10-15 23:09:44 +02:00
title = self._html_search_meta('name', webpage, 'title')
2016-10-15 23:09:44 +02:00
track_paths = re.findall(r'<a href="(.+)" class="link-wrap js-trackrow-albumpage-link" itemprop="url">', webpage)
entries = [
self.url_result(compat_urlparse.urljoin(url, path), ie=JamendoIE.ie_key())
for path in track_paths
]
return {
'_type': 'playlist',
'id': album_id,
'title': title,
'entries': entries
}