You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.2 KiB

11 years ago
  1. # encoding: utf-8
  2. from __future__ import unicode_literals
  3. import re
  4. from .common import InfoExtractor
  5. from ..utils import (
  6. compat_urllib_request,
  7. compat_urllib_parse,
  8. ExtractorError,
  9. clean_html,
  10. unified_strdate,
  11. compat_str,
  12. )
  13. class NocoIE(InfoExtractor):
  14. _VALID_URL = r'http://(?:(?:www\.)?noco\.tv/emission/|player\.noco\.tv/\?idvideo=)(?P<id>\d+)'
  15. _LOGIN_URL = 'http://noco.tv/do.php'
  16. _NETRC_MACHINE = 'noco'
  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. def _real_initialize(self):
  33. self._login()
  34. def _login(self):
  35. (username, password) = self._get_login_info()
  36. if username is None:
  37. return
  38. login_form = {
  39. 'a': 'login',
  40. 'cookie': '1',
  41. 'username': username,
  42. 'password': password,
  43. }
  44. request = compat_urllib_request.Request(self._LOGIN_URL, compat_urllib_parse.urlencode(login_form))
  45. request.add_header('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8')
  46. login = self._download_json(request, None, 'Logging in as %s' % username)
  47. if 'erreur' in login:
  48. raise ExtractorError('Unable to login: %s' % clean_html(login['erreur']), expected=True)
  49. def _real_extract(self, url):
  50. mobj = re.match(self._VALID_URL, url)
  51. video_id = mobj.group('id')
  52. medias = self._download_json(
  53. 'https://api.noco.tv/1.0/video/medias/%s' % video_id, video_id, 'Downloading video JSON')
  54. formats = []
  55. for fmt in medias['fr']['video_list']['default']['quality_list']:
  56. format_id = fmt['quality_key']
  57. file = self._download_json(
  58. 'https://api.noco.tv/1.0/video/file/%s/fr/%s' % (format_id.lower(), video_id),
  59. video_id, 'Downloading %s video JSON' % format_id)
  60. file_url = file['file']
  61. if not file_url:
  62. continue
  63. if file_url == 'forbidden':
  64. raise ExtractorError(
  65. '%s returned error: %s - %s' % (
  66. self.IE_NAME, file['popmessage']['title'], file['popmessage']['message']),
  67. expected=True)
  68. formats.append({
  69. 'url': file_url,
  70. 'format_id': format_id,
  71. 'width': fmt['res_width'],
  72. 'height': fmt['res_lines'],
  73. 'abr': fmt['audiobitrate'],
  74. 'vbr': fmt['videobitrate'],
  75. 'filesize': fmt['filesize'],
  76. 'format_note': fmt['quality_name'],
  77. 'preference': fmt['priority'],
  78. })
  79. self._sort_formats(formats)
  80. show = self._download_json(
  81. 'https://api.noco.tv/1.0/shows/show/%s' % video_id, video_id, 'Downloading show JSON')[0]
  82. upload_date = unified_strdate(show['indexed'])
  83. uploader = show['partner_name']
  84. uploader_id = show['partner_key']
  85. duration = show['duration_ms'] / 1000.0
  86. thumbnail = show['screenshot']
  87. episode = show.get('show_TT') or show.get('show_OT')
  88. family = show.get('family_TT') or show.get('family_OT')
  89. episode_number = show.get('episode_number')
  90. title = ''
  91. if family:
  92. title += family
  93. if episode_number:
  94. title += ' #' + compat_str(episode_number)
  95. if episode:
  96. title += ' - ' + episode
  97. description = show.get('show_resume') or show.get('family_resume')
  98. return {
  99. 'id': video_id,
  100. 'title': title,
  101. 'description': description,
  102. 'thumbnail': thumbnail,
  103. 'upload_date': upload_date,
  104. 'uploader': uploader,
  105. 'uploader_id': uploader_id,
  106. 'duration': duration,
  107. 'formats': formats,
  108. }