]> jfr.im git - yt-dlp.git/blame - yt_dlp/extractor/wakanim.py
Completely change project name to yt-dlp (#85)
[yt-dlp.git] / yt_dlp / extractor / wakanim.py
CommitLineData
845333ac
S
1# coding: utf-8
2from __future__ import unicode_literals
3
4from .common import InfoExtractor
5from ..utils import (
30cd1a5f 6 ExtractorError,
845333ac
S
7 merge_dicts,
8 urljoin,
9)
10
11
12class WakanimIE(InfoExtractor):
13 _VALID_URL = r'https://(?:www\.)?wakanim\.tv/[^/]+/v2/catalogue/episode/(?P<id>\d+)'
30cd1a5f 14 _TESTS = [{
845333ac
S
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 },
30cd1a5f
RA
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 }]
845333ac
S
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'))
06869367 44 if not self._downloader.params.get('allow_unplayable_formats'):
45 # https://docs.microsoft.com/en-us/azure/media-services/previous/media-services-content-protection-overview#streaming-urls
46 encryption = self._search_regex(
47 r'encryption%3D(c(?:enc|bc(?:s-aapl)?))',
48 m3u8_url, 'encryption', default=None)
49 if encryption in ('cenc', 'cbcs-aapl'):
50 raise ExtractorError('This video is DRM protected.', expected=True)
845333ac
S
51
52 formats = self._extract_m3u8_formats(
53 m3u8_url, video_id, 'mp4', entry_protocol='m3u8_native',
54 m3u8_id='hls')
55
56 info = self._search_json_ld(webpage, video_id, default={})
57
58 title = self._search_regex(
59 (r'<h1[^>]+\bclass=["\']episode_h1[^>]+\btitle=(["\'])(?P<title>(?:(?!\1).)+)\1',
60 r'<span[^>]+\bclass=["\']episode_title["\'][^>]*>(?P<title>[^<]+)'),
61 webpage, 'title', default=None, group='title')
62
63 return merge_dicts(info, {
64 'id': video_id,
65 'title': title,
66 'formats': formats,
67 })