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.

67 lines
2.1 KiB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. from __future__ import unicode_literals
  2. import json
  3. import time
  4. from .common import InfoExtractor
  5. from ..compat import (
  6. compat_urllib_parse,
  7. compat_urllib_request,
  8. )
  9. from ..utils import (
  10. ExtractorError,
  11. )
  12. class HypemIE(InfoExtractor):
  13. _VALID_URL = r'http://(?:www\.)?hypem\.com/track/(?P<id>[^/]+)/'
  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. track_id = self._match_id(url)
  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. }