# coding: utf-8
from __future__ import unicode_literals
from .common import InfoExtractor
import re
class BlenderCloudBaseIE(InfoExtractor):
# A video on the Blender Cloud site is referenced by a single alphanumeric node,
# i.e. '56041550044a2a00d0d7e068'
#
# The data we want for any given node ID can be fetched at:
url_node = "https://cloud.blender.org/nodes/%s/view"
# TODO: Add authentication scheme for subscriber-only videos.
#
# This will require the use of a (paid) Blender ID token available from:
# https://store.blender.org/product/membership/
#
# For now - ignore any subscriber-only videos and just grab the public ones.
def notify_for(self, node_id, notify_type):
notify_message = None
if notify_type == 'subscribers_only':
notify_message = 'Only available to Blender Cloud subscribers.'
elif notify_type == 'no_video_sources_available':
notify_message = 'No video sources available.'
else:
return None
self.report_warning('%s - %s' % (node_id, notify_message))
def get_node_title(self, source):
return self._html_search_regex(
r'
(.*?)
', source, 'title').strip()
def get_video_single(self, node_id, source):
video_title = None
video_formats = []
if self.is_video(source, 'subscribers_only'):
self.notify_for(node_id, 'subscribers_only')
else:
video_title = self.get_node_title(source)
video_formats = self.get_video_formats(source)
self._sort_formats(video_formats)
return video_title, video_formats
def get_video_playlist(self, display_id, source):
entries = []
for node_id in re.findall(r'data-node_id=\"([0-9a-z]+)\"\s*title=\"', source):
webpage_node = self._download_webpage(self.url_node % node_id, node_id)
if self.is_video(webpage_node, 'single'):
title, formats = self.get_video_single(node_id, webpage_node)
if title is not None:
entries.append({
'id': node_id,
'display_id': display_id,
'title': title,
'formats': formats,
})
else:
self.notify_for(node_id, 'no_video_sources_available')
return entries
@staticmethod
def is_video(source, check_for):
tag = None
if check_for == 'subscribers_only':
tag = 'Only available to Blender Cloud subscribers.'
elif check_for == 'single':
tag = ''
elif check_for == 'playlist':
tag = ''
else:
return False
return True if tag in source else False
@staticmethod
def get_video_formats(source):
video_formats = []
for video in re.findall(r'