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.

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