1
0
Fork 0
mirror of https://github.com/ytdl-org/youtube-dl.git synced 2024-11-16 23:26:59 +00:00
youtube-dl/youtube_dl/extractor/ubu.py

58 lines
1.7 KiB
Python
Raw Normal View History

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