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.

102 lines
3.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. from .common import InfoExtractor
  4. from ..utils import unified_strdate
  5. class TheSixtyOneIE(InfoExtractor):
  6. _VALID_URL = r'''(?x)https?://(?:www\.)?thesixtyone\.com/
  7. (?:.*?/)*
  8. (?:
  9. s|
  10. song/comments/list|
  11. song
  12. )/(?P<id>[A-Za-z0-9]+)/?$'''
  13. _SONG_URL_TEMPLATE = 'http://thesixtyone.com/s/{0:}'
  14. _SONG_FILE_URL_TEMPLATE = 'http://{audio_server:}/thesixtyone_production/audio/{0:}_stream'
  15. _THUMBNAIL_URL_TEMPLATE = '{photo_base_url:}_desktop'
  16. _TESTS = [
  17. {
  18. 'url': 'http://www.thesixtyone.com/s/SrE3zD7s1jt/',
  19. 'md5': '821cc43b0530d3222e3e2b70bb4622ea',
  20. 'info_dict': {
  21. 'id': 'SrE3zD7s1jt',
  22. 'ext': 'mp3',
  23. 'title': 'CASIO - Unicorn War Mixtape',
  24. 'thumbnail': 're:^https?://.*_desktop$',
  25. 'upload_date': '20071217',
  26. 'duration': 3208,
  27. }
  28. },
  29. {
  30. 'url': 'http://www.thesixtyone.com/song/comments/list/SrE3zD7s1jt',
  31. 'only_matching': True,
  32. },
  33. {
  34. 'url': 'http://www.thesixtyone.com/s/ULoiyjuJWli#/s/SrE3zD7s1jt/',
  35. 'only_matching': True,
  36. },
  37. {
  38. 'url': 'http://www.thesixtyone.com/#/s/SrE3zD7s1jt/',
  39. 'only_matching': True,
  40. },
  41. {
  42. 'url': 'http://www.thesixtyone.com/song/SrE3zD7s1jt/',
  43. 'only_matching': True,
  44. },
  45. ]
  46. _DECODE_MAP = {
  47. 'x': 'a',
  48. 'm': 'b',
  49. 'w': 'c',
  50. 'q': 'd',
  51. 'n': 'e',
  52. 'p': 'f',
  53. 'a': '0',
  54. 'h': '1',
  55. 'e': '2',
  56. 'u': '3',
  57. 's': '4',
  58. 'i': '5',
  59. 'o': '6',
  60. 'y': '7',
  61. 'r': '8',
  62. 'c': '9'
  63. }
  64. def _real_extract(self, url):
  65. song_id = self._match_id(url)
  66. webpage = self._download_webpage(
  67. self._SONG_URL_TEMPLATE.format(song_id), song_id)
  68. song_data = self._parse_json(self._search_regex(
  69. r'"%s":\s(\{.*?\})' % song_id, webpage, 'song_data'), song_id)
  70. if self._search_regex(r'(t61\.s3_audio_load\s*=\s*1\.0;)', webpage, 's3_audio_load marker', default=None):
  71. song_data['audio_server'] = 's3.amazonaws.com'
  72. else:
  73. song_data['audio_server'] = song_data['audio_server'] + '.thesixtyone.com'
  74. keys = [self._DECODE_MAP.get(s, s) for s in song_data['key']]
  75. url = self._SONG_FILE_URL_TEMPLATE.format(
  76. "".join(reversed(keys)), **song_data)
  77. formats = [{
  78. 'format_id': 'sd',
  79. 'url': url,
  80. 'ext': 'mp3',
  81. }]
  82. return {
  83. 'id': song_id,
  84. 'title': '{artist:} - {name:}'.format(**song_data),
  85. 'formats': formats,
  86. 'comment_count': song_data.get('comments_count'),
  87. 'duration': song_data.get('play_time'),
  88. 'like_count': song_data.get('score'),
  89. 'thumbnail': self._THUMBNAIL_URL_TEMPLATE.format(**song_data),
  90. 'upload_date': unified_strdate(song_data.get('publish_date')),
  91. }