logo

youtube-dl

[mirror] Download/Watch videos from video hostersgit clone https://hacktivis.me/git/mirror/youtube-dl.git

chilloutzone.py (3501B)


  1. from __future__ import unicode_literals
  2. import re
  3. import json
  4. from .common import InfoExtractor
  5. from .youtube import YoutubeIE
  6. from ..compat import compat_b64decode
  7. from ..utils import (
  8. clean_html,
  9. ExtractorError
  10. )
  11. class ChilloutzoneIE(InfoExtractor):
  12. _VALID_URL = r'https?://(?:www\.)?chilloutzone\.net/video/(?P<id>[\w|-]+)\.html'
  13. _TESTS = [{
  14. 'url': 'http://www.chilloutzone.net/video/enemene-meck-alle-katzen-weg.html',
  15. 'md5': 'a76f3457e813ea0037e5244f509e66d1',
  16. 'info_dict': {
  17. 'id': 'enemene-meck-alle-katzen-weg',
  18. 'ext': 'mp4',
  19. 'title': 'Enemene Meck - Alle Katzen weg',
  20. 'description': 'Ist das der Umkehrschluss des Niesenden Panda-Babys?',
  21. },
  22. }, {
  23. 'note': 'Video hosted at YouTube',
  24. 'url': 'http://www.chilloutzone.net/video/eine-sekunde-bevor.html',
  25. 'info_dict': {
  26. 'id': '1YVQaAgHyRU',
  27. 'ext': 'mp4',
  28. 'title': '16 Photos Taken 1 Second Before Disaster',
  29. 'description': 'md5:58a8fcf6a459fe0a08f54140f0ad1814',
  30. 'uploader': 'BuzzFeedVideo',
  31. 'uploader_id': 'BuzzFeedVideo',
  32. 'upload_date': '20131105',
  33. },
  34. }, {
  35. 'note': 'Video hosted at Vimeo',
  36. 'url': 'http://www.chilloutzone.net/video/icon-blending.html',
  37. 'md5': '2645c678b8dc4fefcc0e1b60db18dac1',
  38. 'info_dict': {
  39. 'id': '85523671',
  40. 'ext': 'mp4',
  41. 'title': 'The Sunday Times - Icons',
  42. 'description': 're:(?s)^Watch the making of - makingoficons.com.{300,}',
  43. 'uploader': 'Us',
  44. 'uploader_id': 'usfilms',
  45. 'upload_date': '20140131'
  46. },
  47. }]
  48. def _real_extract(self, url):
  49. mobj = re.match(self._VALID_URL, url)
  50. video_id = mobj.group('id')
  51. webpage = self._download_webpage(url, video_id)
  52. base64_video_info = self._html_search_regex(
  53. r'var cozVidData = "(.+?)";', webpage, 'video data')
  54. decoded_video_info = compat_b64decode(base64_video_info).decode('utf-8')
  55. video_info_dict = json.loads(decoded_video_info)
  56. # get video information from dict
  57. video_url = video_info_dict['mediaUrl']
  58. description = clean_html(video_info_dict.get('description'))
  59. title = video_info_dict['title']
  60. native_platform = video_info_dict['nativePlatform']
  61. native_video_id = video_info_dict['nativeVideoId']
  62. source_priority = video_info_dict['sourcePriority']
  63. # If nativePlatform is None a fallback mechanism is used (i.e. youtube embed)
  64. if native_platform is None:
  65. youtube_url = YoutubeIE._extract_url(webpage)
  66. if youtube_url:
  67. return self.url_result(youtube_url, ie=YoutubeIE.ie_key())
  68. # Non Fallback: Decide to use native source (e.g. youtube or vimeo) or
  69. # the own CDN
  70. if source_priority == 'native':
  71. if native_platform == 'youtube':
  72. return self.url_result(native_video_id, ie='Youtube')
  73. if native_platform == 'vimeo':
  74. return self.url_result(
  75. 'http://vimeo.com/' + native_video_id, ie='Vimeo')
  76. if not video_url:
  77. raise ExtractorError('No video found')
  78. return {
  79. 'id': video_id,
  80. 'url': video_url,
  81. 'ext': 'mp4',
  82. 'title': title,
  83. 'description': description,
  84. }