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.

108 lines
3.5 KiB

  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import json
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. ExtractorError,
  7. NO_DEFAULT,
  8. )
  9. class EllenTVIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?(?:ellentv|ellentube)\.com/videos/(?P<id>[a-z0-9_-]+)'
  11. _TESTS = [{
  12. 'url': 'http://www.ellentv.com/videos/0-ipq1gsai/',
  13. 'md5': '4294cf98bc165f218aaa0b89e0fd8042',
  14. 'info_dict': {
  15. 'id': '0_ipq1gsai',
  16. 'ext': 'mov',
  17. 'title': 'Fast Fingers of Fate',
  18. 'description': 'md5:3539013ddcbfa64b2a6d1b38d910868a',
  19. 'timestamp': 1428035648,
  20. 'upload_date': '20150403',
  21. 'uploader_id': 'batchUser',
  22. },
  23. }, {
  24. # not available via http://widgets.ellentube.com/
  25. 'url': 'http://www.ellentv.com/videos/1-szkgu2m2/',
  26. 'info_dict': {
  27. 'id': '1_szkgu2m2',
  28. 'ext': 'flv',
  29. 'title': "Ellen's Amazingly Talented Audience",
  30. 'description': 'md5:86ff1e376ff0d717d7171590e273f0a5',
  31. 'timestamp': 1255140900,
  32. 'upload_date': '20091010',
  33. 'uploader_id': 'ellenkaltura@gmail.com',
  34. },
  35. 'params': {
  36. 'skip_download': True,
  37. },
  38. }]
  39. def _real_extract(self, url):
  40. video_id = self._match_id(url)
  41. URLS = ('http://widgets.ellentube.com/videos/%s' % video_id, url)
  42. for num, url_ in enumerate(URLS, 1):
  43. webpage = self._download_webpage(
  44. url_, video_id, fatal=num == len(URLS))
  45. default = NO_DEFAULT if num == len(URLS) else None
  46. partner_id = self._search_regex(
  47. r"var\s+partnerId\s*=\s*'([^']+)", webpage, 'partner id',
  48. default=default)
  49. kaltura_id = self._search_regex(
  50. [r'id="kaltura_player_([^"]+)"',
  51. r"_wb_entry_id\s*:\s*'([^']+)",
  52. r'data-kaltura-entry-id="([^"]+)'],
  53. webpage, 'kaltura id', default=default)
  54. if partner_id and kaltura_id:
  55. break
  56. return self.url_result('kaltura:%s:%s' % (partner_id, kaltura_id), 'Kaltura')
  57. class EllenTVClipsIE(InfoExtractor):
  58. IE_NAME = 'EllenTV:clips'
  59. _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
  60. _TEST = {
  61. 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
  62. 'info_dict': {
  63. 'id': 'meryl-streep-vanessa-hudgens',
  64. 'title': 'Meryl Streep, Vanessa Hudgens',
  65. },
  66. 'playlist_mincount': 7,
  67. }
  68. def _real_extract(self, url):
  69. playlist_id = self._match_id(url)
  70. webpage = self._download_webpage(url, playlist_id)
  71. playlist = self._extract_playlist(webpage)
  72. return {
  73. '_type': 'playlist',
  74. 'id': playlist_id,
  75. 'title': self._og_search_title(webpage),
  76. 'entries': self._extract_entries(playlist)
  77. }
  78. def _extract_playlist(self, webpage):
  79. json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
  80. try:
  81. return json.loads('[{' + json_string + '}]')
  82. except ValueError as ve:
  83. raise ExtractorError('Failed to download JSON', cause=ve)
  84. def _extract_entries(self, playlist):
  85. return [
  86. self.url_result(
  87. 'kaltura:%s:%s' % (item['kaltura_partner_id'], item['kaltura_entry_id']),
  88. 'Kaltura')
  89. for item in playlist]