Browse Source

[ubu] Fix test and modernize

totalwebcasting
Philipp Hagemeister 10 years ago
parent
commit
8604e882a8
1 changed files with 14 additions and 13 deletions
  1. +14
    -13
      youtube_dl/extractor/ubu.py

+ 14
- 13
youtube_dl/extractor/ubu.py View File

@ -3,50 +3,51 @@ from __future__ import unicode_literals
import re import re
from .common import InfoExtractor from .common import InfoExtractor
from ..utils import int_or_none
from ..utils import (
int_or_none,
qualities,
)
class UbuIE(InfoExtractor): class UbuIE(InfoExtractor):
_VALID_URL = r'http://(?:www\.)?ubu\.com/film/(?P<id>[\da-z_-]+)\.html' _VALID_URL = r'http://(?:www\.)?ubu\.com/film/(?P<id>[\da-z_-]+)\.html'
_TEST = { _TEST = {
'url': 'http://ubu.com/film/her_noise.html', 'url': 'http://ubu.com/film/her_noise.html',
'md5': '8edd46ee8aa6b265fb5ed6cf05c36bc9',
'md5': '138d5652618bf0f03878978db9bef1ee',
'info_dict': { 'info_dict': {
'id': 'her_noise', 'id': 'her_noise',
'ext': 'mp4',
'ext': 'm4v',
'title': 'Her Noise - The Making Of (2007)', 'title': 'Her Noise - The Making Of (2007)',
'duration': 3600, 'duration': 3600,
}, },
} }
def _real_extract(self, url): def _real_extract(self, url):
mobj = re.match(self._VALID_URL, url)
video_id = mobj.group('id')
video_id = self._match_id(url)
webpage = self._download_webpage(url, video_id) webpage = self._download_webpage(url, video_id)
title = self._html_search_regex( title = self._html_search_regex(
r'<title>.+?Film &amp; Video: ([^<]+)</title>', webpage, 'title') r'<title>.+?Film &amp; Video: ([^<]+)</title>', webpage, 'title')
duration = int_or_none(self._html_search_regex( duration = int_or_none(self._html_search_regex(
r'Duration: (\d+) minutes', webpage, 'duration', fatal=False, default=None))
if duration:
duration *= 60
r'Duration: (\d+) minutes', webpage, 'duration', fatal=False),
invscale=60)
formats = [] formats = []
FORMAT_REGEXES = [ FORMAT_REGEXES = [
['sq', r"'flashvars'\s*,\s*'file=([^']+)'"],
['hq', r'href="(http://ubumexico\.centro\.org\.mx/video/[^"]+)"']
('sq', r"'flashvars'\s*,\s*'file=([^']+)'"),
('hq', r'href="(http://ubumexico\.centro\.org\.mx/video/[^"]+)"'),
] ]
preference = qualities([fid for fid, _ in FORMAT_REGEXES])
for format_id, format_regex in FORMAT_REGEXES: for format_id, format_regex in FORMAT_REGEXES:
m = re.search(format_regex, webpage) m = re.search(format_regex, webpage)
if m: if m:
formats.append({ formats.append({
'url': m.group(1), 'url': m.group(1),
'format_id': format_id, 'format_id': format_id,
'preference': preference(format_id),
}) })
self._sort_formats(formats)
return { return {
'id': video_id, 'id': video_id,


Loading…
Cancel
Save