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.

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