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.

96 lines
3.9 KiB

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