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.

63 lines
2.1 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class TheOnionIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?theonion\.com/video/[^,]+,(?P<id>[0-9]+)/?'
  7. _TEST = {
  8. 'url': 'http://www.theonion.com/video/man-wearing-mm-jacket-gods-image,36918/',
  9. 'md5': '19eaa9a39cf9b9804d982e654dc791ee',
  10. 'info_dict': {
  11. 'id': '2133',
  12. 'ext': 'mp4',
  13. 'title': 'Man Wearing M&M Jacket Apparently Made In God\'s Image',
  14. 'description': 'md5:cc12448686b5600baae9261d3e180910',
  15. 'thumbnail': 're:^https?://.*\.jpg\?\d+$',
  16. }
  17. }
  18. def _real_extract(self, url):
  19. display_id = self._match_id(url)
  20. webpage = self._download_webpage(url, display_id)
  21. video_id = self._search_regex(
  22. r'"videoId":\s(\d+),', webpage, 'video ID')
  23. title = self._og_search_title(webpage)
  24. description = self._og_search_description(webpage)
  25. thumbnail = self._og_search_thumbnail(webpage)
  26. sources = re.findall(r'<source src="([^"]+)" type="([^"]+)"', webpage)
  27. formats = []
  28. for src, type_ in sources:
  29. if type_ == 'video/mp4':
  30. formats.append({
  31. 'format_id': 'mp4_sd',
  32. 'preference': 1,
  33. 'url': src,
  34. })
  35. elif type_ == 'video/webm':
  36. formats.append({
  37. 'format_id': 'webm_sd',
  38. 'preference': 0,
  39. 'url': src,
  40. })
  41. elif type_ == 'application/x-mpegURL':
  42. formats.extend(
  43. self._extract_m3u8_formats(src, display_id, preference=-1))
  44. else:
  45. self.report_warning(
  46. 'Encountered unexpected format: %s' % type_)
  47. self._sort_formats(formats)
  48. return {
  49. 'id': video_id,
  50. 'display_id': display_id,
  51. 'title': title,
  52. 'formats': formats,
  53. 'thumbnail': thumbnail,
  54. 'description': description,
  55. }