]>
Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/adn.py
66caf6a818278796648dd4496da95c661fcdb36c
2 from __future__
import unicode_literals
8 from .common
import InfoExtractor
9 from ..aes
import aes_cbc_decrypt
10 from ..compat
import compat_ord
16 srt_subtitles_timecode
,
21 class ADNIE(InfoExtractor
):
22 IE_DESC
= 'Anime Digital Network'
23 _VALID_URL
= r
'https?://(?:www\.)?animedigitalnetwork\.fr/video/[^/]+/(?P<id>\d+)'
25 'url': 'http://animedigitalnetwork.fr/video/blue-exorcist-kyoto-saga/7778-episode-1-debut-des-hostilites',
26 'md5': 'e497370d847fd79d9d4c74be55575c7a',
30 'title': 'Blue Exorcist - Kyôto Saga - Épisode 1',
31 'description': 'md5:2f7b5aa76edbc1a7a92cedcda8a528d5',
35 def _get_subtitles(self
, sub_path
, video_id
):
39 enc_subtitles
= self
._download
_webpage
(
40 'http://animedigitalnetwork.fr/' + sub_path
,
41 video_id
, fatal
=False)
45 # http://animedigitalnetwork.fr/components/com_vodvideo/videojs/adn-vjs.min.js
46 dec_subtitles
= intlist_to_bytes(aes_cbc_decrypt(
47 bytes_to_intlist(base64
.b64decode(enc_subtitles
[24:])),
48 bytes_to_intlist(b
'\nd\xaf\xd2J\xd0\xfc\xe1\xfc\xdf\xb61\xe8\xe1\xf0\xcc'),
49 bytes_to_intlist(base64
.b64decode(enc_subtitles
[:24]))
51 subtitles_json
= self
._parse
_json
(
52 dec_subtitles
[:-compat_ord(dec_subtitles
[-1])],
54 if not subtitles_json
:
58 for sub_lang
, sub
in subtitles_json
.items():
60 for num
, current
in enumerate(sub
):
62 float_or_none(current
.get('startTime')),
63 float_or_none(current
.get('endTime')),
65 if start
is None or end
is None or text
is None:
67 srt
+= os
.linesep
.join(
71 srt_subtitles_timecode(start
),
72 srt_subtitles_timecode(end
)),
77 if sub_lang
== 'vostf':
79 subtitles
.setdefault(sub_lang
, []).extend([{
81 'data': json
.dumps(sub
),
88 def _real_extract(self
, url
):
89 video_id
= self
._match
_id
(url
)
90 webpage
= self
._download
_webpage
(url
, video_id
)
91 player_config
= self
._parse
_json
(self
._search
_regex
(
92 r
'playerConfig\s*=\s*({.+});', webpage
, 'player config'), video_id
)
95 video_info_str
= self
._search
_regex
(
96 r
'videoInfo\s*=\s*({.+});', webpage
,
97 'video info', fatal
=False)
99 video_info
= self
._parse
_json
(
100 video_info_str
, video_id
, fatal
=False) or {}
102 options
= player_config
.get('options') or {}
103 metas
= options
.get('metas') or {}
104 title
= metas
.get('title') or video_info
['title']
105 links
= player_config
.get('links') or {}
108 for format_id
, qualities
in links
.items():
109 for load_balancer_url
in qualities
.values():
110 load_balancer_data
= self
._download
_json
(
111 load_balancer_url
, video_id
, fatal
=False) or {}
112 m3u8_url
= load_balancer_data
.get('location')
115 m3u8_formats
= self
._extract
_m
3u8_formats
(
116 m3u8_url
, video_id
, 'mp4', 'm3u8_native',
117 m3u8_id
=format_id
, fatal
=False)
118 if format_id
== 'vf':
119 for f
in m3u8_formats
:
121 formats
.extend(m3u8_formats
)
122 error
= options
.get('error')
123 if not formats
and error
:
124 raise ExtractorError('%s said: %s' % (self
.IE_NAME
, error
), expected
=True)
125 self
._sort
_formats
(formats
)
130 'description': strip_or_none(metas
.get('summary') or video_info
.get('resume')),
131 'thumbnail': video_info
.get('image'),
133 'subtitles': self
.extract_subtitles(player_config
.get('subtitles'), video_id
),
134 'episode': metas
.get('subtitle') or video_info
.get('videoTitle'),
135 'series': video_info
.get('playlistTitle'),