[hotnewhiphop] Modernize

This commit is contained in:
Philipp Hagemeister 2014-11-26 12:45:40 +01:00
parent 855dc479c2
commit 5c40bba82f

View file

@ -1,12 +1,13 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import re
import base64 import base64
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..compat import (
compat_urllib_parse, compat_urllib_parse,
compat_urllib_request, compat_urllib_request,
)
from ..utils import (
ExtractorError, ExtractorError,
HEADRequest, HEADRequest,
) )
@ -16,25 +17,24 @@ 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 = {
'url': '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',
'file': '1435540.mp3',
'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96', 'md5': '2c2cd2f76ef11a9b3b581e8b232f3d96',
'info_dict': { 'info_dict': {
'id': '1435540',
'ext': 'mp3',
'title': 'Freddie Gibbs - Lay It Down' 'title': 'Freddie Gibbs - Lay It Down'
} }
} }
def _real_extract(self, url): def _real_extract(self, url):
m = re.match(self._VALID_URL, url) video_id = self._match_id(url)
video_id = m.group('id') webpage = self._download_webpage(url, video_id)
webpage_src = self._download_webpage(url, video_id)
video_url_base64 = self._search_regex( video_url_base64 = self._search_regex(
r'data-path="(.*?)"', webpage_src, u'video URL', fatal=False) r'data-path="(.*?)"', webpage, 'video URL', default=None)
if video_url_base64 is None: if video_url_base64 is None:
video_url = self._search_regex( video_url = self._search_regex(
r'"contentUrl" content="(.*?)"', webpage_src, u'video URL') r'"contentUrl" content="(.*?)"', webpage, 'content URL')
return self.url_result(video_url, ie='Youtube') return self.url_result(video_url, ie='Youtube')
reqdata = compat_urllib_parse.urlencode([ reqdata = compat_urllib_parse.urlencode([
@ -59,11 +59,11 @@ class HotNewHipHopIE(InfoExtractor):
if video_url.endswith('.html'): if video_url.endswith('.html'):
raise ExtractorError('Redirect failed') raise ExtractorError('Redirect failed')
video_title = self._og_search_title(webpage_src).strip() video_title = self._og_search_title(webpage).strip()
return { return {
'id': video_id, 'id': video_id,
'url': video_url, 'url': video_url,
'title': video_title, 'title': video_title,
'thumbnail': self._og_search_thumbnail(webpage_src), 'thumbnail': self._og_search_thumbnail(webpage),
} }