youtube-dl

Another place where youtube-dl lives on
git clone git://git.oshgnacknak.de/youtube-dl.git
Log | Files | Refs | README | LICENSE

amcnetworks.py (4967B)


      1 # coding: utf-8
      2 from __future__ import unicode_literals
      3 
      4 import re
      5 
      6 from .theplatform import ThePlatformIE
      7 from ..utils import (
      8     int_or_none,
      9     parse_age_limit,
     10     try_get,
     11     update_url_query,
     12 )
     13 
     14 
     15 class AMCNetworksIE(ThePlatformIE):
     16     _VALID_URL = r'https?://(?:www\.)?(?P<site>amc|bbcamerica|ifc|(?:we|sundance)tv)\.com/(?P<id>(?:movies|shows(?:/[^/]+)+)/[^/?#&]+)'
     17     _TESTS = [{
     18         'url': 'https://www.bbcamerica.com/shows/the-graham-norton-show/videos/tina-feys-adorable-airline-themed-family-dinner--51631',
     19         'info_dict': {
     20             'id': '4Lq1dzOnZGt0',
     21             'ext': 'mp4',
     22             'title': "The Graham Norton Show - Season 28 - Tina Fey's Adorable Airline-Themed Family Dinner",
     23             'description': "It turns out child stewardesses are very generous with the wine! All-new episodes of 'The Graham Norton Show' premiere Fridays at 11/10c on BBC America.",
     24             'upload_date': '20201120',
     25             'timestamp': 1605904350,
     26             'uploader': 'AMCN',
     27         },
     28         'params': {
     29             # m3u8 download
     30             'skip_download': True,
     31         },
     32     }, {
     33         'url': 'http://www.bbcamerica.com/shows/the-hunt/full-episodes/season-1/episode-01-the-hardest-challenge',
     34         'only_matching': True,
     35     }, {
     36         'url': 'http://www.amc.com/shows/preacher/full-episodes/season-01/episode-00/pilot',
     37         'only_matching': True,
     38     }, {
     39         'url': 'http://www.wetv.com/shows/million-dollar-matchmaker/season-01/episode-06-the-dumped-dj-and-shallow-hal',
     40         'only_matching': True,
     41     }, {
     42         'url': 'http://www.ifc.com/movies/chaos',
     43         'only_matching': True,
     44     }, {
     45         'url': 'http://www.bbcamerica.com/shows/doctor-who/full-episodes/the-power-of-the-daleks/episode-01-episode-1-color-version',
     46         'only_matching': True,
     47     }, {
     48         'url': 'http://www.wetv.com/shows/mama-june-from-not-to-hot/full-episode/season-01/thin-tervention',
     49         'only_matching': True,
     50     }, {
     51         'url': 'http://www.wetv.com/shows/la-hair/videos/season-05/episode-09-episode-9-2/episode-9-sneak-peek-3',
     52         'only_matching': True,
     53     }, {
     54         'url': 'https://www.sundancetv.com/shows/riviera/full-episodes/season-1/episode-01-episode-1',
     55         'only_matching': True,
     56     }]
     57     _REQUESTOR_ID_MAP = {
     58         'amc': 'AMC',
     59         'bbcamerica': 'BBCA',
     60         'ifc': 'IFC',
     61         'sundancetv': 'SUNDANCE',
     62         'wetv': 'WETV',
     63     }
     64 
     65     def _real_extract(self, url):
     66         site, display_id = re.match(self._VALID_URL, url).groups()
     67         requestor_id = self._REQUESTOR_ID_MAP[site]
     68         properties = self._download_json(
     69             'https://content-delivery-gw.svc.ds.amcn.com/api/v2/content/amcn/%s/url/%s' % (requestor_id.lower(), display_id),
     70             display_id)['data']['properties']
     71         query = {
     72             'mbr': 'true',
     73             'manifest': 'm3u',
     74         }
     75         tp_path = 'M_UwQC/media/' + properties['videoPid']
     76         media_url = 'https://link.theplatform.com/s/' + tp_path
     77         theplatform_metadata = self._download_theplatform_metadata(tp_path, display_id)
     78         info = self._parse_theplatform_metadata(theplatform_metadata)
     79         video_id = theplatform_metadata['pid']
     80         title = theplatform_metadata['title']
     81         rating = try_get(
     82             theplatform_metadata, lambda x: x['ratings'][0]['rating'])
     83         video_category = properties.get('videoCategory')
     84         if video_category and video_category.endswith('-Auth'):
     85             resource = self._get_mvpd_resource(
     86                 requestor_id, title, video_id, rating)
     87             query['auth'] = self._extract_mvpd_auth(
     88                 url, video_id, requestor_id, resource)
     89         media_url = update_url_query(media_url, query)
     90         formats, subtitles = self._extract_theplatform_smil(
     91             media_url, video_id)
     92         self._sort_formats(formats)
     93         info.update({
     94             'id': video_id,
     95             'subtitles': subtitles,
     96             'formats': formats,
     97             'age_limit': parse_age_limit(parse_age_limit(rating)),
     98         })
     99         ns_keys = theplatform_metadata.get('$xmlns', {}).keys()
    100         if ns_keys:
    101             ns = list(ns_keys)[0]
    102             series = theplatform_metadata.get(ns + '$show')
    103             season_number = int_or_none(
    104                 theplatform_metadata.get(ns + '$season'))
    105             episode = theplatform_metadata.get(ns + '$episodeTitle')
    106             episode_number = int_or_none(
    107                 theplatform_metadata.get(ns + '$episode'))
    108             if season_number:
    109                 title = 'Season %d - %s' % (season_number, title)
    110             if series:
    111                 title = '%s - %s' % (series, title)
    112             info.update({
    113                 'title': title,
    114                 'series': series,
    115                 'season_number': season_number,
    116                 'episode': episode,
    117                 'episode_number': episode_number,
    118             })
    119         return info