]> jfr.im git - yt-dlp.git/blame - youtube_dl/extractor/wat.py
[jeuxvideo] Modernize
[yt-dlp.git] / youtube_dl / extractor / wat.py
CommitLineData
8244288d
JMF
1# coding: utf-8
2
99afb3dd
JMF
3import json
4import re
5
6from .common import InfoExtractor
7
8from ..utils import (
8244288d 9 unified_strdate,
99afb3dd
JMF
10)
11
12
13class WatIE(InfoExtractor):
c0ade33e 14 _VALID_URL=r'http://www\.wat\.tv/.*-(?P<shortID>.*?)_.*?\.html'
99afb3dd
JMF
15 IE_NAME = 'wat.tv'
16 _TEST = {
17 u'url': u'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
8244288d 18 u'file': u'10631273.mp4',
0725f584 19 u'md5': u'd8b2231e1e333acd12aad94b80937e19',
99afb3dd 20 u'info_dict': {
8244288d
JMF
21 u'title': u'World War Z - Philadelphia VOST',
22 u'description': u'La menace est partout. Que se passe-t-il à Philadelphia ?\r\nWORLD WAR Z, avec Brad Pitt, au cinéma le 3 juillet.\r\nhttp://www.worldwarz.fr',
fa800269
JMF
23 },
24 u'skip': u'Sometimes wat serves the whole file with the --test option',
99afb3dd 25 }
8244288d
JMF
26
27 def download_video_info(self, real_id):
28 # 'contentv4' is used in the website, but it also returns the related
29 # videos, we don't need them
30 info = self._download_webpage('http://www.wat.tv/interface/contentv3/' + real_id, real_id, 'Downloading video info')
31 info = json.loads(info)
32 return info['media']
33
99afb3dd
JMF
34
35 def _real_extract(self, url):
8244288d
JMF
36 def real_id_for_chapter(chapter):
37 return chapter['tc_start'].split('-')[0]
99afb3dd
JMF
38 mobj = re.match(self._VALID_URL, url)
39 short_id = mobj.group('shortID')
8244288d
JMF
40 webpage = self._download_webpage(url, short_id)
41 real_id = self._search_regex(r'xtpage = ".*-(.*?)";', webpage, 'real id')
42
43 video_info = self.download_video_info(real_id)
44 chapters = video_info['chapters']
45 first_chapter = chapters[0]
99afb3dd 46
8244288d
JMF
47 if real_id_for_chapter(first_chapter) != real_id:
48 self.to_screen('Multipart video detected')
49 chapter_urls = []
50 for chapter in chapters:
51 chapter_id = real_id_for_chapter(chapter)
52 # Yes, when we this chapter is processed by WatIE,
53 # it will download the info again
54 chapter_info = self.download_video_info(chapter_id)
55 chapter_urls.append(chapter_info['url'])
56 entries = [self.url_result(chapter_url) for chapter_url in chapter_urls]
57 return self.playlist_result(entries, real_id, video_info['title'])
58
59 # Otherwise we can continue and extract just one part, we have to use
60 # the short id for getting the video url
8244288d 61 info = {'id': real_id,
0725f584 62 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
99afb3dd 63 'ext': 'mp4',
8244288d
JMF
64 'title': first_chapter['title'],
65 'thumbnail': first_chapter['preview'],
66 'description': first_chapter['description'],
67 'view_count': video_info['views'],
99afb3dd 68 }
8244288d
JMF
69 if 'date_diffusion' in first_chapter:
70 info['upload_date'] = unified_strdate(first_chapter['date_diffusion'])
71
72 return info