]> Raphaƫl G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wakanim.py
Initiate new release.
[youtubedl] / youtube_dl / extractor / wakanim.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 from .common import InfoExtractor
5 from ..utils import (
6 ExtractorError,
7 merge_dicts,
8 urljoin,
9 )
10
11
12 class WakanimIE(InfoExtractor):
13 _VALID_URL = r'https://(?:www\.)?wakanim\.tv/[^/]+/v2/catalogue/episode/(?P<id>\d+)'
14 _TESTS = [{
15 'url': 'https://www.wakanim.tv/de/v2/catalogue/episode/2997/the-asterisk-war-omu-staffel-1-episode-02-omu',
16 'info_dict': {
17 'id': '2997',
18 'ext': 'mp4',
19 'title': 'Episode 02',
20 'description': 'md5:2927701ea2f7e901de8bfa8d39b2852d',
21 'series': 'The Asterisk War (OmU.)',
22 'season_number': 1,
23 'episode': 'Episode 02',
24 'episode_number': 2,
25 },
26 'params': {
27 'format': 'bestvideo',
28 'skip_download': True,
29 },
30 }, {
31 # DRM Protected
32 'url': 'https://www.wakanim.tv/de/v2/catalogue/episode/7843/sword-art-online-alicization-omu-arc-2-folge-15-omu',
33 'only_matching': True,
34 }]
35
36 def _real_extract(self, url):
37 video_id = self._match_id(url)
38
39 webpage = self._download_webpage(url, video_id)
40
41 m3u8_url = urljoin(url, self._search_regex(
42 r'file\s*:\s*(["\'])(?P<url>(?:(?!\1).)+)\1', webpage, 'm3u8 url',
43 group='url'))
44 # https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-content-protection-overview#streaming-urls
45 encryption = self._search_regex(
46 r'encryption%3D(c(?:enc|bc(?:s-aapl)?))',
47 m3u8_url, 'encryption', default=None)
48 if encryption and encryption in ('cenc', 'cbcs-aapl'):
49 raise ExtractorError('This video is DRM protected.', expected=True)
50
51 formats = self._extract_m3u8_formats(
52 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
53 m3u8_id='hls')
54
55 info = self._search_json_ld(webpage, video_id, default={})
56
57 title = self._search_regex(
58 (r'<h1[^>]+\bclass=["\']episode_h1[^>]+\btitle=(["\'])(?P<title>(?:(?!\1).)+)\1',
59 r'<span[^>]+\bclass=["\']episode_title["\'][^>]*>(?P<title>[^<]+)'),
60 webpage, 'title', default=None, group='title')
61
62 return merge_dicts(info, {
63 'id': video_id,
64 'title': title,
65 'formats': formats,
66 })