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.

56 lines
2.2 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. get_meta_content,
  8. ExtractorError,
  9. )
  10. class LivestreamIE(InfoExtractor):
  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)