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.

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