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.

81 lines
2.7 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/(?:video(?:s/[^/]+-|/)|embed\?.*\bid=)(?P<id>\d+)(?!-)'
  13. _TESTS = [{
  14. 'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
  15. 'md5': '719d1f8c32094b8c33902c17bcae5e34',
  16. 'info_dict': {
  17. 'id': '2937',
  18. 'ext': 'mp4',
  19. 'title': 'Hannibal charges forward, stops for a cocktail',
  20. 'thumbnail': r'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. 'url': 'http://www.onionstudios.com/video/6139.json',
  29. 'only_matching': True,
  30. }]
  31. @staticmethod
  32. def _extract_url(webpage):
  33. mobj = re.search(
  34. r'(?s)<(?:iframe|bulbs-video)[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/(?:embed.+?|video/\d+\.json))\1', webpage)
  35. if mobj:
  36. return mobj.group('url')
  37. def _real_extract(self, url):
  38. video_id = self._match_id(url)
  39. video_data = self._download_json(
  40. 'http://www.onionstudios.com/video/%s.json' % video_id, video_id)
  41. title = video_data['title']
  42. formats = []
  43. for source in video_data.get('sources', []):
  44. source_url = source.get('url')
  45. if not source_url:
  46. continue
  47. ext = mimetype2ext(source.get('content_type')) or determine_ext(source_url)
  48. if ext == 'm3u8':
  49. formats.extend(self._extract_m3u8_formats(
  50. source_url, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  51. else:
  52. tbr = int_or_none(source.get('bitrate'))
  53. formats.append({
  54. 'format_id': ext + ('-%d' % tbr if tbr else ''),
  55. 'url': source_url,
  56. 'width': int_or_none(source.get('width')),
  57. 'tbr': tbr,
  58. 'ext': ext,
  59. })
  60. self._sort_formats(formats)
  61. return {
  62. 'id': video_id,
  63. 'title': title,
  64. 'thumbnail': video_data.get('poster_url'),
  65. 'uploader': video_data.get('channel_name'),
  66. 'uploader_id': video_data.get('channel_slug'),
  67. 'duration': float_or_none(video_data.get('duration', 1000)),
  68. 'tags': video_data.get('tags'),
  69. 'formats': formats,
  70. }