[shahid] raise ExtractorError instead of warning
[youtube-dl] / youtube_dl / extractor / shahid.py
1 from .common import InfoExtractor
2 from ..utils import (
3     get_element_by_id,
4     ExtractorError,
5 }
6
7 class ShahidIE(InfoExtractor):
8     _VALID_URL = r'https?://shahid\.mbc\.net/ar/episode/(?P<id>\d+)/?'
9     _TESTS = [
10         {
11             'url': 'https://shahid.mbc.net/ar/episode/108084/%D8%AE%D9%88%D8%A7%D8%B7%D8%B1-%D8%A7%D9%84%D9%85%D9%88%D8%B3%D9%85-11-%D8%A7%D9%84%D8%AD%D9%84%D9%82%D8%A9-1.html',
12             'info_dict': {
13                 'id': '108084',
14                 'ext': 'm3u8',
15                 'title': 'بسم الله',
16                 'description': 'بسم الله'
17             },
18             'params': {
19                 # m3u8 download
20                 'skip_download': True,
21             }
22         },
23         {
24             #shahid plus subscriber only
25             'url': 'https://shahid.mbc.net/ar/series/90497/%D9%85%D8%B1%D8%A7%D9%8A%D8%A7-2011.html',
26             'only_matching': True
27         }
28     ]
29
30     def _real_extract(self, url):
31         video_id = self._match_id(url)
32         webpage = self._download_webpage(url, video_id)
33         json_data = self._parse_json(
34             get_element_by_id('jsonld', webpage),
35             video_id
36         )
37         title = json_data['name']
38         thumbnail = json_data['image']
39         categories = json_data['genre']
40         description = json_data['description']
41         player_json_data = self._download_json(
42             'https://shahid.mbc.net/arContent/getPlayerContent-param-.id-'+video_id+'.type-player.html',
43             video_id
44         )['data']
45         if 'url' in player_json_data:
46             m3u8_url = player_json_data['url']
47         else:
48             for error in json_data['error'].values():
49                 raise ExtractorError(error)
50             return
51         formats = self._extract_m3u8_formats(m3u8_url, video_id)
52         return {
53             'id': video_id,
54             'title': title,
55             'thumbnail': thumbnail,
56             'categories': categories,
57             'description': description,
58             'formats': formats,
59         }