def video_invalid_files(video_data, document_file): args_data = get_content_node_args(video_data) contentnode_kwargs = get_content_node_kwargs(video_data) contentnode_kwargs['files'] = [] # clear files becuse added one above video = VideoNode(*args_data, **contentnode_kwargs) video.add_file(document_file) return video
def construct_channel(self, *args, **kwargs): channel = self.get_channel(**kwargs) videos_topic = TopicNode(source_id="/wiki/Category:Articles_containing_video_clips", title="Articles containing video clips") channel.add_child(videos_topic) thumbnail_url = 'https://upload.wikimedia.org/wikipedia/commons/thumb/e/ee/A_Is_for_Atom_1953.webm/220px--A_Is_for_Atom_1953.webm.jpg' page = download_wikipedia_page('/wiki/Category:Articles_containing_video_clips', thumbnail_url, 'A Is for Atom') videos_topic.add_child(page) video_url = 'https://upload.wikimedia.org/wikipedia/commons/e/ee/A_Is_for_Atom_1953.webm' video_file = VideoFile(path=video_url) video_node = VideoNode(title='A Is for Atom 1953', source_id='A_Is_for_Atom_1953.webm', files=[video_file], license=licenses.PublicDomainLicense()) subtitle_url = 'https://commons.wikimedia.org/w/api.php?action=timedtext&title=File%3AA_Is_for_Atom_1953.webm&lang={}&trackformat=srt' subtitle_languages = [ 'en', 'es', ] for lang in subtitle_languages: subtitle_file = SubtitleFile(path=subtitle_url.format(lang), language=lang, subtitlesformat='srt') video_node.add_file(subtitle_file) videos_topic.add_child(video_node) return channel
def video(video_file, video_data, channel): args_data = get_content_node_args(video_data) contentnode_kwargs = get_content_node_kwargs(video_data) video = VideoNode(*args_data, **contentnode_kwargs) video.add_file(video_file) channel.add_child(video) video_data['files'].append(video_file) # save it so we can compare later return video
def test_invalid_mp4_fails(self, invalid_video_file): node = VideoNode('video-src-id', "Document", licenses.PUBLIC_DOMAIN, thumbnail=None) node.add_file(invalid_video_file) config.THUMBNAILS = True filenames = node.process_files()
def get_video_node(self, path, thumbnail=None): video_file = VideoFile(path, language='en') video_node = VideoNode('vid-src-id', "Video", licenses.PUBLIC_DOMAIN, thumbnail=thumbnail) video_node.add_file(video_file) return video_node
def test_generate_thumbnail_from_video(self, video_file): node = VideoNode('vid-src-id', "Video", licenses.PUBLIC_DOMAIN, thumbnail=None) node.add_file(video_file) config.THUMBNAILS = True filenames = node.process_files() assert len(filenames) == 2, 'expected two filenames' self.check_has_thumbnail(node)
def test_non_existent_mp4_fails(self): node = VideoNode('video-src-id', "Video", licenses.PUBLIC_DOMAIN, thumbnail=None) non_existent_path = 'does/not/exist.mp4' document_file = VideoFile(non_existent_path, language='en') node.add_file(document_file) config.THUMBNAILS = True filenames = node.process_files() assert filenames == [None], 'expected one None (the non existent mp4)' assert len(config.FAILED_FILES) == 1, 'expected one failed file'
def add_lesson_video(self, lesson, url, title, course_title, module_title): LOGGER.info("Adding video for the course {}...".format(lesson.title)) # resp = downloader.make_request(url, cookies=self.cookies).content.decode("utf-8") file_path = "files/{}/{}/{}/{}-video.txt".format( course_title, module_title, lesson.title, title) with open(file_path, "r") as resp: page = BeautifulSoup(resp, "html.parser") video_id = page.find( "div", {"youtube-api": "lesson.youtubeApi"})["video-id"] source_id = "{}-video".format(lesson.source_id) video_file = YouTubeVideoFile(youtube_id=video_id, high_resolution=True, language=CHANNEL_LANGUAGE) video_node = VideoNode( source_id=source_id, title=title, license=CC_BY_NC_SALicense( copyright_holder="Google Garage Digital"), language=CHANNEL_LANGUAGE, files=[video_file], ) # Add subtitles for the video info = ydl.extract_info(video_id, download=False) subtitle_languages = info["subtitles"].keys() for lang_code in subtitle_languages: if is_youtube_subtitle_file_supported_language(lang_code): video_node.add_file( YouTubeSubtitleFile(youtube_id=video_id, language=lang_code)) else: LOGGER.info('Unsupported subtitle language code:', lang_code) lesson.add_child(video_node)
def test_multiple_subs_can_be_added(video_file): """ Baseline check to make sure we're not dropping subtitle files on validate. """ assert os.path.exists("tests/testcontent/testsubtitles_ar.srt") video_node = VideoNode('vid-src-id', "Video", licenses.PUBLIC_DOMAIN) video_node.add_file(video_file) sub1 = SubtitleFile("tests/testcontent/testsubtitles_ar.srt", language='en') video_node.add_file(sub1) sub2 = SubtitleFile("tests/testcontent/testsubtitles_ar.srt", language='ar') video_node.add_file(sub2) video_node.validate() sub_files = [f for f in video_node.files if isinstance(f, SubtitleFile)] assert len(sub_files) == 2, 'Missing subtitles files!'
def test_duplicate_language_codes_fixed_by_validate(video_file): """ Video nodes should have at most one subtitle file for a particular lang code. """ assert os.path.exists("tests/testcontent/testsubtitles_ar.srt") video_node = VideoNode('vid-src-id', "Video", licenses.PUBLIC_DOMAIN) video_node.add_file(video_file) sub1 = SubtitleFile("tests/testcontent/testsubtitles_ar.srt", language='ar') video_node.add_file(sub1) # now let's add file with a duplicate language code... sub2 = SubtitleFile("tests/testcontent/testsubtitles_ar.srt", language='ar') video_node.add_file(sub2) video_node.validate() sub_files = [f for f in video_node.files if isinstance(f, SubtitleFile)] assert len(sub_files) == 1, 'Duplicate subtitles files not removed!'