コード例 #1
0
ファイル: flac.py プロジェクト: sffjunkie/media
    def read_ds(self, ds, doctype=None, **kwargs):
        only_metadata = kwargs.get('only_metadata', True)
        foreign_metadata = kwargs.get('foreign_metadata', False)

        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self.container = MediaContainer(FLAC_MIMETYPE)
            self._media_entry = MediaEntry()
            self.container.entries.append(self._media_entry)
    
            ds.seek(4, os.SEEK_SET)
            self._ds = ds

            last_metadata = 0
            while not last_metadata:
                last_metadata = self._read_block(foreign_metadata)
            
            if only_metadata:
                return
            
            self._media_entry.streams[0].data = self._ds.read(-1)
        else:
            raise MediaHandlerError("FlacHandler: Unable to handle stream")
コード例 #2
0
ファイル: jpeg.py プロジェクト: sffjunkie/media
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self._ds = ds
            self.container = MediaContainer()
            self._media_entry = MediaEntry()
            self._media_entry.container = self.container
            self.container.entries.append(self._media_entry)

            # skip the file magic as we've checked this in can_handle
            self._ds.seek(2, os.SEEK_SET)

            try:
                while True:
                    self._read_box('root')
            except StopIteration:
                pass
            except JPEGError as exc:
                if self.filename != '':
                    raise JPEGError('%s in file %s' %
                                    (exc.args[0], self.filename))
        else:
            raise MediaHandlerError("JPEGHandler: Unable to handle stream")
コード例 #3
0
ファイル: ebml.py プロジェクト: sffjunkie/media
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self._ds = ds
            self.container = MediaContainer('application/x-ebml')
            self._read_element('root')
            self.container.metadata['stream_size'] = self._ds.tell()
        else:
            raise MediaHandlerError("EBMLHandler: Unable to handle stream")
コード例 #4
0
ファイル: asf.py プロジェクト: sffjunkie/media
 def read(self, filename, doctype=None):
     with open(filename, 'rb') as ds:
         if doctype is None:
             doctype = self.can_handle(ds)
 
         if doctype is not None:
             try:
                 self.read_stream(ds)
             except EOFError:
                 pass
         else:
             raise MediaHandlerError("ASFHandler: Unable to handle file '%s'" % filename)
コード例 #5
0
ファイル: asf.py プロジェクト: sffjunkie/media
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self._ds = ds
            self.container = MediaContainer()
            self._media_entry = MediaEntry()
            self._media_entry.container = self.container
            self.container.entries.append(self._media_entry)
            
            self._read_element('root')
        else:
            raise MediaHandlerError("ASFHandler: Unable to handle stream")
コード例 #6
0
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self._ds = ds
            self.container = MediaContainer()
            self._media_entry = MediaEntry()
            self._media_entry.container = self.container
            self.container.entries.append(self._media_entry)

            self._ds.seek(4, os.SEEK_CUR)
            self.read_header()
        else:
            raise MediaHandlerError("PSDHandler: Unable to handle stream")
コード例 #7
0
ファイル: mp3.py プロジェクト: sffjunkie/media
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self.container = MediaContainer('audio/mp3')
            self._media_entry = MediaEntry()
            self.container.entries.append(self._media_entry)

            if doctype == 'ID3v1':
                self.handler = ID3v1TagHandler()
            else:
                self.handler = ID3v2TagHandler()

            self.handler.read_stream(ds)
        else:
            raise MediaHandlerError("MP3Handler: Unable to handle stream")
コード例 #8
0
ファイル: mp4.py プロジェクト: sffjunkie/media
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self._ds = ds

            size_read = 0
            try:
                while True:
                    size_read += self._read_box('root')
            except StopIteration:
                pass

            return size_read
        else:
            raise MediaHandlerError("MP4Handler: Unable to handle stream")
コード例 #9
0
ファイル: png.py プロジェクト: sffjunkie/media
    def read_stream(self, ds, doctype=None):
        if doctype is None:
            doctype = self.can_handle(ds)

        if doctype is not None:
            self._ds = ds
            self.container = MediaContainer()
            self._media_entry = MediaEntry()
            self._media_entry.container = self.container
            self.container.entries.append(self._media_entry)

            try:
                while True:
                    self._read_box('root')
            except StopIteration:
                self._combine_idat()
        else:
            raise MediaHandlerError("PNGHandler: Unable to handle stream")