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.3 KiB

  1. from __future__ import unicode_literals
  2. import base64
  3. from .common import InfoExtractor
  4. from ..compat import (
  5. compat_urllib_parse,
  6. compat_urllib_request,
  7. )
  8. from ..utils import (
  9. ExtractorError,
  10. HEADRequest,
  11. )
  12. class HotNewHipHopIE(InfoExtractor):
  13. _VALID_URL = r'http://www\.hotnewhiphop\.com/.*\.(?P<id>.*)\.html'
  14. _TEST = {
  15. 'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html',
  16. 'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
  17. 'info_dict': {
  18. 'id': '1435540',
  19. 'ext': 'mp3',
  20. 'title': 'Freddie Gibbs - Lay It Down'
  21. }
  22. }
  23. def _real_extract(self, url):
  24. video_id = self._match_id(url)
  25. webpage = self._download_webpage(url, video_id)
  26. video_url_base64 = self._search_regex(
  27. r'data-path="(.*?)"', webpage, 'video URL', default=None)
  28. if video_url_base64 is None:
  29. video_url = self._search_regex(
  30. r'"contentUrl" content="(.*?)"', webpage, 'content URL')
  31. return self.url_result(video_url, ie='Youtube')
  32. reqdata = compat_urllib_parse.urlencode([
  33. ('mediaType', 's'),
  34. ('mediaId', video_id),
  35. ])
  36. r = compat_urllib_request.Request(
  37. 'http://www.hotnewhiphop.com/ajax/media/getActions/', data=reqdata)
  38. r.add_header('Content-Type', 'application/x-www-form-urlencoded')
  39. mkd = self._download_json(
  40. r, video_id, note='Requesting media key',
  41. errnote='Could not download media key')
  42. if 'mediaKey' not in mkd:
  43. raise ExtractorError('Did not get a media key')
  44. redirect_url = base64.b64decode(video_url_base64).decode('utf-8')
  45. redirect_req = HEADRequest(redirect_url)
  46. req = self._request_webpage(
  47. redirect_req, video_id,
  48. note='Resolving final URL', errnote='Could not resolve final URL')
  49. video_url = req.geturl()
  50. if video_url.endswith('.html'):
  51. raise ExtractorError('Redirect failed')
  52. video_title = self._og_search_title(webpage).strip()
  53. return {
  54. 'id': video_id,
  55. 'url': video_url,
  56. 'title': video_title,
  57. 'thumbnail': self._og_search_thumbnail(webpage),
  58. }