aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey M․ <dstftw@gmail.com>2014-05-01 21:15:25 +0700
committerSergey M․ <dstftw@gmail.com>2014-05-01 21:15:25 +0700
commitb8b01bb92ad5399e655c0756a74902aefe7bc6a7 (patch)
treeb628b61abac8c972db5373ef65e3985ad8a7d68e
parenteb451334514d77b3e0fd7a63ea99c7c266199ef8 (diff)
[newstube] Add support for newstube.ru (Closes #2814)
-rw-r--r--youtube_dl/extractor/__init__.py1
-rw-r--r--youtube_dl/extractor/newstube.py87
2 files changed, 88 insertions, 0 deletions
diff --git a/youtube_dl/extractor/__init__.py b/youtube_dl/extractor/__init__.py
index e27cd2d2d..09209a739 100644
--- a/youtube_dl/extractor/__init__.py
+++ b/youtube_dl/extractor/__init__.py
@@ -180,6 +180,7 @@ from .nbc import (
from .ndr import NDRIE
from .ndtv import NDTVIE
from .newgrounds import NewgroundsIE
+from .newstube import NewstubeIE
from .nfb import NFBIE
from .nhl import NHLIE, NHLVideocenterIE
from .niconico import NiconicoIE
diff --git a/youtube_dl/extractor/newstube.py b/youtube_dl/extractor/newstube.py
new file mode 100644
index 000000000..119414da0
--- /dev/null
+++ b/youtube_dl/extractor/newstube.py
@@ -0,0 +1,87 @@
+# encoding: utf-8
+from __future__ import unicode_literals
+
+import re
+
+from .common import InfoExtractor
+
+
+class NewstubeIE(InfoExtractor):
+ _VALID_URL = r'https?://(?:www\.)?newstube\.ru/media/(?P<id>.+)'
+ _TEST = {
+ 'url': 'http://newstube.ru/media/na-korable-progress-prodolzhaetsya-testirovanie-sistemy-kurs',
+ 'info_dict': {
+ 'id': 'd156a237-a6e9-4111-a682-039995f721f1',
+ 'ext': 'flv',
+ 'title': 'На корабле «Прогресс» продолжается тестирование системы «Курс»',
+ 'description': 'md5:d0cbe7b4a6f600552617e48548d5dc77',
+ 'duration': 20.04,
+ },
+ 'params': {
+ # rtmp download
+ 'skip_download': True,
+ },
+ }
+
+ def _real_extract(self, url):
+ mobj = re.match(self._VALID_URL, url)
+ video_id = mobj.group('id')
+
+ page = self._download_webpage(url, video_id, 'Downloading page')
+
+ video_guid = self._html_search_regex(
+ 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})',
+ page, 'video GUID')
+
+ player = self._download_xml(
+ 'http://p.newstube.ru/v2/player.asmx/GetAutoPlayInfo6?state=&url=%s&sessionId=&id=%s&placement=profile&location=n2' % (url, video_guid),
+ video_guid, 'Downloading player XML')
+
+ def ns(str):
+ return str.replace('/', '/%(ns)s') % {'ns': '{http://app1.newstube.ru/N2SiteWS/player.asmx}'}
+
+ session_id = player.find(ns('./SessionId')).text
+ media_info = player.find(ns('./Medias/MediaInfo'))
+ title = media_info.find(ns('./Name')).text
+ description = self._og_search_description(page)
+ thumbnail = media_info.find(ns('./KeyFrame')).text
+ duration = int(media_info.find(ns('./Duration')).text) / 1000.0
+
+ formats = []
+
+ for stream_info in media_info.findall(ns('./Streams/StreamInfo')):
+ media_location = stream_info.find(ns('./MediaLocation'))
+ if media_location is None:
+ continue
+
+ server = media_location.find(ns('./Server')).text
+ app = media_location.find(ns('./App')).text
+ media_id = stream_info.find(ns('./Id')).text
+ quality_id = stream_info.find(ns('./QualityId')).text
+ name = stream_info.find(ns('./Name')).text
+ width = int(stream_info.find(ns('./Width')).text)
+ height = int(stream_info.find(ns('./Height')).text)
+
+ formats.append({
+ 'url': 'rtmp://%s/%s' % (server, app),
+ 'app': app,
+ 'play_path': '01/%s' % video_guid.upper(),
+ 'rtmp_conn': ['S:%s' % session_id, 'S:%s' % media_id, 'S:n2'],
+ 'page_url': url,
+ 'ext': 'flv',
+ 'format_id': quality_id,
+ 'format_note': name,
+ 'width': width,
+ 'height': height,
+ })
+
+ self._sort_formats(formats)
+
+ return {
+ 'id': video_guid,
+ 'title': title,
+ 'description': description,
+ 'thumbnail': thumbnail,
+ 'duration': duration,
+ 'formats': formats,
+ } \ No newline at end of file