You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.3 KiB

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