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.

92 lines
3.5 KiB

10 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import ExtractorError
  6. class NewstubeIE(InfoExtractor):
  7. _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
  8. _TEST = {
  9. 'url': 'http://www.newstube.ru/media/telekanal-cnn-peremestil-gorod-slavyansk-v-krym',
  10. 'info_dict': {
  11. 'id': '728e0ef2-e187-4012-bac0-5a081fdcb1f6',
  12. 'ext': 'flv',
  13. 'title': 'Телеканал CNN переместил город Славянск в Крым',
  14. 'description': 'md5:419a8c9f03442bc0b0a794d689360335',
  15. 'duration': 31.05,
  16. },
  17. 'params': {
  18. # rtmp download
  19. 'skip_download': True,
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. page = self._download_webpage(url, video_id, 'Downloading page')
  26. video_guid = self._html_search_regex(
  27. 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})',
  28. page, 'video GUID')
  29. player = self._download_xml(
  30. 'http://p.newstube.ru/v2/player.asmx/GetAutoPlayInfo6?state=&url=%s&sessionId=&id=%s&placement=profile&location=n2' % (url, video_guid),
  31. video_guid, 'Downloading player XML')
  32. def ns(s):
  33. return s.replace('/', '/%(ns)s') % {'ns': '{http://app1.newstube.ru/N2SiteWS/player.asmx}'}
  34. error_message = player.find(ns('./ErrorMessage'))
  35. if error_message is not None:
  36. raise ExtractorError('%s returned error: %s' % (self.IE_NAME, error_message.text), expected=True)
  37. session_id = player.find(ns('./SessionId')).text
  38. media_info = player.find(ns('./Medias/MediaInfo'))
  39. title = media_info.find(ns('./Name')).text
  40. description = self._og_search_description(page)
  41. thumbnail = media_info.find(ns('./KeyFrame')).text
  42. duration = int(media_info.find(ns('./Duration')).text) / 1000.0
  43. formats = []
  44. for stream_info in media_info.findall(ns('./Streams/StreamInfo')):
  45. media_location = stream_info.find(ns('./MediaLocation'))
  46. if media_location is None:
  47. continue
  48. server = media_location.find(ns('./Server')).text
  49. app = media_location.find(ns('./App')).text
  50. media_id = stream_info.find(ns('./Id')).text
  51. quality_id = stream_info.find(ns('./QualityId')).text
  52. name = stream_info.find(ns('./Name')).text
  53. width = int(stream_info.find(ns('./Width')).text)
  54. height = int(stream_info.find(ns('./Height')).text)
  55. formats.append({
  56. 'url': 'rtmp://%s/%s' % (server, app),
  57. 'app': app,
  58. 'play_path': '01/%s' % video_guid.upper(),
  59. 'rtmp_conn': ['S:%s' % session_id, 'S:%s' % media_id, 'S:n2'],
  60. 'page_url': url,
  61. 'ext': 'flv',
  62. 'format_id': quality_id,
  63. 'format_note': name,
  64. 'width': width,
  65. 'height': height,
  66. })
  67. self._sort_formats(formats)
  68. return {
  69. 'id': video_guid,
  70. 'title': title,
  71. 'description': description,
  72. 'thumbnail': thumbnail,
  73. 'duration': duration,
  74. 'formats': formats,
  75. }