ellentv.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. import json
  5. from .common import InfoExtractor, ExtractorError
  6. class EllenTVIE(InfoExtractor):
  7. IE_NAME = u'ellentv'
  8. _VALID_URL = r'https?://(?:www\.)?ellentv\.com/videos/(?P<id>[a-z0-9_-]+)'
  9. _TEST = {
  10. 'url': 'http://www.ellentv.com/videos/0-7jqrsr18/',
  11. 'md5': 'e4af06f3bf0d5f471921a18db5764642',
  12. 'info_dict': {
  13. 'id': '0-7jqrsr18',
  14. 'ext': 'mp4',
  15. 'title': u'What\'s Wrong with These Photos? A Whole Lot',
  16. # TODO more properties, either as:
  17. # * A value
  18. # * MD5 checksum; start the string with md5:
  19. # * A regular expression; start the string with re:
  20. # * Any Python type (for example int or float)
  21. }
  22. }
  23. def _real_extract(self, url):
  24. mobj = re.match(self._VALID_URL, url)
  25. id = mobj.group('id')
  26. webpage = self._download_webpage(url, id)
  27. return {
  28. 'id': id,
  29. 'title': self._og_search_title(webpage),
  30. 'url': self._html_search_meta('VideoURL', webpage, 'url')
  31. }
  32. class EllenTVClipsIE(InfoExtractor):
  33. IE_NAME = u'ellentv:clips'
  34. _VALID_URL = r'https?://(?:www\.)?ellentv\.com/episodes/(?P<id>[a-z0-9_-]+)'
  35. _TEST = {
  36. 'url': 'http://www.ellentv.com/episodes/meryl-streep-vanessa-hudgens/',
  37. 'md5': 'TODO: md5 sum of the first 10KiB of the video file',
  38. 'info_dict': {
  39. 'id': '0_wf6pizq7',
  40. 'ext': 'mp4',
  41. 'title': 'Video title goes here',
  42. # TODO more properties, either as:
  43. # * A value
  44. # * MD5 checksum; start the string with md5:
  45. # * A regular expression; start the string with re:
  46. # * Any Python type (for example int or float)
  47. }
  48. }
  49. def _real_extract(self, url):
  50. mobj = re.match(self._VALID_URL, url)
  51. playlist_id = mobj.group('id')
  52. webpage = self._download_webpage(url, playlist_id)
  53. playlist = self._extract_playlist(webpage)
  54. return {
  55. '_type': 'playlist',
  56. 'id': playlist_id,
  57. 'title': self._og_search_title(webpage),
  58. 'entries': self._extract_entries(playlist)
  59. }
  60. def _extract_playlist(self, webpage):
  61. json_string = self._search_regex(r'playerView.addClips\(\[\{(.*?)\}\]\);', webpage, 'json')
  62. try:
  63. return json.loads("[{" + json_string + "}]")
  64. except ValueError as ve:
  65. raise ExtractorError('Failed to download JSON', cause=ve)
  66. def _extract_entries(self, playlist):
  67. return [self.url_result(item[u'url'], 'EllenTV') for item in playlist]