logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

hotnewhiphop.py (2283B)


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