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.

69 lines
2.1 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. import time
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. compat_str,
  8. compat_urllib_parse,
  9. compat_urllib_request,
  10. ExtractorError,
  11. )
  12. class HypemIE(InfoExtractor):
  13. _VALID_URL = r'http://(?:www\.)?hypem\.com/track/([^/]+)/([^/]+)'
  14. _TEST = {
  15. 'url': 'http://hypem.com/track/1v6ga/BODYWORK+-+TAME',
  16. 'md5': 'b9cc91b5af8995e9f0c1cee04c575828',
  17. 'info_dict': {
  18. 'id': '1v6ga',
  19. 'ext': 'mp3',
  20. 'title': 'Tame',
  21. 'uploader': 'BODYWORK',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. mobj = re.match(self._VALID_URL, url)
  26. track_id = mobj.group(1)
  27. data = {'ax': 1, 'ts': time.time()}
  28. data_encoded = compat_urllib_parse.urlencode(data)
  29. complete_url = url + "?" + data_encoded
  30. request = compat_urllib_request.Request(complete_url)
  31. response, urlh = self._download_webpage_handle(
  32. request, track_id, 'Downloading webpage with the url')
  33. cookie = urlh.headers.get('Set-Cookie', '')
  34. html_tracks = self._html_search_regex(
  35. r'(?ms)<script type="application/json" id="displayList-data">\s*(.*?)\s*</script>',
  36. response, 'tracks')
  37. try:
  38. track_list = json.loads(html_tracks)
  39. track = track_list['tracks'][0]
  40. except ValueError:
  41. raise ExtractorError('Hypemachine contained invalid JSON.')
  42. key = track['key']
  43. track_id = track['id']
  44. artist = track['artist']
  45. title = track['song']
  46. serve_url = "http://hypem.com/serve/source/%s/%s" % (track_id, key)
  47. request = compat_urllib_request.Request(
  48. serve_url, '', {'Content-Type': 'application/json'})
  49. request.add_header('cookie', cookie)
  50. song_data = self._download_json(request, track_id, 'Downloading metadata')
  51. final_url = song_data["url"]
  52. return {
  53. 'id': track_id,
  54. 'url': final_url,
  55. 'ext': 'mp3',
  56. 'title': title,
  57. 'uploader': artist,
  58. }