Esempio n. 1
0
    def __extractMetaData(self):

        self.filex = open(self.pathFile)
        self.flv = tags.FLV(self.filex)
        self.flv = self.flv.parse_header
        self.tags = tags.Tag(self.flv, self.filex)
        self.tags.parse_tag_content()
Esempio n. 2
0
    def test_errors(self):
        # file shorter than 3 bytes
        s = StringIO()
        f = tags.FLV(s)
        self.assertRaises(tags.MalformedFLV, f.read_tags)

        # header invalid
        s = StringIO('XLV\x00\x04\x00\x00\x00\x09\x00\x00\x00\x00')
        f = tags.FLV(s)
        self.assertRaises(tags.MalformedFLV, f.read_tags)

        # invalid tag type
        s = StringIO('FLV\x00\x05\x00\x00\x00\x09\x00\x00\x00\x00' + '\x01' +
                     self.tag_body('\x4b'))
        f = tags.FLV(s)
        self.assertRaises(tags.MalformedFLV, f.read_tags)
Esempio n. 3
0
    def test_simple_parse(self):
        s = StringIO('FLV\x00\x04\x00\x00\x00\x09\x00\x00\x00\x00')
        f = tags.FLV(s)
        f.parse_header()

        self.assertEquals(f.version, 0)
        self.assertEquals(f.has_audio, True)
        self.assertEquals(f.has_video, False)
Esempio n. 4
0
 def extractTags(self, filedata, onEdge=True,onMetaData=False):
     f = StringIO(filedata)
     flv = tags.FLV(f)
     try:
         tag_generator = flv.iter_tags()
         for i, tag in enumerate(tag_generator):
             if isinstance(tag, tags.ScriptTag):
                 if tag.name == "onEdge" and onEdge:
                     return tag.variable
                 elif tag.name == "onMetaData" and onMetaData:
                     return tag.variable
     except MalformedFLV, e:
         return False
Esempio n. 5
0
def debug_file(filename, quiet=False, metadata=False):
    try:
        f = open(filename, 'rb')
    except IOError as e:
        (errno, strerror) = e.args
        log.error("Failed to open `%s': %s", filename, strerror)
        return False

    flv = tags.FLV(f)

    if not quiet:
        print(("=== `%s' ===" % filename))

    try:
        tag_generator = flv.iter_tags()
        for i, tag in enumerate(tag_generator):
            if quiet:
                # If we're quiet, we just want to catch errors
                continue
            # Print the tag information
            print(("#%05d %s" % (i + 1, tag)))
            # Print the content of onMetaData tags
            if (isinstance(tag, tags.ScriptTag) and tag.name == "onMetaData"):
                helpers.pprint(tag.variable)
                if metadata:
                    return True
    except MalformedFLV as e:
        message = e.args[0] % e.args[1:]
        log.error("The file `%s' is not a valid FLV file: %s", filename,
                  message)
        return False
    except tags.EndOfFile:
        log.error("Unexpected end of file on file `%s'", filename)
        return False

    f.close()

    return True
Esempio n. 6
0
    def test_parse_tags(self):
        s = StringIO('FLV\x00\x05\x00\x00\x00\x09\x00\x00\x00\x00' + '\x08' +
                     self.tag_body('\x4b') + '\x08' + self.tag_body('\xbb') +
                     '\x09' + self.tag_body('\x17\x00') + '\x0f' +
                     ('\x00\x00\x17\x00\x00\x4d\x00\x00\x00\x00' +
                      '\x00\x02\x00\x0a\x73\x74\x72\x65\x61\x6d' +
                      '\x50\x69\x6e\x67\x00\x42\x74\x29\xa6\xff' +
                      '\x4b\x50\x00\x00\x00\x00\x22') + '\x12' +
                     ('\x00\x00\x07\x00\x26\x5f\x00\x00\x00\x00' +
                      '\x02\x00\x03\x66\x6f\x6f\x05\x00\x00\x00\x12'))
        f = tags.FLV(s)
        f.read_tags()

        self.assertEquals(f.version, 0)
        self.assertEquals(f.has_audio, True)
        self.assertEquals(f.has_video, True)

        self.assertEquals(len(f.tags), 5)
        self.assertTrue(isinstance(f.tags[0], tags.AudioTag))
        self.assertTrue(isinstance(f.tags[1], tags.AudioTag))
        self.assertTrue(isinstance(f.tags[2], tags.VideoTag))
        self.assertTrue(isinstance(f.tags[3], tags.ScriptAMF3Tag))
        self.assertTrue(isinstance(f.tags[4], tags.ScriptTag))
Esempio n. 7
0
def GetFLVProperties( path ):
    
    with open( path, 'rb' ) as f:
        
        flv = flv_tags.FLV( f )
        
        script_tag = None
        
        for tag in flv.iter_tags():
            
            if isinstance( tag, flv_tags.ScriptTag ):
                
                script_tag = tag
                
                break
                
            
        
        width = 853
        height = 480
        duration = 0
        num_frames = 0
        
        if script_tag is not None:
            
            tag_dict = script_tag.variable
            
            # tag_dict can sometimes be a float?
            # it is on the broken one I tried!
            
            if 'width' in tag_dict: width = tag_dict[ 'width' ]
            if 'height' in tag_dict: height = tag_dict[ 'height' ]
            if 'duration' in tag_dict: duration = int( tag_dict[ 'duration' ] * 1000 )
            if 'framerate' in tag_dict: num_frames = int( ( duration / 1000.0 ) * tag_dict[ 'framerate' ] )
            
        
        return ( ( width, height ), duration, num_frames )
Esempio n. 8
0
            raise NotImplementedError("no end")

    def tell(self):
        return self._i

def debug_file(filename, quiet=False, metadata=False):
    try:
        if filename.startswith('http://') or filename.startswith('https://'):
            f = HttpFile(urllib2.urlopen(filename))
        else:
            f = open(filename, 'rb')
    except IOError, (errno, strerror):
        log.error("Failed to open `%s': %s", filename, strerror)
        return []

    flv = tags.FLV(f)

    if not quiet:
        print "=== `%s' ===" % filename

    ret_tags = []
    ret_msg = []
    try:
        tag_generator = flv.iter_tags()
        for i, tag in enumerate(tag_generator):
            # Print the tag information
            # Print the content of onMetaData tags
            msg = ''
            if (isinstance(tag, tags.ScriptTag) and tag.name == "onMetaData"):
                if not quiet:
                    helpers.pprint(tag.variable)