0
0
Fork 0

[jukebox] Modernize and add a test

main
Jaime Marquínez Ferrándiz 2014-03-09 18:13:17 +01:00
parent bdebf51c8f
commit b4a186b7be
1 changed files with 38 additions and 33 deletions

View File

@ -1,56 +1,61 @@
# coding: utf-8 from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import ( from ..utils import (
ExtractorError, ExtractorError,
RegexNotFoundError,
unescapeHTML, unescapeHTML,
) )
class JukeboxIE(InfoExtractor): class JukeboxIE(InfoExtractor):
_VALID_URL = r'^http://www\.jukebox?\..+?\/.+[,](?P<video_id>[a-z0-9\-]+)\.html' _VALID_URL = r'^http://www\.jukebox?\..+?\/.+[,](?P<video_id>[a-z0-9\-]+)\.html'
_IFRAME = r'<iframe .*src="(?P<iframe>[^"]*)".*>' _TEST = {
_VIDEO_URL = r'"config":{"file":"(?P<video_url>http:[^"]+[.](?P<video_ext>[^.?]+)[?]mdtk=[0-9]+)"' 'url': 'http://www.jukebox.es/kosheen/videoclip,pride,r303r.html',
_TITLE = r'<h1 class="inline">(?P<title>[^<]+)</h1>.*<span id="infos_article_artist">(?P<artist>[^<]+)</span>' 'md5': '5dc6477e74b1e37042ac5acedd8413e5',
_IS_YOUTUBE = r'config":{"file":"(?P<youtube_url>http:[\\][/][\\][/]www[.]youtube[.]com[\\][/]watch[?]v=[^"]+)"' 'info_dict': {
'id': 'r303r',
'ext': 'flv',
'title': 'Kosheen-En Vivo Pride',
'uploader': 'Kosheen',
},
}
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url) mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('video_id') video_id = mobj.group('video_id')
html = self._download_webpage(url, video_id) html = self._download_webpage(url, video_id)
iframe_url = unescapeHTML(self._search_regex(r'<iframe .*src="([^"]*)"', html, 'iframe url'))
mobj = re.search(self._IFRAME, html)
if mobj is None:
raise ExtractorError(u'Cannot extract iframe url')
iframe_url = unescapeHTML(mobj.group('iframe'))
iframe_html = self._download_webpage(iframe_url, video_id, 'Downloading iframe') iframe_html = self._download_webpage(iframe_url, video_id, 'Downloading iframe')
mobj = re.search(r'class="jkb_waiting"', iframe_html) if re.search(r'class="jkb_waiting"', iframe_html) is not None:
if mobj is not None: raise ExtractorError('Video is not available(in your country?)!')
raise ExtractorError(u'Video is not available(in your country?)!')
self.report_extraction(video_id) self.report_extraction(video_id)
mobj = re.search(self._VIDEO_URL, iframe_html) try:
if mobj is None: video_url = self._search_regex(r'"config":{"file":"(?P<video_url>http:[^"]+\?mdtk=[0-9]+)"',
mobj = re.search(self._IS_YOUTUBE, iframe_html) iframe_html, 'video url')
if mobj is None: video_url = unescapeHTML(video_url).replace('\/', '/')
raise ExtractorError(u'Cannot extract video url') except RegexNotFoundError:
youtube_url = unescapeHTML(mobj.group('youtube_url')).replace('\/','/') youtube_url = self._search_regex(
self.to_screen(u'Youtube video detected') r'config":{"file":"(http:\\/\\/www\.youtube\.com\\/watch\?v=[^"]+)"',
return self.url_result(youtube_url,ie='Youtube') iframe_html, 'youtube url')
video_url = unescapeHTML(mobj.group('video_url')).replace('\/','/') youtube_url = unescapeHTML(youtube_url).replace('\/', '/')
video_ext = unescapeHTML(mobj.group('video_ext')) self.to_screen('Youtube video detected')
return self.url_result(youtube_url, ie='Youtube')
mobj = re.search(self._TITLE, html) title = self._html_search_regex(r'<h1 class="inline">([^<]+)</h1>',
if mobj is None: html, 'title')
raise ExtractorError(u'Cannot extract title') artist = self._html_search_regex(r'<span id="infos_article_artist">([^<]+)</span>',
title = unescapeHTML(mobj.group('title')) html, 'artist')
artist = unescapeHTML(mobj.group('artist'))
return [{'id': video_id, return {
'id': video_id,
'url': video_url, 'url': video_url,
'title': artist + '-' + title, 'title': artist + '-' + title,
'ext': video_ext 'uploader': artist,
}] }