chilloutzone.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. from __future__ import unicode_literals
  2. import re
  3. import base64
  4. import json
  5. from .common import InfoExtractor
  6. from ..utils import (
  7. clean_html,
  8. ExtractorError
  9. )
  10. class ChilloutzoneIE(InfoExtractor):
  11. _VALID_URL = r'https?://(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+)\.html'
  12. _TEST = {
  13. 'url': 'http://www.chilloutzone.net/video/enemene-meck-alle-katzen-weg.html',
  14. 'md5': 'a76f3457e813ea0037e5244f509e66d1',
  15. 'info_dict': {
  16. 'id': 'enemene-meck-alle-katzen-weg',
  17. 'ext': 'mp4',
  18. 'title': 'Enemene Meck - Alle Katzen weg',
  19. 'description': 'Ist das der Umkehrschluss des Niesenden Panda-Babys?',
  20. },
  21. }
  22. def _real_extract(self, url):
  23. mobj = re.match(self._VALID_URL, url)
  24. video_id = mobj.group('id')
  25. webpage = self._download_webpage(url, video_id)
  26. base64_video_info = self._html_search_regex(
  27. r'var cozVidData = "(.+?)";', webpage, 'video data')
  28. decoded_video_info = base64.b64decode(base64_video_info).decode("utf-8")
  29. video_info_dict = json.loads(decoded_video_info)
  30. # get video information from dict
  31. video_url = video_info_dict['mediaUrl']
  32. description = clean_html(video_info_dict.get('description'))
  33. title = video_info_dict['title']
  34. native_platform = video_info_dict['nativePlatform']
  35. native_video_id = video_info_dict['nativeVideoId']
  36. source_priority = video_info_dict['sourcePriority']
  37. # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed)
  38. if native_platform is None:
  39. youtube_url = self._html_search_regex(
  40. r'<iframe.* src="((?:https?:)?//(?:[^.]+\.)?youtube\.com/.+?)"',
  41. webpage, 'fallback video URL', default=None)
  42. if youtube_url is not None:
  43. return self.url_result(youtube_url, ie='Youtube')
  44. # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or
  45. # the own CDN
  46. if source_priority == 'native':
  47. if native_platform == 'youtube':
  48. return self.url_result(video_id, ie='Youtube')
  49. if native_platform == 'vimeo':
  50. return self.url_result(
  51. 'http://vimeo.com/' + native_video_id, ie='Vimeo')
  52. if not video_url:
  53. raise ExtractorError('No video found')
  54. return {
  55. 'id': video_id,
  56. 'url': video_url,
  57. 'ext': 'mp4',
  58. 'title': title,
  59. 'description': description,
  60. }