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.

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