[fxnetworks] add test and check geo restriction
[youtube-dl] / youtube_dl / extractor / fxnetworks.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .adobepass import AdobePass
5 from ..utils import (
6     update_url_query,
7     extract_attributes,
8     parse_age_limit,
9     smuggle_url,
10 )
11
12
13 class FXNetworksIE(AdobePass):
14     _VALID_URL = r'https?://(?:www\.)?fxnetworks\.com/video/(?P<id>\d+)'
15     _TEST = {
16         'url': 'http://www.fxnetworks.com/video/719841347694',
17         'md5': '1447d4722e42ebca19e5232ab93abb22',
18         'info_dict': {
19             'id': '719841347694',
20             'ext': 'mp4',
21             'title': 'Vanpage',
22             'description': 'F*ck settling down. You\'re the Worst returns for an all new season August 31st on FXX.',
23             'age_limit': 14,
24             'uploader': 'NEWA-FNG-FX',
25             'upload_date': '20160706',
26             'timestamp': 1467844741,
27         },
28         'add_ie': ['ThePlatform'],
29     }
30
31     def _real_extract(self, url):
32         video_id = self._match_id(url)
33         webpage = self._download_webpage(url, video_id)
34         if 'The content you are trying to access is not available in your region.' in webpage:
35             self.raise_geo_restricted()
36         video_data = extract_attributes(self._search_regex(
37             r'(<a.+?rel="http://link\.theplatform\.com/s/.+?</a>)', webpage, 'video data'))
38         player_type = self._search_regex(r'playerType\s*=\s*[\'"]([^\'"]+)', webpage, 'player type', fatal=False)
39         release_url = video_data['rel']
40         title = video_data['data-title']
41         rating = video_data.get('data-rating')
42         query = {
43             'mbr': 'true',
44         }
45         if player_type == 'movies':
46             query.update({
47                 'manifest': 'm3u',
48             })
49         else:
50             query.update({
51                 'switch': 'http',
52             })
53         if video_data.get('data-req-auth') == '1':
54             resource = self._get_mvpd_resource(
55                 video_data['data-channel'], title,
56                 video_data.get('data-guid'), rating)
57             query['auth'] = self._extract_mvpd_auth(url, video_id, 'fx', resource)
58
59         return {
60             '_type': 'url_transparent',
61             'id': video_id,
62             'title': title,
63             'url': smuggle_url(update_url_query(release_url, query), {'force_smil_url': True}),
64             'thumbnail': video_data.get('data-large-thumb'),
65             'age_limit': parse_age_limit(rating),
66             'ie_key': 'ThePlatform',
67         }