ellentv.py 2.9 KB

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