def add_files(node, file_list): for f in file_list: path = f.get('path') if path is not None: abspath = get_abspath(path) # NEW: expand content:// --> ./content/ in file paths else: abspath = None file_type = guess_file_type(node.kind, filepath=abspath, youtube_id=f.get('youtube_id'), web_url=f.get('web_url'), encoding=f.get('encoding')) if file_type == FileTypes.AUDIO_FILE: node.add_file(files.AudioFile(path=abspath, language=f.get('language'))) elif file_type == FileTypes.THUMBNAIL: node.add_file(files.ThumbnailFile(path=abspath)) elif file_type == FileTypes.DOCUMENT_FILE: node.add_file(files.DocumentFile(path=abspath, language=f.get('language'))) elif file_type == FileTypes.HTML_ZIP_FILE: node.add_file(files.HTMLZipFile(path=abspath, language=f.get('language'))) elif file_type == FileTypes.VIDEO_FILE: node.add_file(files.VideoFile(path=abspath, language=f.get('language'), ffmpeg_settings=f.get('ffmpeg_settings'))) elif file_type == FileTypes.SUBTITLE_FILE: node.add_file(files.SubtitleFile(path=abspath, language=f['language'])) elif file_type == FileTypes.BASE64_FILE: node.add_file(files.Base64ImageFile(encoding=f['encoding'])) elif file_type == FileTypes.WEB_VIDEO_FILE: node.add_file(files.WebVideoFile(web_url=f['web_url'], high_resolution=f.get('high_resolution'))) elif file_type == FileTypes.YOUTUBE_VIDEO_FILE: node.add_file(files.YouTubeVideoFile(youtube_id=f['youtube_id'], high_resolution=f.get('high_resolution'))) node.add_file(files.YouTubeSubtitleFile(youtube_id=f['youtube_id'], language='en')) else: raise UnknownFileTypeError("Unrecognized file type '{0}'".format(f['path']))
def make_content_node(kind, source_id, title, license, filepath, optionals): """ Create `kind` subclass of ContentNode based on required args and optionals. """ content_node = None if kind == content_kinds.VIDEO: content_node = nodes.VideoNode( source_id=source_id, title=title, license=license, author=optionals.get("author", None), description=optionals.get("description", None), derive_thumbnail=True, # video-specific data files=[files.VideoFile(path=filepath)], ) elif kind == content_kinds.AUDIO: content_node = nodes.AudioNode( source_id=source_id, title=title, license=license, author=optionals.get("author", None), description=optionals.get("description", None), thumbnail=optionals.get("thumbnail", None), files=[files.AudioFile(path=filepath)], ) elif kind == content_kinds.DOCUMENT: content_node = nodes.DocumentNode( source_id=source_id, title=title, license=license, author=optionals.get("author", None), description=optionals.get("description", None), thumbnail=optionals.get("thumbnail", None), files=[files.DocumentFile(path=filepath)], ) return content_node
def add_files(node, file_list): for f in file_list: file_name, file_type = parse_file_name(f) print (f) if file_type == 'mp3':#FileTypes.AUDIO_FILE: node.add_file(files.AudioFile(path=f)) #elif file_type == FileTypes.THUMBNAIL: # node.add_file(files.ThumbnailFile(path=f['path'])) elif file_type == 'pdf':#FileTypes.DOCUMENT_FILE: node.add_file(files.DocumentFile(path=f)) #elif file_type == FileTypes.HTML_ZIP_FILE: # node.add_file(files.HTMLZipFile(path=f['path'], language=f.get('language'))) elif file_type == 'mp4':#FileTypes.VIDEO_FILE: node.add_file(files.VideoFile(path=f)) #elif file_type == FileTypes.SUBTITLE_FILE: # node.add_file(files.SubtitleFile(path=f['path'], language=f['language'])) #elif file_type == FileTypes.BASE64_FILE: # node.add_file(files.Base64ImageFile(encoding=f['encoding'])) #elif file_type == FileTypes.WEB_VIDEO_FILE: # node.add_file(files.WebVideoFile(web_url=f['web_url'], high_resolution=f.get('high_resolution'))) #elif file_type == FileTypes.YOUTUBE_VIDEO_FILE: # node.add_file(files.YouTubeVideoFile(youtube_id=f['youtube_id'], high_resolution=f.get('high_resolution'))) else: raise UnknownFileTypeError("Unrecognised file type '{0}'".format(f['path']))
def add_files(node, file_list): EXPECTED_FILE_TYPES = [ VIDEO_FILE, AUDIO_FILE, DOCUMENT_FILE, HTML5_FILE, THUMBNAIL_FILE, SUBTITLES_FILE ] for f in file_list: file_type = f.get('file_type') if file_type not in EXPECTED_FILE_TYPES: LOGGER.critical(file_type) raise NotImplementedError( 'Unexpected File type found in channel json.') path = f.get('path') # path can be an URL or a local path (or None) # handle different types of files if file_type == VIDEO_FILE: # handle three types of video files if 'youtube_id' in f: video_file = files.YouTubeVideoFile( youtube_id=f['youtube_id'], download_settings=f.get('download_settings', None), high_resolution=f.get('high_resolution', True), maxheight=f.get('maxheight', None), language=f.get('language', None), ) elif 'web_url' in f: video_file = files.WebVideoFile( web_url=f['web_url'], download_settings=f.get('download_settings', None), high_resolution=f.get('high_resolution', True), maxheight=f.get('maxheight', None), language=f.get('language', None), ) else: video_file = files.VideoFile( path=f['path'], language=f.get('language', None), ffmpeg_settings=f.get('ffmpeg_settings'), ) node.add_file(video_file) elif file_type == AUDIO_FILE: node.add_file( files.AudioFile(path=f['path'], language=f.get('language', None))) elif file_type == DOCUMENT_FILE: node.add_file( files.DocumentFile(path=path, language=f.get('language', None))) elif file_type == HTML5_FILE: node.add_file( files.HTMLZipFile(path=path, language=f.get('language', None))) elif file_type == THUMBNAIL_FILE: if 'encoding' in f: node.add_file(files.Base64ImageFile(encoding=f['encoding'], )) else: node.add_file( files.ThumbnailFile( path=path, language=f.get('language', None), )) elif file_type == SUBTITLES_FILE: if 'youtube_id' in f: node.add_file( files.YouTubeSubtitleFile(youtube_id=f['youtube_id'], language=f['language'])) else: node.add_file( files.SubtitleFile(path=path, language=f['language'])) else: raise UnknownFileTypeError("Unrecognized file type '{0}'".format( f['path']))