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.

81 lines
2.9 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)/(?P<videoID>\d+)'
  11. IE_NAME = 'ustream'
  12. _TEST = {
  13. 'url': 'http://www.ustream.tv/recorded/20274954',
  14. 'file': '20274954.flv',
  15. 'md5': '088f151799e8f572f84eb62f17d73e5c',
  16. 'info_dict': {
  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. if m.group('type') == 'embed':
  24. video_id = m.group('videoID')
  25. webpage = self._download_webpage(url, video_id)
  26. desktop_video_id = self._html_search_regex(r'ContentVideoIds=\["([^"]*?)"\]', webpage, 'desktop_video_id')
  27. desktop_url = 'http://www.ustream.tv/recorded/' + desktop_video_id
  28. return self.url_result(desktop_url, 'Ustream')
  29. video_id = m.group('videoID')
  30. video_url = 'http://tcdn.ustream.tv/video/%s' % video_id
  31. webpage = self._download_webpage(url, video_id)
  32. self.report_extraction(video_id)
  33. video_title = self._html_search_regex(r'data-title="(?P<title>.+)"',
  34. webpage, 'title')
  35. uploader = self._html_search_regex(r'data-content-type="channel".*?>(?P<uploader>.*?)</a>',
  36. webpage, 'uploader', fatal=False, flags=re.DOTALL)
  37. thumbnail = self._html_search_regex(r'<link rel="image_src" href="(?P<thumb>.*?)"',
  38. webpage, 'thumbnail', fatal=False)
  39. return {
  40. 'id': video_id,
  41. 'url': video_url,
  42. 'ext': 'flv',
  43. 'title': video_title,
  44. 'uploader': uploader,
  45. 'thumbnail': thumbnail,
  46. }
  47. class UstreamChannelIE(InfoExtractor):
  48. _VALID_URL = r'https?://www\.ustream\.tv/channel/(?P<slug>.+)'
  49. IE_NAME = 'ustream:channel'
  50. def _real_extract(self, url):
  51. m = re.match(self._VALID_URL, url)
  52. slug = m.group('slug')
  53. webpage = self._download_webpage(url, slug)
  54. channel_id = get_meta_content('ustream:channel_id', webpage)
  55. BASE = 'http://www.ustream.tv'
  56. next_url = '/ajax/socialstream/videos/%s/1.json' % channel_id
  57. video_ids = []
  58. while next_url:
  59. reply = json.loads(self._download_webpage(compat_urlparse.urljoin(BASE, next_url), channel_id))
  60. video_ids.extend(re.findall(r'data-content-id="(\d.*)"', reply['data']))
  61. next_url = reply['nextUrl']
  62. urls = ['http://www.ustream.tv/recorded/' + vid for vid in video_ids]
  63. url_entries = [self.url_result(eurl, 'Ustream') for eurl in urls]
  64. return self.playlist_result(url_entries, channel_id)