]> git.bitcoin.ninja Git - youtube-dl/blob - youtube_dl/extractor/noco.py
release 2014.09.04
[youtube-dl] / youtube_dl / extractor / noco.py
1 # encoding: utf-8
2 from __future__ import unicode_literals
3
4 import re
5
6 from .common import InfoExtractor
7 from ..utils import (
8     ExtractorError,
9     unified_strdate,
10     compat_str,
11 )
12
13
14 class NocoIE(InfoExtractor):
15     _VALID_URL = r'http://(?:(?:www\.)?noco\.tv/emission/|player\.noco\.tv/\?idvideo=)(?P<id>\d+)'
16
17     _TEST = {
18         'url': 'http://noco.tv/emission/11538/nolife/ami-ami-idol-hello-france/',
19         'md5': '0a993f0058ddbcd902630b2047ef710e',
20         'info_dict': {
21             'id': '11538',
22             'ext': 'mp4',
23             'title': 'Ami Ami Idol - Hello! France',
24             'description': 'md5:4eaab46ab68fa4197a317a88a53d3b86',
25             'upload_date': '20140412',
26             'uploader': 'Nolife',
27             'uploader_id': 'NOL',
28             'duration': 2851.2,
29         },
30         'skip': 'Requires noco account',
31     }
32
33     def _real_extract(self, url):
34         mobj = re.match(self._VALID_URL, url)
35         video_id = mobj.group('id')
36
37         medias = self._download_json(
38             'https://api.noco.tv/1.0/video/medias/%s' % video_id, video_id, 'Downloading video JSON')
39
40         formats = []
41
42         for fmt in medias['fr']['video_list']['default']['quality_list']:
43             format_id = fmt['quality_key']
44
45             file = self._download_json(
46                 'https://api.noco.tv/1.0/video/file/%s/fr/%s' % (format_id.lower(), video_id),
47                 video_id, 'Downloading %s video JSON' % format_id)
48
49             file_url = file['file']
50             if not file_url:
51                 continue
52
53             if file_url == 'forbidden':
54                 raise ExtractorError(
55                     '%s returned error: %s - %s' % (
56                         self.IE_NAME, file['popmessage']['title'], file['popmessage']['message']),
57                     expected=True)
58
59             formats.append({
60                 'url': file_url,
61                 'format_id': format_id,
62                 'width': fmt['res_width'],
63                 'height': fmt['res_lines'],
64                 'abr': fmt['audiobitrate'],
65                 'vbr': fmt['videobitrate'],
66                 'filesize': fmt['filesize'],
67                 'format_note': fmt['quality_name'],
68                 'preference': fmt['priority'],
69             })
70
71         self._sort_formats(formats)
72
73         show = self._download_json(
74             'https://api.noco.tv/1.0/shows/show/%s' % video_id, video_id, 'Downloading show JSON')[0]
75
76         upload_date = unified_strdate(show['indexed'])
77         uploader = show['partner_name']
78         uploader_id = show['partner_key']
79         duration = show['duration_ms'] / 1000.0
80         thumbnail = show['screenshot']
81
82         episode = show.get('show_TT') or show.get('show_OT')
83         family = show.get('family_TT') or show.get('family_OT')
84         episode_number = show.get('episode_number')
85
86         title = ''
87         if family:
88             title += family
89         if episode_number:
90             title += ' #' + compat_str(episode_number)
91         if episode:
92             title += ' - ' + episode
93
94         description = show.get('show_resume') or show.get('family_resume')
95
96         return {
97             'id': video_id,
98             'title': title,
99             'description': description,
100             'thumbnail': thumbnail,
101             'upload_date': upload_date,
102             'uploader': uploader,
103             'uploader_id': uploader_id,
104             'duration': duration,
105             'formats': formats,
106         }