コード例 #1
0
 def __on_tag(self, bin, taglist):    
     ''' The playbin found the tag information'''
     if not self.song: return 
     if not self.song.get("title") and self.song.get_type() not in ["cue", "cdda", "webcast", "local"]:
         self.logdebug("tag found %s", taglist)
         IDS = {
             "title": "title",
             "genre": "genre",
             "artist": "artist",
             "album": "album",
             "bitrate": "#bitrate",
             'track-number':"#track"
         }
         mod = {}
         for key in taglist.keys():
             if IDS.has_key(key):
                 if key == "lenght":
                     value = int(taglist[key]) * 1000
                 elif key == "bitrate":    
                     value = int(taglist[key] / 100)
                 elif isinstance(taglist[key], long):
                     value = int(taglist[key])
                 else:    
                     value = fix_charset(taglist[key])
                 mod[IDS[key]] = value
         MediaDB.set_property(self.song, mod)        
コード例 #2
0
ファイル: song.py プロジェクト: yxsyxs/QMusic
        def message(bus, message, pipeline):
            if message.type == gst.MESSAGE_EOS:
                finalize(pipeline)
            elif message.type == gst.MESSAGE_TAG:
                taglist = message.parse_tag()
                for key in taglist.keys():
                    if GST_IDS.has_key(key):
                        if key == "bitrate":
                            value = int(taglist[key] / 100)
                        elif isinstance(taglist[key], long):
                            value = int(taglist[key])
                        else:
                            value = taglist[key]
                        self[GST_IDS[key]] = utils.fix_charset(value)
                        print key, ":", utils.fix_charset(value)

                is_tagged = True

            elif message.type == gst.MESSAGE_ERROR:
                err, debug = message.parse_error()
                finalize(pipeline)
                raise "W:Song:GstTag:Decoder error: %s%s" % (err, debug)
コード例 #3
0
 def message(bus, message, pipeline):        
     if message.type == gst.MESSAGE_EOS:
         finalize(pipeline)
     elif message.type == gst.MESSAGE_TAG:    
         taglist = message.parse_tag()
         for key in taglist.keys():
             if GST_IDS.has_key(key):
                 if key == "bitrate":
                     value = int(taglist[key] / 100)
                 elif isinstance(taglist[key], long):
                     value = int(taglist[key])
                 else:    
                     value = taglist[key]
                 self[GST_IDS[key]] = utils.fix_charset(value)
                 print key,":", utils.fix_charset(value)
                 
         is_tagged = True        
         
     elif message.type == gst.MESSAGE_ERROR:    
         err, debug = message.parse_error()
         finalize(pipeline)
         raise "W:Song:GstTag:Decoder error: %s\n%s" % (err,debug)
コード例 #4
0
ファイル: song.py プロジェクト: yxsyxs/QMusic
    def __read_from_local_file(self):
        try:
            path = self.get_path()
            self["#size"] = os.path.getsize(path)
            self["#mtime"] = os.path.getmtime(path)
            self["#ctime"] = os.path.getctime(path)

            audio = common.MutagenFile(self.get_path(), common.FORMATS)
            tag_keys_override = None

            if audio is not None:
                tag_keys_override = TAGS_KEYS_OVERRIDE.get(
                    audio.__class__.__name__, None)
                for file_tag, tag in TAG_KEYS.iteritems():
                    if tag_keys_override and tag_keys_override.has_key(
                            file_tag):
                        file_tag = tag_keys_override[file_tag]
                    if audio.has_key(file_tag) and audio[file_tag]:
                        value = audio[file_tag]
                        if isinstance(value, list) or isinstance(value, tuple):
                            value = value[0]
                        fix_value = utils.fix_charset(value)
                        if fix_value == "[Invalid Encoding]":
                            if tag == "title":
                                fix_value = self.get_filename()
                            else:
                                fix_value = ""
                        self[tag] = fix_value

                self["#duration"] = int(audio.info.length) * 1000
                try:
                    self["#bitrate"] = int(audio.info.bitrate)
                except AttributeError:
                    pass

            else:
                raise "W:Song:MutagenTag:No audio found"
            self.load_sort_object()
        except Exception, e:
            # print "W: Error while Loading (" + self.get_path() + ")Tracback :", e
            self.last_error = "Error while reading" + ":" + self.get_filename()
            return False
コード例 #5
0
    def __read_from_local_file(self):
        try:
            path = self.get_path()
            self["#size"]  = os.path.getsize(path)
            self["#mtime"] = os.path.getmtime(path)
            self["#ctime"] = os.path.getctime(path)
            
            audio = common.MutagenFile(self.get_path(), common.FORMATS)
            tag_keys_override = None

            if audio is not None:
                tag_keys_override = TAGS_KEYS_OVERRIDE.get(audio.__class__.__name__, None)
                for file_tag, tag in TAG_KEYS.iteritems():
                    if tag_keys_override and tag_keys_override.has_key(file_tag):
                        file_tag = tag_keys_override[file_tag]
                    if audio.has_key(file_tag) and audio[file_tag]:    
                        value = audio[file_tag]
                        if isinstance(value, list) or isinstance(value, tuple):
                            value = value[0]
                        fix_value = utils.fix_charset(value)    
                        if fix_value == "[Invalid Encoding]":
                            if tag == "title":
                                fix_value = self.get_filename()
                            else:    
                                fix_value = ""
                        self[tag] = fix_value
                            
                self["#duration"] = int(audio.info.length) * 1000        
                try:
                    self["#bitrate"] = int(audio.info.bitrate)
                except AttributeError: pass    
                
            
            else:    
                raise "W:Song:MutagenTag:No audio found"
            self.load_sort_object()    
        except Exception, e:    
            # print "W: Error while Loading (" + self.get_path() + ")\nTracback :", e
            self.last_error = "Error while reading" + ":" + self.get_filename()
            return False