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.

86 lines
3.3 KiB

  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. class NewstubeIE(InfoExtractor):
  6. _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
  7. _TEST = {
  8. 'url': 'http://newstube.ru/media/na-korable-progress-prodolzhaetsya-testirovanie-sistemy-kurs',
  9. 'info_dict': {
  10. 'id': 'd156a237-a6e9-4111-a682-039995f721f1',
  11. 'ext': 'flv',
  12. 'title': 'На корабле «Прогресс» продолжается тестирование системы «Курс»',
  13. 'description': 'md5:d0cbe7b4a6f600552617e48548d5dc77',
  14. 'duration': 20.04,
  15. },
  16. 'params': {
  17. # rtmp download
  18. 'skip_download': True,
  19. },
  20. }
  21. def _real_extract(self, url):
  22. mobj = re.match(self._VALID_URL, url)
  23. video_id = mobj.group('id')
  24. page = self._download_webpage(url, video_id, 'Downloading page')
  25. video_guid = self._html_search_regex(
  26. r'<meta property="og:video" content="https?://(?:www\.)?newstube\.ru/freshplayer\.swf\?guid=(?P<guid>[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12})',
  27. page, 'video GUID')
  28. player = self._download_xml(
  29. 'http://p.newstube.ru/v2/player.asmx/GetAutoPlayInfo6?state=&url=%s&sessionId=&id=%s&placement=profile&location=n2' % (url, video_guid),
  30. video_guid, 'Downloading player XML')
  31. def ns(s):
  32. return s.replace('/', '/%(ns)s') % {'ns': '{http://app1.newstube.ru/N2SiteWS/player.asmx}'}
  33. session_id = player.find(ns('./SessionId')).text
  34. media_info = player.find(ns('./Medias/MediaInfo'))
  35. title = media_info.find(ns('./Name')).text
  36. description = self._og_search_description(page)
  37. thumbnail = media_info.find(ns('./KeyFrame')).text
  38. duration = int(media_info.find(ns('./Duration')).text) / 1000.0
  39. formats = []
  40. for stream_info in media_info.findall(ns('./Streams/StreamInfo')):
  41. media_location = stream_info.find(ns('./MediaLocation'))
  42. if media_location is None:
  43. continue
  44. server = media_location.find(ns('./Server')).text
  45. app = media_location.find(ns('./App')).text
  46. media_id = stream_info.find(ns('./Id')).text
  47. quality_id = stream_info.find(ns('./QualityId')).text
  48. name = stream_info.find(ns('./Name')).text
  49. width = int(stream_info.find(ns('./Width')).text)
  50. height = int(stream_info.find(ns('./Height')).text)
  51. formats.append({
  52. 'url': 'rtmp://%s/%s' % (server, app),
  53. 'app': app,
  54. 'play_path': '01/%s' % video_guid.upper(),
  55. 'rtmp_conn': ['S:%s' % session_id, 'S:%s' % media_id, 'S:n2'],
  56. 'page_url': url,
  57. 'ext': 'flv',
  58. 'format_id': quality_id,
  59. 'format_note': name,
  60. 'width': width,
  61. 'height': height,
  62. })
  63. self._sort_formats(formats)
  64. return {
  65. 'id': video_guid,
  66. 'title': title,
  67. 'description': description,
  68. 'thumbnail': thumbnail,
  69. 'duration': duration,
  70. 'formats': formats,
  71. }