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