onionstudios.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(
  27. 'http://www.onionstudios.com/embed?id=%s' % video_id, video_id)
  28. formats = []
  29. for src in re.findall(r'<source[^>]+src="([^"]+)"', webpage):
  30. if determine_ext(src) != 'm3u8': # m3u8 always results in 403
  31. formats.append({
  32. 'url': src,
  33. })
  34. self._sort_formats(formats)
  35. title = self._search_regex(
  36. r'share_title\s*=\s*"([^"]+)"', webpage, 'title')
  37. description = self._search_regex(
  38. r'share_description\s*=\s*"([^"]+)"', webpage,
  39. 'description', default=None)
  40. thumbnail = self._search_regex(
  41. r'poster="([^"]+)"', webpage, 'thumbnail', default=False)
  42. uploader_id = self._search_regex(
  43. r'twitter_handle\s*=\s*"([^"]+)"',
  44. webpage, 'uploader id', fatal=False)
  45. uploader = self._search_regex(
  46. r'window\.channelName\s*=\s*"Embedded:([^"]+)"',
  47. webpage, 'uploader', default=False)
  48. return {
  49. 'id': video_id,
  50. 'title': title,
  51. 'description': description,
  52. 'thumbnail': thumbnail,
  53. 'uploader': uploader,
  54. 'uploader_id': uploader_id,
  55. 'formats': formats,
  56. }