Exemple #1
0
def audio_invalid_files(audio_data, document_file):
    args_data = get_content_node_args(audio_data)
    contentnode_kwargs = get_content_node_kwargs(audio_data)
    contentnode_kwargs['files'] = []  # clear files because added one above
    audio = AudioNode(*args_data, **contentnode_kwargs)
    audio.add_file(document_file)
    return audio
Exemple #2
0
 def test_invalid_mp3_fails(self, invalid_audio_file):
     node = AudioNode('audio-src-id',
                      "Document",
                      licenses.PUBLIC_DOMAIN,
                      thumbnail=None)
     node.add_file(invalid_audio_file)
     config.THUMBNAILS = True
     filenames = node.process_files()
Exemple #3
0
def audio(audio_file, audio_data, channel):
    args_data = get_content_node_args(audio_data)
    contentnode_kwargs = get_content_node_kwargs(audio_data)
    audio = AudioNode(*args_data, **contentnode_kwargs)
    audio.add_file(audio_file)
    channel.add_child(audio)
    audio_data['files'].append(audio_file)  # save it so we can compare later
    return audio
Exemple #4
0
 def test_generate_thumbnail_from_audio(self, audio_file):
     node = AudioNode('audio-src-id',
                      "Audio",
                      licenses.PUBLIC_DOMAIN,
                      thumbnail=None)
     node.add_file(audio_file)
     config.THUMBNAILS = True
     filenames = node.process_files()
     assert len(filenames) == 2, 'expected two filenames'
     self.check_has_thumbnail(node)
Exemple #5
0
 def test_non_existent_mp3_fails(self):
     node = AudioNode('audio-src-id',
                      "Document",
                      licenses.PUBLIC_DOMAIN,
                      thumbnail=None)
     non_existent_path = 'does/not/exist.mp3'
     document_file = AudioFile(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 mp3)'
     assert len(config.FAILED_FILES) == 1, 'expected one failed file'
