mirror of
https://github.com/ytdl-org/youtube-dl
synced 2024-11-27 21:46:54 +01:00
[hotnewhiphop] Retrieve media key
This commit is contained in:
parent
00122de6a9
commit
99f770caa8
@ -1,17 +1,25 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import base64
|
import base64
|
||||||
|
|
||||||
from .common import InfoExtractor
|
from .common import InfoExtractor
|
||||||
|
from ..utils import (
|
||||||
|
compat_urllib_parse,
|
||||||
|
compat_urllib_request,
|
||||||
|
ExtractorError,
|
||||||
|
HEADRequest,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class HotNewHipHopIE(InfoExtractor):
|
class HotNewHipHopIE(InfoExtractor):
|
||||||
_VALID_URL = r'http://www\.hotnewhiphop.com/.*\.(?P<id>.*)\.html'
|
_VALID_URL = r'http://www\.hotnewhiphop.com/.*\.(?P<id>.*)\.html'
|
||||||
_TEST = {
|
_TEST = {
|
||||||
u'url': u"http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html",
|
'url': 'http://www.hotnewhiphop.com/freddie-gibbs-lay-it-down-song.1435540.html',
|
||||||
u'file': u'1435540.mp3',
|
'file': '1435540.mp3',
|
||||||
u'md5': u'2c2cd2f76ef11a9b3b581e8b232f3d96',
|
'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
|
||||||
u'info_dict': {
|
'info_dict': {
|
||||||
u"title": u'Freddie Gibbs "Lay It Down"'
|
'title': 'Freddie Gibbs - Lay It Down'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,24 +29,41 @@ class HotNewHipHopIE(InfoExtractor):
|
|||||||
|
|
||||||
webpage_src = self._download_webpage(url, video_id)
|
webpage_src = self._download_webpage(url, video_id)
|
||||||
|
|
||||||
video_url_base64 = self._search_regex(r'data-path="(.*?)"',
|
video_url_base64 = self._search_regex(
|
||||||
webpage_src, u'video URL', fatal=False)
|
r'data-path="(.*?)"', webpage_src, u'video URL', fatal=False)
|
||||||
|
|
||||||
if video_url_base64 == None:
|
if video_url_base64 is None:
|
||||||
video_url = self._search_regex(r'"contentUrl" content="(.*?)"', webpage_src,
|
video_url = self._search_regex(
|
||||||
u'video URL')
|
r'"contentUrl" content="(.*?)"', webpage_src, u'video URL')
|
||||||
return self.url_result(video_url, ie='Youtube')
|
return self.url_result(video_url, ie='Youtube')
|
||||||
|
|
||||||
video_url = base64.b64decode(video_url_base64).decode('utf-8')
|
reqdata = compat_urllib_parse.urlencode([
|
||||||
|
('mediaType', 's'),
|
||||||
|
('mediaId', video_id),
|
||||||
|
])
|
||||||
|
r = compat_urllib_request.Request(
|
||||||
|
'http://www.hotnewhiphop.com/ajax/media/getActions/', data=reqdata)
|
||||||
|
r.add_header('Content-Type', 'application/x-www-form-urlencoded')
|
||||||
|
mkd = self._download_json(
|
||||||
|
r, video_id, note='Requesting media key',
|
||||||
|
errnote='Could not download media key')
|
||||||
|
if 'mediaKey' not in mkd:
|
||||||
|
raise ExtractorError('Did not get a media key')
|
||||||
|
|
||||||
video_title = self._html_search_regex(r"<title>(.*)</title>",
|
redirect_url = base64.b64decode(video_url_base64).decode('utf-8')
|
||||||
webpage_src, u'title')
|
redirect_req = HEADRequest(redirect_url)
|
||||||
|
req = self._request_webpage(
|
||||||
|
redirect_req, video_id,
|
||||||
|
note='Resolving final URL', errnote='Could not resolve final URL')
|
||||||
|
video_url = req.geturl()
|
||||||
|
if video_url.endswith('.html'):
|
||||||
|
raise ExtractorError('Redirect failed')
|
||||||
|
|
||||||
results = [{
|
video_title = self._og_search_title(webpage_src).strip()
|
||||||
'id': video_id,
|
|
||||||
'url' : video_url,
|
return {
|
||||||
'title' : video_title,
|
'id': video_id,
|
||||||
'thumbnail' : self._og_search_thumbnail(webpage_src),
|
'url': video_url,
|
||||||
'ext' : 'mp3',
|
'title': video_title,
|
||||||
}]
|
'thumbnail': self._og_search_thumbnail(webpage_src),
|
||||||
return results
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user