ellentv.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. parse_iso8601,
  8. )
  9. class EllenTVIE(InfoExtractor):
  10. _VALID_URL = r'https?://(?:www\.)?(?:ellentv|ellentube)\.com/videos/(?P<id>[a-z0-9_-]+)'
  11. _TEST = {
  12. 'url': 'http://www.ellentv.com/videos/0-ipq1gsai/',
  13. 'md5': '8e3c576bf2e9bfff4d76565f56f94c9c',
  14. 'info_dict': {
  15. 'id': '0_ipq1gsai',
  16. 'ext': 'mp4',
  17. 'title': 'Fast Fingers of Fate',
  18. 'description': 'md5:587e79fbbd0d73b148bc596d99ce48e6',
  19. 'timestamp': 1428035648,
  20. 'upload_date': '20150403',
  21. 'uploader_id': 'batchUser',
  22. }
  23. }
  24. def _real_extract(self, url):
  25. video_id = self._match_id(url)
  26. webpage = self._download_webpage(
  27. 'http://widgets.ellentube.com/videos/%s' % video_id,
  28. video_id)
  29. partner_id = self._search_regex(
  30. r"var\s+partnerId\s*=\s*'([^']+)", webpage, 'partner id')
  31. kaltura_id = self._search_regex(
  32. [r'id="kaltura_player_([^"]+)"',
  33. r"_wb_entry_id\s*:\s*'([^']+)",
  34. r'data-kaltura-entry-id="([^"]+)'],
  35. webpage, 'kaltura id')
  36. return self.url_result('kaltura:%s:%s' % (partner_id, kaltura_id), 'Kaltura')
  37. class EllenTVClipsIE(InfoExtractor):
  38. IE_NAME = 'EllenTV:clips'
  39. _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
  40. _TEST = {
  41. 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
  42. 'info_dict': {
  43. 'id': 'meryl-streep-vanessa-hudgens',
  44. 'title': 'Meryl Streep, Vanessa Hudgens',
  45. },
  46. 'playlist_mincount': 7,
  47. }
  48. def _real_extract(self, url):
  49. playlist_id = self._match_id(url)
  50. webpage = self._download_webpage(url, playlist_id)
  51. playlist = self._extract_playlist(webpage)
  52. return {
  53. '_type': 'playlist',
  54. 'id': playlist_id,
  55. 'title': self._og_search_title(webpage),
  56. 'entries': self._extract_entries(playlist)
  57. }
  58. def _extract_playlist(self, webpage):
  59. json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
  60. try:
  61. return json.loads("[{" + json_string + "}]")
  62. except ValueError as ve:
  63. raise ExtractorError('Failed to download JSON', cause=ve)
  64. def _extract_entries(self, playlist):
  65. return [
  66. self.url_result(
  67. 'kaltura:%s:%s' % (item['kaltura_partner_id'], item['kaltura_entry_id']),
  68. 'Kaltura')
  69. for item in playlist]