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.

89 lines
3.2 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. )
  9. class OnionStudiosIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?onionstudios\.com/(?:videos/[^/]+-|embed\?.*\bid=)(?P<id>\d+)(?!-)'
  11. _TESTS = [{
  12. 'url': 'http://www.onionstudios.com/videos/hannibal-charges-forward-stops-for-a-cocktail-2937',
  13. 'md5': 'd4851405d31adfadf71cd7a487b765bb',
  14. 'info_dict': {
  15. 'id': '2937',
  16. 'ext': 'mp4',
  17. 'title': 'Hannibal charges forward, stops for a cocktail',
  18. 'description': 'md5:e786add7f280b7f0fe237b64cc73df76',
  19. 'thumbnail': 're:^https?://.*\.jpg$',
  20. 'uploader': 'The A.V. Club',
  21. 'uploader_id': 'TheAVClub',
  22. },
  23. }, {
  24. 'url': 'http://www.onionstudios.com/embed?id=2855&autoplay=true',
  25. 'only_matching': True,
  26. }]
  27. @staticmethod
  28. def _extract_url(webpage):
  29. mobj = re.search(
  30. r'<iframe[^>]+?src=(["\'])(?P<url>(?:https?:)?//(?:www\.)?onionstudios\.com/embed.+?)\1', webpage)
  31. if mobj:
  32. return mobj.group('url')
  33. def _real_extract(self, url):
  34. video_id = self._match_id(url)
  35. webpage = self._download_webpage(
  36. 'http://www.onionstudios.com/embed?id=%s' % video_id, video_id)
  37. formats = []
  38. for src in re.findall(r'<source[^>]+src="([^"]+)"', webpage):
  39. ext = determine_ext(src)
  40. if ext == 'm3u8':
  41. formats.extend(self._extract_m3u8_formats(
  42. src, video_id, 'mp4', 'm3u8_native', m3u8_id='hls', fatal=False))
  43. else:
  44. height = int_or_none(self._search_regex(
  45. r'/(\d+)\.%s' % ext, src, 'height', default=None))
  46. formats.append({
  47. 'format_id': ext + ('-%sp' % height if height else ''),
  48. 'url': src,
  49. 'height': height,
  50. 'ext': ext,
  51. 'preference': 1,
  52. })
  53. self._sort_formats(formats)
  54. title = self._search_regex(
  55. r'share_title\s*=\s*(["\'])(?P<title>[^\1]+?)\1',
  56. webpage, 'title', group='title')
  57. description = self._search_regex(
  58. r'share_description\s*=\s*(["\'])(?P<description>[^\'"]+?)\1',
  59. webpage, 'description', default=None, group='description')
  60. thumbnail = self._search_regex(
  61. r'poster\s*=\s*(["\'])(?P<thumbnail>[^\1]+?)\1',
  62. webpage, 'thumbnail', default=False, group='thumbnail')
  63. uploader_id = self._search_regex(
  64. r'twitter_handle\s*=\s*(["\'])(?P<uploader_id>[^\1]+?)\1',
  65. webpage, 'uploader id', fatal=False, group='uploader_id')
  66. uploader = self._search_regex(
  67. r'window\.channelName\s*=\s*(["\'])Embedded:(?P<uploader>[^\1]+?)\1',
  68. webpage, 'uploader', default=False, group='uploader')
  69. return {
  70. 'id': video_id,
  71. 'title': title,
  72. 'description': description,
  73. 'thumbnail': thumbnail,
  74. 'uploader': uploader,
  75. 'uploader_id': uploader_id,
  76. 'formats': formats,
  77. }