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.

74 lines
2.5 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*"([^"]+)"', webpage, 'title')
  43. description = self._search_regex(
  44. r'share_description\s*=\s*"([^"]+)"', webpage,
  45. 'description', default=None)
  46. thumbnail = self._search_regex(
  47. r'poster="([^"]+)"', webpage, 'thumbnail', default=False)
  48. uploader_id = self._search_regex(
  49. r'twitter_handle\s*=\s*"([^"]+)"',
  50. webpage, 'uploader id', fatal=False)
  51. uploader = self._search_regex(
  52. r'window\.channelName\s*=\s*"Embedded:([^"]+)"',
  53. webpage, 'uploader', default=False)
  54. return {
  55. 'id': video_id,
  56. 'title': title,
  57. 'description': description,
  58. 'thumbnail': thumbnail,
  59. 'uploader': uploader,
  60. 'uploader_id': uploader_id,
  61. 'formats': formats,
  62. }