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.

102 lines
3.6 KiB

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