chilloutzone.py 2.5 KB

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