Exemplo n.º 1
0
    def __init__(self, model, name=""):        
        self.model = model
        self.lst = None
        if type(name) is list:
            name = name[0]
        self.name = self.namebackup = name
        self.fav = True

        # just make sure the following function is properly initialized first
        # TODO it would be better to create a class or singleton 
        filenametoinfo("", CFG["regaudio"]["import filename exceptions"])
Exemplo n.º 2
0
    def readmp3(self):
        # iglob would not allow the following test if not gmp3
        gmp3 = glob.glob(os.path.join(self.dname, "*.mp3"))
        if not gmp3:
            return False 
        ordered = True # unless stated otherwise
        someordered = False # at least one number somewhere
        from lib.id3reader import Reader
        readervals = ["track", "performer","title"]#, "album"]
        dd = dict() # K: lcase filename V: track info
        for ff in sorted(gmp3):
            # read id3 
            id3 = Reader(ff)
            tt = [ id3.getValue(rv) for rv in readervals ] 
            # check trackno (first index)
            if tt[0] == None or tt[0] == 0 or tt[0].strip() == "" or tt[0] == None:
                # try parsing the filename
                tt = self.mergeid3fn(tt, filenametoinfo(ff))
                if tt[0] == 0 or tt[0].strip() == "" or tt[0] == None:
                    ordered = False
            else:
                someordered = True
            for e,t in enumerate(tt):
                if t == None:
                    tt[e] = ""                

            self.lst.append(tt)
            dd[os.path.basename(ff).strip().lower()] = tt
        if not ordered:
            # means that some tracks lack tracknumber (if not all)
            gm3u = sorted(glob.glob(os.path.join(self.dname, "*.m3u")))
            files = []
            if gm3u:
                # use the order in m3u to assign track no
                if len(gm3u) == 1: 
                    with open(gm3u[0], 'r') as fg: files=fg.readlines()
                else:          
                    readall = False
                    # if the
                    for i, m3u in enumerate(gm3u):
                        if not m3u[0] == chr(i):
                            readall = True
                    if readall: # readthem all then join them together
                        fll = []
                        for m3u in gm3u:
                            with open(m3u, 'r') as fg: 
                                fl = fg.readlines()
                                if not fl in fll: # duplicate m3u happens from time to time
                                    fll.append(fl)
                        for fl in fll:
                            files.extend(fl)
                    else: # just the first one
                        with open(gm3u[0], 'r') as fg: files=fg.readlines()
            else:
                # we could use some magic, but why bother
                # numbers by filename order
                for ii, kk in enumerate(sorted(dd.keys())):
                    dd[kk][0] = str(ii)
        return True
Exemplo n.º 3
0
 def readm4a(self):
     gm4a = glob.glob(os.path.join(self.dname, "*.m4a"))
     if not gm4a:
         return False 
     for ff in sorted(gm4a):
         # no library to read the tags: split by - (track no - artist - name)
         tt = filenametoinfo(ff, stripext=".m4a")
         self.lst.append(tt)
     return True