2 from __future__ import unicode_literals
6 from .common import InfoExtractor
17 class NocoIE(InfoExtractor):
18 _VALID_URL = r'http://(?:(?:www\.)?noco\.tv/emission/|player\.noco\.tv/\?idvideo=)(?P<id>\d+)'
19 _LOGIN_URL = 'http://noco.tv/do.php'
20 _NETRC_MACHINE = 'noco'
23 'url': 'http://noco.tv/emission/11538/nolife/ami-ami-idol-hello-france/',
24 'md5': '0a993f0058ddbcd902630b2047ef710e',
28 'title': 'Ami Ami Idol - Hello! France',
29 'description': 'md5:4eaab46ab68fa4197a317a88a53d3b86',
30 'upload_date': '20140412',
35 'skip': 'Requires noco account',
38 def _real_initialize(self):
42 (username, password) = self._get_login_info()
52 request = compat_urllib_request.Request(self._LOGIN_URL, compat_urllib_parse.urlencode(login_form))
53 request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
55 login = self._download_json(request, None, 'Logging in as %s' % username)
58 raise ExtractorError('Unable to login: %s' % clean_html(login['erreur']), expected=True)
60 def _real_extract(self, url):
61 mobj = re.match(self._VALID_URL, url)
62 video_id = mobj.group('id')
64 medias = self._download_json(
65 'https://api.noco.tv/1.0/video/medias/%s' % video_id, video_id, 'Downloading video JSON')
69 for fmt in medias['fr']['video_list']['default']['quality_list']:
70 format_id = fmt['quality_key']
72 file = self._download_json(
73 'https://api.noco.tv/1.0/video/file/%s/fr/%s' % (format_id.lower(), video_id),
74 video_id, 'Downloading %s video JSON' % format_id)
76 file_url = file['file']
80 if file_url == 'forbidden':
82 '%s returned error: %s - %s' % (
83 self.IE_NAME, file['popmessage']['title'], file['popmessage']['message']),
88 'format_id': format_id,
89 'width': fmt['res_width'],
90 'height': fmt['res_lines'],
91 'abr': fmt['audiobitrate'],
92 'vbr': fmt['videobitrate'],
93 'filesize': fmt['filesize'],
94 'format_note': fmt['quality_name'],
95 'preference': fmt['priority'],
98 self._sort_formats(formats)
100 show = self._download_json(
101 'https://api.noco.tv/1.0/shows/show/%s' % video_id, video_id, 'Downloading show JSON')[0]
103 upload_date = unified_strdate(show['indexed'])
104 uploader = show['partner_name']
105 uploader_id = show['partner_key']
106 duration = show['duration_ms'] / 1000.0
107 thumbnail = show['screenshot']
109 episode = show.get('show_TT') or show.get('show_OT')
110 family = show.get('family_TT') or show.get('family_OT')
111 episode_number = show.get('episode_number')
117 title += ' #' + compat_str(episode_number)
119 title += ' - ' + episode
121 description = show.get('show_resume') or show.get('family_resume')
126 'description': description,
127 'thumbnail': thumbnail,
128 'upload_date': upload_date,
129 'uploader': uploader,
130 'uploader_id': uploader_id,
131 'duration': duration,