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.

60 lines
2.5 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. player = get_meta_content('twitter:player', webpage)
  38. if player is None:
  39. raise ExtractorError('Couldn\'t extract event api url')
  40. api_url = player.replace('/player', '')
  41. api_url = re.sub(r'^(https?://)(new\.)', r'\1api.\2', api_url)
  42. info = json.loads(self._download_webpage(api_url, event_name,
  43. u'Downloading event info'))
  44. videos = [self._extract_video_info(video_data['data'])
  45. for video_data in info['feed']['data'] if video_data['type'] == u'video']
  46. return self.playlist_result(videos, info['id'], info['full_name'])
  47. else:
  48. og_video = self._og_search_video_url(webpage, name=u'player url')
  49. query_str = compat_urllib_parse_urlparse(og_video).query
  50. query = compat_urlparse.parse_qs(query_str)
  51. api_url = query['play_url'][0].replace('.smil', '')
  52. info = json.loads(self._download_webpage(api_url, video_id,
  53. u'Downloading video info'))
  54. return self._extract_video_info(info)