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.

104 lines
3.3 KiB

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