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.

93 lines
3.4 KiB

  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. }]