You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.7 KiB

  1. from __future__ import unicode_literals
  2. import re
  3. from .common import InfoExtractor
  4. from ..utils import (
  5. int_or_none,
  6. qualities,
  7. )
  8. class UbuIE(InfoExtractor):
  9. _VALID_URL = r'http://(?:www\.)?ubu\.com/film/(?P<id>[\da-z_-]+)\.html'
  10. _TEST = {
  11. 'url': 'http://ubu.com/film/her_noise.html',
  12. 'md5': '138d5652618bf0f03878978db9bef1ee',
  13. 'info_dict': {
  14. 'id': 'her_noise',
  15. 'ext': 'm4v',
  16. 'title': 'Her Noise - The Making Of (2007)',
  17. 'duration': 3600,
  18. },
  19. }
  20. def _real_extract(self, url):
  21. video_id = self._match_id(url)
  22. webpage = self._download_webpage(url, video_id)
  23. title = self._html_search_regex(
  24. r'<title>.+?Film &amp; Video: ([^<]+)</title>', webpage, 'title')
  25. duration = int_or_none(self._html_search_regex(
  26. r'Duration: (\d+) minutes', webpage, 'duration', fatal=False),
  27. invscale=60)
  28. formats = []
  29. FORMAT_REGEXES = [
  30. ('sq', r"'flashvars'\s*,\s*'file=([^']+)'"),
  31. ('hq', r'href="(http://ubumexico\.centro\.org\.mx/video/[^"]+)"'),
  32. ]
  33. preference = qualities([fid for fid, _ in FORMAT_REGEXES])
  34. for format_id, format_regex in FORMAT_REGEXES:
  35. m = re.search(format_regex, webpage)
  36. if m:
  37. formats.append({
  38. 'url': m.group(1),
  39. 'format_id': format_id,
  40. 'preference': preference(format_id),
  41. })
  42. self._sort_formats(formats)
  43. return {
  44. 'id': video_id,
  45. 'title': title,
  46. 'duration': duration,
  47. 'formats': formats,
  48. }