Esempio n. 1
0
    def get_metadata(video_file):
        """Parses file metadata

        Parsing is delegated to appropriate library based on filetype
        If filetype is unsupported default metadata is used instead

        Args:
            video_file: path to file

        Returns:
            Metadata formatted to Youtube APIs status parameter
        """
        metadata = {
            "title": os.path.basename(video_file).split(".")[0],
            "description": "A video recorded with Freeseer",
            "tags": ['Freeseer', 'FOSSLC', 'Open Source'],
            "categoryId": 27  # temporary, see gh#415
        }
        if video_file.lower().endswith('.ogg'):
            tags = oggvorbis.Open(video_file)
            if "title" in tags:
                metadata['title'] = tags['title'][0]
            if "album" in tags and "artist" in tags and "date" in tags:
                metadata['description'] = "At {} by {} recorded on {}".format(
                    tags['album'][0], tags['artist'][0], tags['date'][0])
        return metadata
Esempio n. 2
0
    def duration(self):
        """Return the duration of the sample.

        :rtype: float
        """
        if self._duration is not None:
            return self._duration

        with closing(SourceFile.open(self.relative_path, 'rb')) as f:
            if self.extension == 'ogg':
                value = oggvorbis.Open(f).info.length
            elif self.extension == 'mp3':
                value = mp3.Open(f).info.length
            elif self.extension == 'wav':
                with closing(wave.open(f)) as open_file:
                    value = open_file.getnframes() / open_file.getframerate()
            else:
                raise NotImplementedError(
                    'Sound extension "{extension}" is not supported.'.format(
                        extension=self.extension,
                    )
                )

        self._duration = value
        return value