hearthisat.py 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. from .common import InfoExtractor
  2. from ..utils import (
  3. KNOWN_EXTENSIONS,
  4. determine_ext,
  5. str_to_int,
  6. )
  7. class HearThisAtIE(InfoExtractor):
  8. _VALID_URL = r'https?://(?:www\.)?hearthis\.at/(?P<artist>[^/?#]+)/(?P<title>[\w.-]+)'
  9. _PLAYLIST_URL = 'https://hearthis.at/playlist.php'
  10. _TESTS = [{
  11. 'url': 'https://hearthis.at/moofi/dr-kreep',
  12. 'md5': 'ab6ec33c8fed6556029337c7885eb4e0',
  13. 'info_dict': {
  14. 'id': '150939',
  15. 'display_id': 'moofi - dr-kreep',
  16. 'ext': 'wav',
  17. 'title': 'Moofi - Dr. Kreep',
  18. 'thumbnail': r're:^https?://.*\.jpg$',
  19. 'timestamp': 1421564134,
  20. 'description': 'md5:1adb0667b01499f9d27e97ddfd53852a',
  21. 'upload_date': '20150118',
  22. 'view_count': int,
  23. 'duration': 70,
  24. 'genres': ['Experimental'],
  25. },
  26. }, {
  27. # 'download' link redirects to the original webpage
  28. 'url': 'https://hearthis.at/twitchsf/dj-jim-hopkins-totally-bitchin-80s-dance-mix/',
  29. 'md5': '5980ceb7c461605d30f1f039df160c6e',
  30. 'info_dict': {
  31. 'id': '811296',
  32. 'display_id': 'twitchsf - dj-jim-hopkins-totally-bitchin-80s-dance-mix',
  33. 'ext': 'mp3',
  34. 'title': 'TwitchSF - DJ Jim Hopkins - Totally Bitchin\' 80\'s Dance Mix!',
  35. 'description': 'md5:ef26815ca8f483272a87b137ff175be2',
  36. 'upload_date': '20160328',
  37. 'timestamp': 1459186146,
  38. 'thumbnail': r're:^https?://.*\.jpg$',
  39. 'view_count': int,
  40. 'duration': 4360,
  41. 'genres': ['Dance'],
  42. },
  43. }, {
  44. 'url': 'https://hearthis.at/tindalos/0001-tindalos-gnrique/eQd/',
  45. 'md5': 'cd08e51911f147f6da2d9678905b0bd9',
  46. 'info_dict': {
  47. 'id': '2685222',
  48. 'ext': 'mp3',
  49. 'duration': 86,
  50. 'view_count': int,
  51. 'timestamp': 1545471670,
  52. 'display_id': 'tindalos - 0001-tindalos-gnrique',
  53. 'thumbnail': r're:^https?://.*\.jpg$',
  54. 'genres': ['Other'],
  55. 'title': 'Tindalos - Tindalos - générique n°1',
  56. 'description': '',
  57. 'upload_date': '20181222',
  58. },
  59. }, {
  60. 'url': 'https://hearthis.at/sithi2/biochip-c-classics-set-wolle-xdp-tresor.core-special-tresor-globus-berlin-13.07.20011/',
  61. 'md5': 'b45ac60f0c8111eef6ddc10ec232e312',
  62. 'info_dict': {
  63. 'id': '7145959',
  64. 'ext': 'mp3',
  65. 'description': 'md5:d7ae36a453d78903f6b7ed6eb2fce1f2',
  66. 'duration': 8986,
  67. 'thumbnail': r're:^https?://.*\.jpg$',
  68. 'title': 'md5:62669ce5b1b67f45c6f846033f37d3b9',
  69. 'timestamp': 1588699409,
  70. 'display_id': 'sithi2 - biochip-c-classics-set-wolle-xdp-tresor.core-special-tresor-globus-berlin-13.07.20011',
  71. 'view_count': int,
  72. 'upload_date': '20200505',
  73. 'genres': ['Other'],
  74. },
  75. }]
  76. def _real_extract(self, url):
  77. m = self._match_valid_url(url)
  78. display_id = '{artist:s} - {title:s}'.format(**m.groupdict())
  79. api_url = url.replace('www.', '').replace('hearthis.at', 'api-v2.hearthis.at')
  80. data_json = self._download_json(api_url, display_id)
  81. track_id = data_json.get('id')
  82. artist_json = data_json.get('user')
  83. title = '{} - {}'.format(artist_json.get('username'), data_json.get('title'))
  84. genre = data_json.get('genre')
  85. description = data_json.get('description')
  86. thumbnail = data_json.get('artwork_url') or data_json.get('thumb')
  87. view_count = str_to_int(data_json.get('playback_count'))
  88. duration = str_to_int(data_json.get('duration'))
  89. timestamp = data_json.get('release_timestamp')
  90. formats = []
  91. mp3_url = data_json.get('stream_url')
  92. if mp3_url:
  93. formats.append({
  94. 'format_id': 'mp3',
  95. 'vcodec': 'none',
  96. 'acodec': 'mp3',
  97. 'url': mp3_url,
  98. 'ext': 'mp3',
  99. })
  100. if data_json.get('download_url'):
  101. download_url = data_json['download_url']
  102. ext = determine_ext(data_json['download_filename'])
  103. if ext in KNOWN_EXTENSIONS:
  104. formats.append({
  105. 'format_id': ext,
  106. 'vcodec': 'none',
  107. 'ext': ext,
  108. 'url': download_url,
  109. 'acodec': ext,
  110. 'quality': 2, # Usually better quality
  111. })
  112. return {
  113. 'id': track_id,
  114. 'display_id': display_id,
  115. 'title': title,
  116. 'formats': formats,
  117. 'thumbnail': thumbnail,
  118. 'description': description,
  119. 'duration': duration,
  120. 'timestamp': timestamp,
  121. 'view_count': view_count,
  122. 'genre': genre,
  123. }