summaryrefslogtreecommitdiff
path: root/youtube_dl/extractor/ketnet.py
blob: fb9c2dbd47789ae6f0457a4b2724c53875d14753 (plain)
    1 from __future__ import unicode_literals
    2 
    3 from .common import InfoExtractor
    4 
    5 
    6 class KetnetIE(InfoExtractor):
    7     _VALID_URL = r'https?://(?:www\.)?ketnet\.be/(?:[^/]+/)*(?P<id>[^/?#&]+)'
    8     _TESTS = [{
    9         'url': 'https://www.ketnet.be/kijken/zomerse-filmpjes',
   10         'md5': 'd907f7b1814ef0fa285c0475d9994ed7',
   11         'info_dict': {
   12             'id': 'zomerse-filmpjes',
   13             'ext': 'mp4',
   14             'title': 'Gluur mee op de filmset en op Pennenzakkenrock',
   15             'description': 'Gluur mee met Ghost Rockers op de filmset',
   16             'thumbnail': r're:^https?://.*\.jpg$',
   17         }
   18     }, {
   19         'url': 'https://www.ketnet.be/kijken/karrewiet/uitzending-8-september-2016',
   20         'only_matching': True,
   21     }, {
   22         'url': 'https://www.ketnet.be/achter-de-schermen/sien-repeteert-voor-stars-for-life',
   23         'only_matching': True,
   24     }, {
   25         # mzsource, geo restricted to Belgium
   26         'url': 'https://www.ketnet.be/kijken/nachtwacht/de-bermadoe',
   27         'only_matching': True,
   28     }]
   29 
   30     def _real_extract(self, url):
   31         video_id = self._match_id(url)
   32 
   33         webpage = self._download_webpage(url, video_id)
   34 
   35         config = self._parse_json(
   36             self._search_regex(
   37                 r'(?s)playerConfig\s*=\s*({.+?})\s*;', webpage,
   38                 'player config'),
   39             video_id)
   40 
   41         title = config['title']
   42 
   43         formats = []
   44         for source_key in ('', 'mz'):
   45             source = config.get('%ssource' % source_key)
   46             if not isinstance(source, dict):
   47                 continue
   48             for format_id, format_url in source.items():
   49                 if format_id == 'hls':
   50                     formats.extend(self._extract_m3u8_formats(
   51                         format_url, video_id, 'mp4',
   52                         entry_protocol='m3u8_native', m3u8_id=format_id,
   53                         fatal=False))
   54                 elif format_id == 'hds':
   55                     formats.extend(self._extract_f4m_formats(
   56                         format_url, video_id, f4m_id=format_id, fatal=False))
   57                 else:
   58                     formats.append({
   59                         'url': format_url,
   60                         'format_id': format_id,
   61                     })
   62         self._sort_formats(formats)
   63 
   64         return {
   65             'id': video_id,
   66             'title': title,
   67             'description': config.get('description'),
   68             'thumbnail': config.get('image'),
   69             'series': config.get('program'),
   70             'episode': config.get('episode'),
   71             'formats': formats,
   72         }

Generated by cgit