]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/screenwavemedia.py
d/control: Add build-dependency on dh-python as per warning from dh_python2.
[youtubedl] / youtube_dl / extractor / screenwavemedia.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 int_or_none,
9 unified_strdate,
10 )
11
12
13 class ScreenwaveMediaIE(InfoExtractor):
14 _VALID_URL = r'http://player\d?\.screenwavemedia\.com/(?:play/)?[a-zA-Z]+\.php\?[^"]*\bid=(?P<id>.+)'
15
16 _TESTS = [{
17 'url': 'http://player.screenwavemedia.com/play/play.php?playerdiv=videoarea&companiondiv=squareAd&id=Cinemassacre-19911',
18 'only_matching': True,
19 }]
20
21 def _real_extract(self, url):
22 video_id = self._match_id(url)
23
24 playerdata = self._download_webpage(
25 'http://player.screenwavemedia.com/play/player.php?id=%s' % video_id,
26 video_id, 'Downloading player webpage')
27
28 vidtitle = self._search_regex(
29 r'\'vidtitle\'\s*:\s*"([^"]+)"', playerdata, 'vidtitle').replace('\\/', '/')
30 vidurl = self._search_regex(
31 r'\'vidurl\'\s*:\s*"([^"]+)"', playerdata, 'vidurl').replace('\\/', '/')
32
33 videolist_url = None
34
35 mobj = re.search(r"'videoserver'\s*:\s*'(?P<videoserver>[^']+)'", playerdata)
36 if mobj:
37 videoserver = mobj.group('videoserver')
38 mobj = re.search(r'\'vidid\'\s*:\s*"(?P<vidid>[^\']+)"', playerdata)
39 vidid = mobj.group('vidid') if mobj else video_id
40 videolist_url = 'http://%s/vod/smil:%s.smil/jwplayer.smil' % (videoserver, vidid)
41 else:
42 mobj = re.search(r"file\s*:\s*'(?P<smil>http.+?/jwplayer\.smil)'", playerdata)
43 if mobj:
44 videolist_url = mobj.group('smil')
45
46 if videolist_url:
47 videolist = self._download_xml(videolist_url, video_id, 'Downloading videolist XML')
48 formats = []
49 baseurl = vidurl[:vidurl.rfind('/') + 1]
50 for video in videolist.findall('.//video'):
51 src = video.get('src')
52 if not src:
53 continue
54 file_ = src.partition(':')[-1]
55 width = int_or_none(video.get('width'))
56 height = int_or_none(video.get('height'))
57 bitrate = int_or_none(video.get('system-bitrate'), scale=1000)
58 format = {
59 'url': baseurl + file_,
60 'format_id': src.rpartition('.')[0].rpartition('_')[-1],
61 }
62 if width or height:
63 format.update({
64 'tbr': bitrate,
65 'width': width,
66 'height': height,
67 })
68 else:
69 format.update({
70 'abr': bitrate,
71 'vcodec': 'none',
72 })
73 formats.append(format)
74 else:
75 formats = [{
76 'url': vidurl,
77 }]
78 self._sort_formats(formats)
79
80 return {
81 'id': video_id,
82 'title': vidtitle,
83 'formats': formats,
84 }
85
86
87 class TeamFourIE(InfoExtractor):
88 _VALID_URL = r'https?://(?:www\.)?teamfourstar\.com/video/(?P<id>[a-z0-9\-]+)/?'
89 _TEST = {
90 'url': 'http://teamfourstar.com/video/a-moment-with-tfs-episode-4/',
91 'info_dict': {
92 'id': 'TeamFourStar-5292a02f20bfa',
93 'ext': 'mp4',
94 'upload_date': '20130401',
95 'description': 'Check out this and more on our website: http://teamfourstar.com\nTFS Store: http://sharkrobot.com/team-four-star\nFollow on Twitter: http://twitter.com/teamfourstar\nLike on FB: http://facebook.com/teamfourstar',
96 'title': 'A Moment With TFS Episode 4',
97 }
98 }
99
100 def _real_extract(self, url):
101 display_id = self._match_id(url)
102 webpage = self._download_webpage(url, display_id)
103
104 playerdata_url = self._search_regex(
105 r'src="(http://player\d?\.screenwavemedia\.com/(?:play/)?[a-zA-Z]+\.php\?[^"]*\bid=.+?)"',
106 webpage, 'player data URL')
107
108 video_title = self._html_search_regex(
109 r'<div class="heroheadingtitle">(?P<title>.+?)</div>',
110 webpage, 'title')
111 video_date = unified_strdate(self._html_search_regex(
112 r'<div class="heroheadingdate">(?P<date>.+?)</div>',
113 webpage, 'date', fatal=False))
114 video_description = self._html_search_regex(
115 r'(?s)<div class="postcontent">(?P<description>.+?)</div>',
116 webpage, 'description', fatal=False)
117 video_thumbnail = self._og_search_thumbnail(webpage)
118
119 return {
120 '_type': 'url_transparent',
121 'display_id': display_id,
122 'title': video_title,
123 'description': video_description,
124 'upload_date': video_date,
125 'thumbnail': video_thumbnail,
126 'url': playerdata_url,
127 }