chilloutzone.py 3.3 KB

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