[jadorecettepub] Add extractor (Fixes #2148)
[youtube-dl] / youtube_dl / extractor / jadorecettepub.py
1 # coding: utf-8
2
3 from __future__ import unicode_literals
4
5 import json
6 import re
7
8 from .common import InfoExtractor
9 from .youtube import YoutubeIE
10
11
12 class JadoreCettePubIE(InfoExtractor):
13     _VALID_URL = r'http://(?:www\.)?jadorecettepub\.com/[0-9]{4}/[0-9]{2}/(?P<id>.*?)\.html'
14
15     _TEST = {
16         'url': 'http://www.jadorecettepub.com/2010/12/star-wars-massacre-par-les-japonais.html',
17         'md5': '401286a06067c70b44076044b66515de',
18         'info_dict': {
19             'id': 'jLMja3tr7a4',
20             'ext': 'mp4',
21             'title': 'La pire utilisation de Star Wars',
22             'description': "Jadorecettepub.com vous a gratifié de plusieurs pubs géniales utilisant Star Wars et Dark Vador plus particulièrement... Mais l'heure est venue de vous proposer une version totalement massacrée, venue du Japon.  Quand les Japonais détruisent l'image de Star Wars pour vendre du thon en boite, ça promet...",
23         },
24     }
25
26     def _real_extract(self, url):
27         mobj = re.match(self._VALID_URL, url)
28         display_id = mobj.group('id')
29
30         webpage = self._download_webpage(url, display_id)
31
32         title = self._html_search_regex(
33             r'<span style="font-size: x-large;"><b>(.*?)</b></span>',
34             webpage, 'title')
35         description = self._html_search_regex(
36             r'(?s)<div id="fb-root">(.*?)<script>', webpage, 'description',
37             fatal=False)
38         real_url = self._search_regex(
39             r'\[/postlink\](.*)endofvid', webpage, 'video URL')
40         video_id = YoutubeIE.extract_id(real_url)
41
42         return {
43             '_type': 'url_transparent',
44             'url': real_url,
45             'id': video_id,
46             'title': title,
47             'description': description,
48         }
49