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.

101 lines
3.6 KiB

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