]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/jamendo.py
debian/control: Rerun wrap-and-sort.
[youtubedl] / youtube_dl / extractor / jamendo.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from ..compat import compat_urlparse
7 from .common import InfoExtractor
8
9
10 class JamendoIE(InfoExtractor):
11 _VALID_URL = r'https?://(?:www\.)?jamendo\.com/track/(?P<id>[0-9]+)/(?P<display_id>[^/?#&]+)'
12 _TEST = {
13 'url': 'https://www.jamendo.com/track/196219/stories-from-emona-i',
14 'md5': '6e9e82ed6db98678f171c25a8ed09ffd',
15 'info_dict': {
16 'id': '196219',
17 'display_id': 'stories-from-emona-i',
18 'ext': 'flac',
19 'title': 'Stories from Emona I',
20 'thumbnail': 're:^https?://.*\.jpg'
21 }
22 }
23
24 def _real_extract(self, url):
25 mobj = self._VALID_URL_RE.match(url)
26 track_id = mobj.group('id')
27 display_id = mobj.group('display_id')
28
29 webpage = self._download_webpage(url, display_id)
30
31 title = self._html_search_meta('name', webpage, 'title')
32
33 formats = [{
34 'url': 'https://%s.jamendo.com/?trackid=%s&format=%s&from=app-97dab294'
35 % (sub_domain, track_id, format_id),
36 'format_id': format_id,
37 'ext': ext,
38 'quality': quality,
39 } for quality, (format_id, sub_domain, ext) in enumerate((
40 ('mp31', 'mp3l', 'mp3'),
41 ('mp32', 'mp3d', 'mp3'),
42 ('ogg1', 'ogg', 'ogg'),
43 ('flac', 'flac', 'flac'),
44 ))]
45 self._sort_formats(formats)
46
47 thumbnail = self._html_search_meta(
48 'image', webpage, 'thumbnail', fatal=False)
49
50 return {
51 'id': track_id,
52 'display_id': display_id,
53 'thumbnail': thumbnail,
54 'title': title,
55 'formats': formats
56 }
57
58
59 class JamendoAlbumIE(InfoExtractor):
60 _VALID_URL = r'https?://(?:www\.)?jamendo\.com/album/(?P<id>[0-9]+)/(?P<display_id>[\w-]+)'
61 _TEST = {
62 'url': 'https://www.jamendo.com/album/121486/duck-on-cover',
63 'info_dict': {
64 'id': '121486',
65 'title': 'Duck On Cover'
66 },
67 'playlist': [{
68 'md5': 'e1a2fcb42bda30dfac990212924149a8',
69 'info_dict': {
70 'id': '1032333',
71 'ext': 'flac',
72 'title': 'Warmachine'
73 }
74 }, {
75 'md5': '1f358d7b2f98edfe90fd55dac0799d50',
76 'info_dict': {
77 'id': '1032330',
78 'ext': 'flac',
79 'title': 'Without Your Ghost'
80 }
81 }],
82 'params': {
83 'playlistend': 2
84 }
85 }
86
87 def _real_extract(self, url):
88 mobj = self._VALID_URL_RE.match(url)
89 album_id = mobj.group('id')
90
91 webpage = self._download_webpage(url, mobj.group('display_id'))
92
93 title = self._html_search_meta('name', webpage, 'title')
94
95 entries = [
96 self.url_result(
97 compat_urlparse.urljoin(url, m.group('path')),
98 ie=JamendoIE.ie_key(),
99 video_id=self._search_regex(
100 r'/track/(\d+)', m.group('path'),
101 'track id', default=None))
102 for m in re.finditer(
103 r'<a[^>]+href=(["\'])(?P<path>(?:(?!\1).)+)\1[^>]+class=["\'][^>]*js-trackrow-albumpage-link',
104 webpage)
105 ]
106
107 return self.playlist_result(entries, album_id, title)