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.

78 lines
2.6 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. determine_ext,
  7. int_or_none,
  8. float_or_none,
  9. mimetype2ext,
  10. )
  11. class OnionStudiosIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?onionstudios\.com/(?:videos/[^/]+-|embed\?.*\bid=)(?P<id>\d+)(?!-)'
  13. _TESTS = [{
  14. 'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
  15. 'md5': 'e49f947c105b8a78a675a0ee1bddedfe',
  16. 'info_dict': {
  17. 'id': '2937',
  18. 'ext': 'mp4',
  19. 'title': 'Hannibal charges forward, stops for a cocktail',
  20. 'thumbnail': 're:^https?://.*\.jpg$',
  21. 'uploader': 'The A.V. Club',
  22. 'uploader_id': 'the-av-club',
  23. },
  24. }, {
  25. 'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
  26. 'only_matching': True,
  27. }]
  28. @staticmethod
  29. def _extract_url(webpage):
  30. mobj = re.search(
  31. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/embed.+?)\1', webpage)
  32. if mobj:
  33. return mobj.group('url')
  34. def _real_extract(self, url):
  35. video_id = self._match_id(url)
  36. video_data = self._download_json(
  37. 'http://www.onionstudios.com/video/%s.json' % video_id, video_id)
  38. title = video_data['title']
  39. formats = []
  40. for source in video_data.get('sources', []):
  41. source_url = source.get('url')
  42. if not source_url:
  43. continue
  44. ext = mimetype2ext(source.get('content_type')) or determine_ext(source_url)
  45. if ext == 'm3u8':
  46. formats.extend(self._extract_m3u8_formats(
  47. source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  48. else:
  49. tbr = int_or_none(source.get('bitrate'))
  50. formats.append({
  51. 'format_id': ext + ('-%d' % tbr if tbr else ''),
  52. 'url': source_url,
  53. 'width': int_or_none(source.get('width')),
  54. 'tbr': tbr,
  55. 'ext': ext,
  56. })
  57. self._sort_formats(formats)
  58. return {
  59. 'id': video_id,
  60. 'title': title,
  61. 'thumbnail': video_data.get('poster_url'),
  62. 'uploader': video_data.get('channel_name'),
  63. 'uploader_id': video_data.get('channel_slug'),
  64. 'duration': float_or_none(video_data.get('duration', 1000)),
  65. 'tags': video_data.get('tags'),
  66. 'formats': formats,
  67. }