]> Raphaël G. Git Repositories - youtubedl/blob - youtube_dl/extractor/wat.py
Imported Upstream version 2014.06.07
[youtubedl] / youtube_dl / extractor / wat.py
1 # coding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8 unified_strdate,
9 )
10
11
12 class WatIE(InfoExtractor):
13 _VALID_URL = r'http://www\.wat\.tv/.*-(?P<shortID>.*?)_.*?\.html'
14 IE_NAME = 'wat.tv'
15 _TEST = {
16 'url': 'http://www.wat.tv/video/world-war-philadelphia-vost-6bv55_2fjr7_.html',
17 'info_dict': {
18 'id': '10631273',
19 'ext': 'mp4',
20 'title': 'World War Z - Philadelphia VOST',
21 'description': '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',
22 },
23 'params': {
24 # Sometimes wat serves the whole file with the --test option
25 'skip_download': True,
26 },
27 }
28
29 def download_video_info(self, real_id):
30 # 'contentv4' is used in the website, but it also returns the related
31 # videos, we don't need them
32 info = self._download_json('http://www.wat.tv/interface/contentv3/' + real_id, real_id)
33 return info['media']
34
35 def _real_extract(self, url):
36 def real_id_for_chapter(chapter):
37 return chapter['tc_start'].split('-')[0]
38 mobj = re.match(self._VALID_URL, url)
39 short_id = mobj.group('shortID')
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]
46
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 upload_date = None
60 if 'date_diffusion' in first_chapter:
61 upload_date = unified_strdate(first_chapter['date_diffusion'])
62 # Otherwise we can continue and extract just one part, we have to use
63 # the short id for getting the video url
64 return {
65 'id': real_id,
66 'url': 'http://wat.tv/get/android5/%s.mp4' % real_id,
67 'title': first_chapter['title'],
68 'thumbnail': first_chapter['preview'],
69 'description': first_chapter['description'],
70 'view_count': video_info['views'],
71 'upload_date': upload_date,
72 }