]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/viewster.py
[SpankBang] Use python2.6 compatible string formatting spec
[youtube-dl] / youtube_dl / extractor / viewster.py
1 from __future__ import unicode_literals
2
3 from .common import InfoExtractor
4 from ..compat import compat_urllib_request
5
6
7 class ViewsterIE(InfoExtractor):
8     _VALID_URL = r'http://(?:www\.)?viewster\.com/movie/(?P<id>\d+-\d+-\d+)'
9     _TESTS = [{
10         # movielink, paymethod=fre
11         'url': 'http://www.viewster.com/movie/1293-19341-000/hout-wood/',
12         'playlist': [{
13             'md5': '8f9d94b282d80c42b378dffdbb11caf3',
14             'info_dict': {
15                 'id': '1293-19341-000-movie',
16                 'ext': 'flv',
17                 'title': "'Hout' (Wood) - Movie",
18             },
19         }],
20         'info_dict': {
21             'id': '1293-19341-000',
22             'title': "'Hout' (Wood)",
23             'description': 'md5:925733185a9242ef96f436937683f33b',
24         }
25     }, {
26         # movielink, paymethod=adv
27         'url': 'http://www.viewster.com/movie/1140-11855-000/the-listening-project/',
28         'playlist': [{
29             'md5': '77a005453ca7396cbe3d35c9bea30aef',
30             'info_dict': {
31                 'id': '1140-11855-000-movie',
32                 'ext': 'flv',
33                 'title': "THE LISTENING PROJECT - Movie",
34             },
35         }],
36         'info_dict': {
37             'id': '1140-11855-000',
38             'title': "THE LISTENING PROJECT",
39             'description': 'md5:714421ae9957e112e672551094bf3b08',
40         }
41     }, {
42         # direct links, no movielink
43         'url': 'http://www.viewster.com/movie/1198-56411-000/sinister/',
44         'playlist': [{
45             'md5': '0307b7eac6bfb21ab0577a71f6eebd8f',
46             'info_dict': {
47                 'id': '1198-56411-000-trailer',
48                 'ext': 'mp4',
49                 'title': "Sinister - Trailer",
50             },
51         }, {
52             'md5': '80b9ee3ad69fb368f104cb5d9732ae95',
53             'info_dict': {
54                 'id': '1198-56411-000-behind-scenes',
55                 'ext': 'mp4',
56                 'title': "Sinister - Behind Scenes",
57             },
58         }, {
59             'md5': '3b3ea897ecaa91fca57a8a94ac1b15c5',
60             'info_dict': {
61                 'id': '1198-56411-000-scene-from-movie',
62                 'ext': 'mp4',
63                 'title': "Sinister - Scene from movie",
64             },
65         }],
66         'info_dict': {
67             'id': '1198-56411-000',
68             'title': "Sinister",
69             'description': 'md5:014c40b0488848de9683566a42e33372',
70         }
71     }]
72
73     _ACCEPT_HEADER = 'application/json, text/javascript, */*; q=0.01'
74
75     def _real_extract(self, url):
76         video_id = self._match_id(url)
77
78         request = compat_urllib_request.Request(
79             'http://api.live.viewster.com/api/v1/movie/%s' % video_id)
80         request.add_header('Accept', self._ACCEPT_HEADER)
81
82         movie = self._download_json(
83             request, video_id, 'Downloading movie metadata JSON')
84
85         title = movie.get('title') or movie['original_title']
86         description = movie.get('synopsis')
87         thumbnail = movie.get('large_artwork') or movie.get('artwork')
88
89         entries = []
90         for clip in movie['play_list']:
91             entry = None
92
93             # movielink api
94             link_request = clip.get('link_request')
95             if link_request:
96                 request = compat_urllib_request.Request(
97                     'http://api.live.viewster.com/api/v1/movielink?movieid=%(movieid)s&action=%(action)s&paymethod=%(paymethod)s&price=%(price)s&currency=%(currency)s&language=%(language)s&subtitlelanguage=%(subtitlelanguage)s&ischromecast=%(ischromecast)s'
98                     % link_request)
99                 request.add_header('Accept', self._ACCEPT_HEADER)
100
101                 movie_link = self._download_json(
102                     request, video_id, 'Downloading movie link JSON', fatal=False)
103
104                 if movie_link:
105                     formats = self._extract_f4m_formats(
106                         movie_link['url'] + '&hdcore=3.2.0&plugin=flowplayer-3.2.0.1', video_id)
107                     self._sort_formats(formats)
108                     entry = {
109                         'formats': formats,
110                     }
111
112             # direct link
113             clip_url = clip.get('clip_data', {}).get('url')
114             if clip_url:
115                 entry = {
116                     'url': clip_url,
117                     'ext': 'mp4',
118                 }
119
120             if entry:
121                 entry.update({
122                     'id': '%s-%s' % (video_id, clip['canonical_title']),
123                     'title': '%s - %s' % (title, clip['title']),
124                 })
125                 entries.append(entry)
126
127         playlist = self.playlist_result(entries, video_id, title, description)
128         playlist['thumbnail'] = thumbnail
129         return playlist