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.

106 lines
3.3 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. 'url': 'http://www.thesixtyone.com/maryatmidnight/song/StrawberriesandCream/yvWtLp0c4GQ/',
  47. 'only_matching': True,
  48. },
  49. ]
  50. _DECODE_MAP = {
  51. 'x': 'a',
  52. 'm': 'b',
  53. 'w': 'c',
  54. 'q': 'd',
  55. 'n': 'e',
  56. 'p': 'f',
  57. 'a': '0',
  58. 'h': '1',
  59. 'e': '2',
  60. 'u': '3',
  61. 's': '4',
  62. 'i': '5',
  63. 'o': '6',
  64. 'y': '7',
  65. 'r': '8',
  66. 'c': '9'
  67. }
  68. def _real_extract(self, url):
  69. song_id = self._match_id(url)
  70. webpage = self._download_webpage(
  71. self._SONG_URL_TEMPLATE.format(song_id), song_id)
  72. song_data = self._parse_json(self._search_regex(
  73. r'"%s":\s(\{.*?\})' % song_id, webpage, 'song_data'), song_id)
  74. if self._search_regex(r'(t61\.s3_audio_load\s*=\s*1\.0;)', webpage, 's3_audio_load marker', default=None):
  75. song_data['audio_server'] = 's3.amazonaws.com'
  76. else:
  77. song_data['audio_server'] = song_data['audio_server'] + '.thesixtyone.com'
  78. keys = [self._DECODE_MAP.get(s, s) for s in song_data['key']]
  79. url = self._SONG_FILE_URL_TEMPLATE.format(
  80. "".join(reversed(keys)), **song_data)
  81. formats = [{
  82. 'format_id': 'sd',
  83. 'url': url,
  84. 'ext': 'mp3',
  85. }]
  86. return {
  87. 'id': song_id,
  88. 'title': '{artist:} - {name:}'.format(**song_data),
  89. 'formats': formats,
  90. 'comment_count': song_data.get('comments_count'),
  91. 'duration': song_data.get('play_time'),
  92. 'like_count': song_data.get('score'),
  93. 'thumbnail': self._THUMBNAIL_URL_TEMPLATE.format(**song_data),
  94. 'upload_date': unified_strdate(song_data.get('publish_date')),
  95. }