hotnewhiphop.py 2.2 KB

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