chilloutzone.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. import re
  2. import base64
  3. import urllib
  4. import json
  5. from .common import InfoExtractor
  6. video_container = ('.mp4', '.mkv', '.flv')
  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. },
  17. }
  18. def _real_extract(self, url):
  19. mobj = re.match(self._VALID_URL, url)
  20. video_id = mobj.group('id')
  21. webpage_url = 'http://www.chilloutzone.net/video/' + video_id + '.html'
  22. # Log that we are starting to download the page
  23. self.report_download_webpage(webpage_url)
  24. webpage = self._download_webpage(webpage_url, video_id)
  25. # Log that we are starting to parse the page
  26. self.report_extraction(video_id)
  27. # Find base64 decoded file info
  28. base64_video_info = self._html_search_regex(r'var cozVidData = "(.+?)";', webpage, u'video Data')
  29. # decode string and find video file
  30. decoded_video_info = base64.b64decode(base64_video_info).decode("utf-8")
  31. video_info_dict = json.loads(decoded_video_info)
  32. # get video information from dict
  33. media_url = video_info_dict['mediaUrl']
  34. description = video_info_dict['description']
  35. title = video_info_dict['title']
  36. native_platform = video_info_dict['nativePlatform']
  37. native_video_id = video_info_dict['nativeVideoId']
  38. source_priority = video_info_dict['sourcePriority']
  39. # Start video extraction
  40. video_url = ''
  41. # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed)
  42. if native_platform == None:
  43. # Look for other video urls
  44. video_url = self._html_search_regex(r'<iframe.* src="(.+?)".*', webpage, u'fallback Video URL')
  45. if 'youtube' in video_url:
  46. self.to_screen(u'Youtube video detected:')
  47. return self.url_result(video_url, ie='Youtube')
  48. # For debugging purposes
  49. #print video_info_dict
  50. #print native_platform
  51. #print native_video_id
  52. #print source_priority
  53. #print media_url
  54. # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or
  55. # the own CDN
  56. if source_priority == 'native':
  57. if native_platform == 'youtube':
  58. self.to_screen(u'Youtube video detected:')
  59. video_url = 'https://www.youtube.com/watch?v=' + native_video_id
  60. return self.url_result(video_url, ie='Youtube')
  61. if native_platform == 'vimeo':
  62. self.to_screen(u'Vimeo video detected:')
  63. video_url = 'http://vimeo.com/' + native_video_id
  64. return self.url_result(video_url, ie='Vimeo')
  65. # No redirect, use coz media url
  66. video_url = media_url
  67. if video_url.endswith('.mp4') == False:
  68. self.report_warning(u'Url does not contain a video container')
  69. return []
  70. return [{
  71. 'id': video_id,
  72. 'url': video_url,
  73. 'ext': 'mp4',
  74. 'title': title,
  75. 'description': description,
  76. }]