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.

88 lines
3.2 KiB

  1. from __future__ import unicode_literals
  2. import json
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urlparse,
  7. get_meta_content,
  8. )
  9. class UstreamIE(InfoExtractor):
  10. _VALID_URL = r'https?://www\.ustream\.tv/(?P<type>recorded|embed|embed/recorded)/(?P<videoID>\d+)'
  11. IE_NAME = 'ustream'
  12. _TEST = {
  13. 'url': 'http://www.ustream.tv/recorded/20274954',
  14. 'md5': '088f151799e8f572f84eb62f17d73e5c',
  15. 'info_dict': {
  16. 'id': '20274954',
  17. 'ext': 'flv',
  18. 'uploader': 'Young Americans for Liberty',
  19. 'title': 'Young Americans for Liberty February 7, 2012 2:28 AM',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. m = re.match(self._VALID_URL, url)
  24. video_id = m.group('videoID')
  25. # some sites use this embed format (see: http://github.com/rg3/youtube-dl/issues/2990)
  26. if m.group('type') == 'embed/recorded':
  27. video_id = m.group('videoID')
  28. desktop_url = 'http://www.ustream.tv/recorded/' + video_id
  29. return self.url_result(desktop_url, 'Ustream')
  30. if m.group('type') == 'embed':
  31. video_id = m.group('videoID')
  32. webpage = self._download_webpage(url, video_id)
  33. desktop_video_id = self._html_search_regex(
  34. r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id')
  35. desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id
  36. return self.url_result(desktop_url, 'Ustream')
  37. video_url = 'http://tcdn.ustream.tv/video/%s' % video_id
  38. webpage = self._download_webpage(url, video_id)
  39. self.report_extraction(video_id)
  40. video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
  41. webpage, 'title')
  42. uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
  43. webpage, 'uploader', fatal=False, flags=re.DOTALL)
  44. thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
  45. webpage, 'thumbnail', fatal=False)
  46. return {
  47. 'id': video_id,
  48. 'url': video_url,
  49. 'ext': 'flv',
  50. 'title': video_title,
  51. 'uploader': uploader,
  52. 'thumbnail': thumbnail,
  53. }
  54. class UstreamChannelIE(InfoExtractor):
  55. _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
  56. IE_NAME = 'ustream:channel'
  57. def _real_extract(self, url):
  58. m = re.match(self._VALID_URL, url)
  59. slug = m.group('slug')
  60. webpage = self._download_webpage(url, slug)
  61. channel_id = get_meta_content('ustream:channel_id', webpage)
  62. BASE = 'http://www.ustream.tv'
  63. next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id
  64. video_ids = []
  65. while next_url:
  66. reply = json.loads(self._download_webpage(compat_urlparse.urljoin(BASE, next_url), channel_id))
  67. video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data']))
  68. next_url = reply['nextUrl']
  69. urls = ['http://www.ustream.tv/recorded/' + vid for vid in video_ids]
  70. url_entries = [self.url_result(eurl, 'Ustream') for eurl in urls]
  71. return self.playlist_result(url_entries, channel_id)