[defense] Modernize
[youtube-dl] / youtube_dl / extractor / defense.py
1 from __future__ import unicode_literals
2
3 import re
4 import json
5
6 from .common import InfoExtractor
7
8
9 class DefenseGouvFrIE(InfoExtractor):
10     IE_NAME = 'defense.gouv.fr'
11     _VALID_URL = r'http://.*?\.defense\.gouv\.fr/layout/set/ligthboxvideo/base-de-medias/webtv/(?P<id>[^/?#]*)'
12
13     _TEST = {
14         'url': 'http://www.defense.gouv.fr/layout/set/ligthboxvideo/base-de-medias/webtv/attaque-chimique-syrienne-du-21-aout-2013-1',
15         'md5': '75bba6124da7e63d2d60b5244ec9430c',
16         'info_dict': {
17             'id': '11213',
18             'ext': 'mp4',
19             'title': 'attaque-chimique-syrienne-du-21-aout-2013-1'
20         }
21     }
22
23     def _real_extract(self, url):
24         title = self._match_id(url)
25         webpage = self._download_webpage(url, title)
26
27         video_id = self._search_regex(
28             r"flashvars.pvg_id=\"(\d+)\";",
29             webpage, 'ID')
30
31         json_url = ('http://static.videos.gouv.fr/brightcovehub/export/json/'
32                     + video_id)
33         info = self._download_json(json_url, title, 'Downloading JSON config')
34         video_url = info['renditions'][0]['url']
35
36         return {
37             'id': video_id,
38             'ext': 'mp4',
39             'url': video_url,
40             'title': title,
41         }