]> jfr.im git - yt-dlp.git/blob - youtube_dl/extractor/noco.py
Merge remote-tracking branch 'kwbr/master'
[yt-dlp.git] / 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 }
31
32 def _real_extract(self, url):
33 mobj = re.match(self._VALID_URL, url)
34 video_id = mobj.group('id')
35
36 medias = self._download_json(
37 'http://api.noco.tv/1.0/video/medias/%s' % video_id, video_id, 'Downloading video JSON')
38
39 formats = []
40
41 for fmt in medias['fr']['video_list']['default']['quality_list']:
42 format_id = fmt['quality_key']
43
44 file = self._download_json(
45 'http://api.noco.tv/1.0/video/file/%s/fr/%s' % (format_id.lower(), video_id),
46 video_id, 'Downloading %s video JSON' % format_id)
47
48 file_url = file['file']
49 if not file_url:
50 continue
51
52 if file_url == 'forbidden':
53 raise ExtractorError(
54 '%s returned error: %s - %s' % (
55 self.IE_NAME, file['popmessage']['title'], file['popmessage']['message']),
56 expected=True)
57
58 formats.append({
59 'url': file_url,
60 'format_id': format_id,
61 'width': fmt['res_width'],
62 'height': fmt['res_lines'],
63 'abr': fmt['audiobitrate'],
64 'vbr': fmt['videobitrate'],
65 'filesize': fmt['filesize'],
66 'format_note': fmt['quality_name'],
67 'preference': fmt['priority'],
68 })
69
70 self._sort_formats(formats)
71
72 show = self._download_json(
73 'http://api.noco.tv/1.0/shows/show/%s' % video_id, video_id, 'Downloading show JSON')[0]
74
75 upload_date = unified_strdate(show['indexed'])
76 uploader = show['partner_name']
77 uploader_id = show['partner_key']
78 duration = show['duration_ms'] / 1000.0
79 thumbnail = show['screenshot']
80
81 episode = show.get('show_TT') or show.get('show_OT')
82 family = show.get('family_TT') or show.get('family_OT')
83 episode_number = show.get('episode_number')
84
85 title = ''
86 if family:
87 title += family
88 if episode_number:
89 title += ' #' + compat_str(episode_number)
90 if episode:
91 title += ' - ' + episode
92
93 description = show.get('show_resume') or show.get('family_resume')
94
95 return {
96 'id': video_id,
97 'title': title,
98 'description': description,
99 'thumbnail': thumbnail,
100 'upload_date': upload_date,
101 'uploader': uploader,
102 'uploader_id': uploader_id,
103 'duration': duration,
104 'formats': formats,
105 }