ellentv.py 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. _TESTS = [{
  12. 'url': 'http://www.ellentv.com/videos/0-7jqrsr18/',
  13. 'md5': 'e4af06f3bf0d5f471921a18db5764642',
  14. 'info_dict': {
  15. 'id': '0-7jqrsr18',
  16. 'ext': 'mp4',
  17. 'title': 'What\'s Wrong with These Photos? A Whole Lot',
  18. 'timestamp': 1406876400,
  19. 'upload_date': '20140801',
  20. }
  21. }, {
  22. 'url': 'http://ellentube.com/videos/0-dvzmabd5/',
  23. 'md5': '98238118eaa2bbdf6ad7f708e3e4f4eb',
  24. 'info_dict': {
  25. 'id': '0-dvzmabd5',
  26. 'ext': 'mp4',
  27. 'title': '1 year old twin sister makes her brother laugh',
  28. 'timestamp': 1419542075,
  29. 'upload_date': '20141225',
  30. }
  31. }]
  32. def _real_extract(self, url):
  33. video_id = self._match_id(url)
  34. webpage = self._download_webpage(url, video_id)
  35. timestamp = parse_iso8601(self._search_regex(
  36. r'<span class="publish-date"><time datetime="([^"]+)">',
  37. webpage, 'timestamp'))
  38. return {
  39. 'id': video_id,
  40. 'title': self._og_search_title(webpage),
  41. 'url': self._html_search_meta('VideoURL', webpage, 'url'),
  42. 'timestamp': timestamp,
  43. }
  44. class EllenTVClipsIE(InfoExtractor):
  45. IE_NAME = 'EllenTV:clips'
  46. _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
  47. _TEST = {
  48. 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
  49. 'info_dict': {
  50. 'id': 'meryl-streep-vanessa-hudgens',
  51. 'title': 'Meryl Streep, Vanessa Hudgens',
  52. },
  53. 'playlist_mincount': 9,
  54. }
  55. def _real_extract(self, url):
  56. playlist_id = self._match_id(url)
  57. webpage = self._download_webpage(url, playlist_id)
  58. playlist = self._extract_playlist(webpage)
  59. return {
  60. '_type': 'playlist',
  61. 'id': playlist_id,
  62. 'title': self._og_search_title(webpage),
  63. 'entries': self._extract_entries(playlist)
  64. }
  65. def _extract_playlist(self, webpage):
  66. json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
  67. try:
  68. return json.loads("[{" + json_string + "}]")
  69. except ValueError as ve:
  70. raise ExtractorError('Failed to download JSON', cause=ve)
  71. def _extract_entries(self, playlist):
  72. return [self.url_result(item['url'], 'EllenTV') for item in playlist]