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.

100 lines
4.0 KiB

  1. import re
  2. import json
  3. import xml.etree.ElementTree
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_parse_urlparse,
  7. compat_urlparse,
  8. get_meta_content,
  9. xpath_with_ns,
  10. ExtractorError,
  11. )
  12. class LivestreamIE(InfoExtractor):
  13. IE_NAME = u'livestream'
  14. _VALID_URL = r'http://new.livestream.com/.*?/(?P<event_name>.*?)(/videos/(?P<id>\d+))?/?$'
  15. _TEST = {
  16. u'url': u'http://new.livestream.com/CoheedandCambria/WebsterHall/videos/4719370',
  17. u'file': u'4719370.mp4',
  18. u'md5': u'0d2186e3187d185a04b3cdd02b828836',
  19. u'info_dict': {
  20. u'title': u'Live from Webster Hall NYC',
  21. u'upload_date': u'20121012',
  22. }
  23. }
  24. def _extract_video_info(self, video_data):
  25. video_url = video_data.get('progressive_url_hd') or video_data.get('progressive_url')
  26. return {'id': video_data['id'],
  27. 'url': video_url,
  28. 'ext': 'mp4',
  29. 'title': video_data['caption'],
  30. 'thumbnail': video_data['thumbnail_url'],
  31. 'upload_date': video_data['updated_at'].replace('-','')[:8],
  32. }
  33. def _real_extract(self, url):
  34. mobj = re.match(self._VALID_URL, url)
  35. video_id = mobj.group('id')
  36. event_name = mobj.group('event_name')
  37. webpage = self._download_webpage(url, video_id or event_name)
  38. if video_id is None:
  39. # This is an event page:
  40. config_json = self._search_regex(r'window.config = ({.*?});',
  41. webpage, u'window config')
  42. info = json.loads(config_json)['event']
  43. videos = [self._extract_video_info(video_data['data'])
  44. for video_data in info['feed']['data'] if video_data['type'] == u'video']
  45. return self.playlist_result(videos, info['id'], info['full_name'])
  46. else:
  47. og_video = self._og_search_video_url(webpage, name=u'player url')
  48. query_str = compat_urllib_parse_urlparse(og_video).query
  49. query = compat_urlparse.parse_qs(query_str)
  50. api_url = query['play_url'][0].replace('.smil', '')
  51. info = json.loads(self._download_webpage(api_url, video_id,
  52. u'Downloading video info'))
  53. return self._extract_video_info(info)
  54. # The original version of Livestream uses a different system
  55. class LivestreamOriginalIE(InfoExtractor):
  56. IE_NAME = u'livestream:original'
  57. _VALID_URL = r'https?://www\.livestream\.com/(?P<user>[^/]+)/video\?.*?clipId=(?P<id>.*?)(&|$)'
  58. _TEST = {
  59. u'url': u'http://www.livestream.com/dealbook/video?clipId=pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
  60. u'info_dict': {
  61. u'id': u'pla_8aa4a3f1-ba15-46a4-893b-902210e138fb',
  62. u'ext': u'flv',
  63. u'title': u'Spark 1 (BitCoin) with Cameron Winklevoss & Tyler Winklevoss of Winklevoss Capital',
  64. },
  65. u'params': {
  66. # rtmp
  67. u'skip_download': True,
  68. },
  69. }
  70. def _real_extract(self, url):
  71. mobj = re.match(self._VALID_URL, url)
  72. video_id = mobj.group('id')
  73. user = mobj.group('user')
  74. api_url = 'http://x{0}x.api.channel.livestream.com/2.0/clipdetails?extendedInfo=true&id={1}'.format(user, video_id)
  75. api_response = self._download_webpage(api_url, video_id)
  76. info = xml.etree.ElementTree.fromstring(api_response.encode('utf-8'))
  77. item = info.find('channel').find('item')
  78. ns = {'media': 'http://search.yahoo.com/mrss'}
  79. thumbnail_url = item.find(xpath_with_ns('media:thumbnail', ns)).attrib['url']
  80. # Remove the extension and number from the path (like 1.jpg)
  81. path = self._search_regex(r'(user-files/.+)_.*?\.jpg$', thumbnail_url, u'path')
  82. return {
  83. 'id': video_id,
  84. 'title': item.find('title').text,
  85. 'url': 'rtmp://extondemand.livestream.com/ondemand',
  86. 'play_path': 'mp4:trans/dv15/mogulus-{0}.mp4'.format(path),
  87. 'ext': 'flv',
  88. 'thumbnail': thumbnail_url,
  89. }