Exemple #6
0
    def create_content_nodes(self, channel):
        """
        This function uses the methods `add_child` and `add_file` to build the
        hierarchy of topic nodes (nested folder structure) and content nodes.
        Every content node is associated with one or more files.
        """
        content_nodes_folder = TopicNode(
            source_id='uniqid001',
            title='Content Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        channel.add_child(content_nodes_folder)

        # AUDIO
        audio_nodes_folder = TopicNode(
            source_id='uniqid002',
            title='Audio Files Folder',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(audio_nodes_folder)

        audio_node = AudioNode(
            source_id='uniqid003',
            title='Whale sounds',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            files=[],
        )
        audio_nodes_folder.add_child(audio_node)
        audio_file = AudioFile(
            path=
            './content/ricecooker-channel-files/Whale_sounds.mp3',  # note path can also be a URL
            language=getlang('en').id)
        audio_node.add_file(audio_file)

        # DOCUMENTS
        documents_folder = TopicNode(
            source_id='uniqid004',
            title='Document Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(documents_folder)

        document_node = DocumentNode(
            source_id='uniqid005',
            title=
            'The Supreme Court\u2019s Ruling in Brown vs. Board of Education',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            files=[
                DocumentFile(
                    path=
                    './content/ricecooker-channel-files/brown-vs-board-of-education.pdf',
                    language=getlang('en').id)
            ])
        documents_folder.add_child(document_node)

        # HTML5 APPS
        html5apps_folder = TopicNode(
            source_id='uniqid006',
            title='HTML5App Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(html5apps_folder)

        html5_node = HTML5AppNode(
            source_id='uniqid007',
            title='HTMLWeb capabilities test',
            author='First Last (author\'s name)',
            description=
            'Tests different HTML/JS capabilities. What capabilities are allowed and disallowed by the sandboxed iframe used to render HTML5App nodes on Kolibri.',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail='./content/ricecooker-channel-files/html5_tests.jpg',
            files=[
                HTMLZipFile(
                    path='./content/ricecooker-channel-files/html5_tests.zip',
                    language=getlang('en').id)
            ])
        html5apps_folder.add_child(html5_node)

        html5_node2 = HTML5AppNode(
            source_id='uniqid008',
            title='Sample Vue.js app',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail='./content/ricecooker-channel-files/html5_vuejs.jpg',
            files=[
                HTMLZipFile(
                    path='./content/ricecooker-channel-files/html5_vuejs.zip',
                    language=getlang('en').id)
            ])
        html5apps_folder.add_child(html5_node2)

        # VIDEOS
        videos_folder = TopicNode(
            source_id='uniqid009',
            title='Video Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(videos_folder)
        video_node = VideoNode(
            source_id='uniqid010',
            title='Wave particle duality explained in 2 mins',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            derive_thumbnail=True,  # video-specicig flag
            thumbnail=None,
            files=[
                VideoFile(
                    path=
                    './content/ricecooker-channel-files/Wave_particle_duality.mp4',
                    language=getlang('en').id)
            ])
        videos_folder.add_child(video_node)

        youtube_id = 'VJyk81HmcZQ'
        video_node2 = VideoNode(
            source_id=youtube_id,  # usually set source_id to youtube_id
            title='Estimating division that results in non whole numbers',
            author='Sal Khan',
            description='Video description would go here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Khan Academy'),
            derive_thumbnail=True,  # video-specicig flag
            thumbnail=None,
            files=[
                YouTubeVideoFile(youtube_id=youtube_id,
                                 high_resolution=False,
                                 language='en'),
                YouTubeSubtitleFile(youtube_id=youtube_id, language='ko')
            ])
        videos_folder.add_child(video_node2)
    def create_content_nodes(self, channel):
        """
        This function uses the methods `add_child` and `add_file` to build the
        hierarchy of topic nodes and content nodes. Every content node is associated
        with the underlying file node.
        """
        content_nodes_folder = TopicNode(
            source_id='121232ms',
            title='Content Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        channel.add_child(content_nodes_folder)

        # AUDIO
        audio_nodes_folder = TopicNode(
            source_id='138iuh23iu',
            title='Audio Files',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(audio_nodes_folder)

        audio_node = AudioNode(
            source_id='940ac8ff',
            title='Whale sounds',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            files=[],
        )
        audio_nodes_folder.add_child(audio_node)
        audio_file = AudioFile(
            path='./content/ricecooker-channel-files/Whale_sounds.mp3',
            language=getlang('en').id)
        audio_node.add_file(audio_file)

        # DOCUMENTS
        documents_folder = TopicNode(
            source_id='asanlksnaklsn',
            title='Document Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(documents_folder)

        document_node = DocumentNode(
            source_id='80b7136f',
            title=
            'The Supreme Court\u2019s Ruling in Brown vs. Board of Education',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=None,
            files=[
                DocumentFile(
                    path=
                    './content/ricecooker-channel-files/commonlit_the-supreme-court-s-ruling-in-brown-vs-board-of-education_student.pdf',
                    language=getlang('en').id)
            ])
        documents_folder.add_child(document_node)

        # HTML5 APPS
        html5apps_folder = TopicNode(
            source_id='asasa331',
            title='HTML5App Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(html5apps_folder)

        html5_node_a = HTML5AppNode(
            source_id='302723b4',
            title='Sample React app',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail='./content/ricecooker-channel-files/html5_react.jpg',
            files=[
                HTMLZipFile(
                    path='./content/ricecooker-channel-files/html5_react.zip',
                    language=getlang('en').id)
            ])
        html5apps_folder.add_child(html5_node_a)

        html5_node_b = HTML5AppNode(
            source_id='3f91184e',
            title='Sample Vue.js app',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail='./content/ricecooker-channel-files/html5_vuejs.jpg',
            files=[
                HTMLZipFile(
                    path='./content/ricecooker-channel-files/html5_vuejs.zip',
                    language=getlang('en').id)
            ])
        html5apps_folder.add_child(html5_node_b)

        html5_node_c = HTML5AppNode(
            source_id='0aec4296',
            title='Sample wget-scraped web content',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            thumbnail=
            './content/ricecooker-channel-files/html5_wget_scraped.jpg',
            files=[
                HTMLZipFile(
                    path=
                    './content/ricecooker-channel-files/html5_wget_scraped.zip',
                    language=getlang('en').id)
            ])
        html5apps_folder.add_child(html5_node_c)

        # VIDEOS
        videos_folder = TopicNode(
            source_id='121213m3m3',
            title='Video Nodes',
            description='Put folder description here',
            author=None,
            language=getlang('en').id,
            thumbnail=None,
        )
        content_nodes_folder.add_child(videos_folder)
        video_node = VideoNode(
            source_id='9e355995',
            title='Wave particle duality explained in 2 mins',
            author='First Last (author\'s name)',
            description='Put file description here',
            language=getlang('en').id,
            license=get_license(licenses.CC_BY,
                                copyright_holder='Copyright holder name'),
            derive_thumbnail=True,  # video-specicig flag
            thumbnail=None,
            files=[
                VideoFile(
                    path=
                    './content/ricecooker-channel-files/Wave_particle_duality.mp4',
                    language=getlang('en').id)
            ])
        videos_folder.add_child(video_node)
Exemple #8
0
def make_random_subtree(parent, depth):
    for i in range(45):
        istr = str(i)
        title = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(10))
        description = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for _ in range(100))

        typ = random.choice("tttttttvadh")

        if typ == 't':
            topic = TopicNode(
                source_id=title + istr,
                title=title,
                description=description,
                author=None,
                language=getlang('en').id,
                thumbnail=None,
            )
            parent.add_child(topic)

            if depth > 0:
                make_random_subtree(topic, depth - 1)

        elif typ == 'a':

            content11a = AudioNode(
                source_id='940ac8ff' + istr,
                title='Whale sounds',
                author='First Last (author\'s name)',
                description='Put file description here',
                language=getlang('en').id,
                license=get_license(licenses.CC_BY,
                                    copyright_holder='Copyright holder name'),
                thumbnail=None,
                files=[],
            )
            parent.add_child(content11a)
            audio_file = AudioFile(
                path='./content/ricecooker-channel-files/Whale_sounds.mp3',
                language=getlang('en').id)
            content11a.add_file(audio_file)

        elif typ == 'd':

            content12a = DocumentNode(
                source_id='80b7136f' + istr,
                title=
                'The Supreme Court\u2019s Ruling in Brown vs. Board of Education',
                author='First Last (author\'s name)',
                description='Put file description here',
                language=getlang('en').id,
                license=get_license(licenses.CC_BY,
                                    copyright_holder='Copyright holder name'),
                thumbnail=None,
                files=[
                    DocumentFile(
                        path=
                        './content/ricecooker-channel-files/commonlit_the-supreme-court-s-ruling-in-brown-vs-board-of-education_student.pdf',
                        language=getlang('en').id)
                ])
            parent.add_child(content12a)

        elif typ == 'h':

            content13a = HTML5AppNode(
                source_id='302723b4' + istr,
                title='Sample React app',
                author='First Last (author\'s name)',
                description='Put file description here',
                language=getlang('en').id,
                license=get_license(licenses.CC_BY,
                                    copyright_holder='Copyright holder name'),
                thumbnail='./content/ricecooker-channel-files/html5_react.jpg',
                files=[
                    HTMLZipFile(
                        path=
                        './content/ricecooker-channel-files/html5_react.zip',
                        language=getlang('en').id)
                ])
            parent.add_child(content13a)

        elif type == 'v':

            content14a = VideoNode(
                source_id='9e355995',
                title='Wave particle duality explained in 2 mins',
                author='First Last (author\'s name)',
                description='Put file description here',
                language=getlang('en').id,
                license=get_license(licenses.CC_BY,
                                    copyright_holder='Copyright holder name'),
                derive_thumbnail=True,  # video-specicig flag
                thumbnail=None,
                files=[
                    VideoFile(
                        path=
                        './content/ricecooker-channel-files/Wave_particle_duality.mp4',
                        language=getlang('en').id)
                ])
            parent.add_child(content14a)