Exemplo n.º 1
0
    def __init__(self, classDir=None, artistDir=None, albumDir=None, debug=False):
        self.debug = debug
        
        if not any([classDir, artistDir, albumDir]):
            raise ValueError("Must provide classDir, artistDir, or albumDir")
                
        self.mClass  = None
        self.mArtist = None
        self.mArtist = None
        self.mAlbum  = None
        self.mDisc   = None
        self.mFile   = None
        self.musicDir = None

        self.known = None
        if artistDir is not None:
            self.musicDir     = artistDir
            self.known        = "Artist"
            self.mArtist      = getDirBasics(artistDir)[-1]
            if debug:
                print("  Artist Path with {0} --> {1}".format(self.known, self.mArtist))
        elif albumDir is not None:
            self.musicDir     = albumDir
            self.known        = "Album"
            self.mAlbum       = getDirBasics(albumDir)[-1]
            self.mArtist      = getDirBasics(albumDir)[-2]
            if debug:
                print("  Album Path with {0} --> {1}".format(self.known, self.mAlbum))
        elif classDir is not None:
            self.musicDir     = classDir
            self.known        = "Class"
            self.mClass       = getDirBasics(classDir)[-1]
            if debug:
                print("  Class Path with {0} --> {1}".format(self.known, self.mClass))
Exemplo n.º 2
0
 def getMyUnmatchedAlbums(self, dirval, returnNames=False):    
     musicdata = myArtistAlbumData()
     musicdata.albums = [x for x in findDirs(dirval) if getDirBasics(x)[-1] not in self.myMusicDirs]
     for dname in musicdata.albums:
         self.updateFileCount(musicdata, dname)
     if returnNames is True:
         musicdata.albums = [getDirBasics(x)[-1] for x in musicdata.albums]
     return musicdata
Exemplo n.º 3
0
def actionOnAlbum(albumDir, artistDir, retval):

    if any([retval["Skip"], retval["Extra"]]):
        return

    ## Set Needed Directories
    todoDir = setDir(artistDir, "Todo", forceExist=False)
    multiDir = setDir(artistDir, "Multi", forceExist=False)
    titleDir = setDir(artistDir, "Title", forceExist=False)
    randomDir = setDir(artistDir, "Random", forceExist=False)
    mixDir = setDir(artistDir, "Mix", forceExist=False)

    testTitle = retval["Title"]
    testTitle = False
    testTrackNo = retval["Track"]
    testMulti = retval["Multi"]
    testMix = retval["Mix"]

    #print(testTitle,testTrackNo,testMulti)

    if testTitle is True:
        if not isDir(titleDir):
            mkDir(titleDir)
        srcdir = albumDir
        dstdir = setDir(titleDir, getDirBasics(albumDir)[-1])
        print("!!! Moving {0}  ==> {1}".format(srcdir, dstdir))
        sleep(1)
        moveDir(srcdir, dstdir)
    elif testMix is True:
        if not isDir(mixDir):
            mkDir(mixDir)
        srcdir = albumDir
        dstdir = setDir(mixDir, getDirBasics(albumDir)[-1])
        print("!!! Moving {0}  ==> {1}".format(srcdir, dstdir))
        sleep(1)
        moveDir(srcdir, dstdir)
    elif testTrackNo is True:
        if not isDir(todoDir):
            mkDir(todoDir)
        srcdir = albumDir
        dstdir = setDir(todoDir, getDirBasics(albumDir)[-1])
        print("!!! Moving {0}  ==> {1}".format(srcdir, dstdir))
        sleep(1)
        moveDir(srcdir, dstdir)
    elif testMulti is True:
        if not isDir(multiDir):
            mkDir(multiDir)
        srcdir = albumDir
        dstdir = setDir(multiDir, getDirBasics(albumDir)[-1])
        print("!!! Moving {0}  ==> {1}".format(srcdir, dstdir))
        sleep(1)
        moveDir(srcdir, dstdir)
Exemplo n.º 4
0
 def getMyUnknownMusicAlbums(self, dirval):
     musicdata = myArtistAlbumData()
     for dval in self.directoryMapping["Unknown"]:
         todoval = join(dirval, dval)
         for dname in glob(todoval):
             musicdata.albums += [getDirBasics(x)[-1] for x in findDirs(dname)]
             self.updateFileCount(musicdata, dname)
     return musicdata
Exemplo n.º 5
0
 def getMyMatchedMusicAlbums(self, dirval):
     musicdata = myArtistAlbumData()
     for matchDir in self.directoryMapping["Match"]:
         matchval = join(dirval, matchDir, "*")
         for dname in glob(matchval):
             musicdata.albums += [getDirBasics(x)[-1].split(" :: ")[0] for x in findDirs(dname)]
             self.updateFileCount(musicdata, dname)
     return musicdata
Exemplo n.º 6
0
def main(args):
    if args.dir is None:
        args.dir = getcwd()

        #retval = testAlbum(albumDir, artistDir, files=filevals)

    albumDirs = findDirs(args.dir)
    for albumDir in albumDirs:
        if getDirBasics(albumDir)[-1] != "Album":
            continue
        pb = pathBasics(albumDir=albumDir)
        files = pb.getFiles()
        print("\n")
        print("=" * 60)
        print("===", albumDir, "===")
        print("=" * 60)
        for subalbumDir, filevals in files.items():
            #print(subalbumDir,len(filevals))

            albumName = Counter()
            for ifile in filevals:
                results = MusicID(ifile, debug=args.debug)
                if results.skip is True:
                    continue
                tags = results.getInfo()
                albumVal = tags["Album"][0]
                albumName[albumVal] += 1

            if len(albumName) != 1:
                continue
            albumName = albumName.most_common(1)[0][0]
            albumName = albumName.replace("/", " ")
            srcDir = subalbumDir
            dstDir = setDir(albumDir, albumName)
            if isDir(dstDir):
                continue

            #print("Moving {0}  ==> {1}\n\n".format(srcDir, dstDir))
            print("\nmv \"{0}\" \"{1}\"\n".format(srcDir, dstDir))
Exemplo n.º 7
0
def testAlbum(albumDir, artistDir, files):

    retval = {
        "Track": False,
        "Album": False,
        "Title": False,
        "Multi": False,
        "Skip": False,
        "Extra": False,
        "Mix": False
    }

    artistName = getDirBasics(artistDir)[-1]
    if artistName in skipDirs():
        retval["Skip"] = True

    #print("artistDir",artistDir)
    #print("albumDir",albumDir)
    #print("artistName",artistName)

    albumName = albumDir.replace(artistDir, "")[1:]
    if "/" in albumName:
        retval["Extra"] = True
    albumDirs = albumName.split("/")
    if albumDirs[0] in skipDirs():
        retval["Skip"] = True
    if albumName in skipDirs():
        retval["Skip"] = True

    #print("albumName",albumName)

    j = 0
    tags = {}

    print("\t-----> Album Info: {0} / {1} \t ==> {2} Songs".format(
        artistName, albumName, len(files)))
    if retval["Extra"] is True:
        return retval
    if retval["Skip"] is True:
        return retval

    ifiles = []
    for jf, ifile in enumerate(files):
        results = MusicID(ifile, debug=args.debug)
        if results.skip is True:
            continue
        tags[j] = results.getInfo()
        ifiles.append(ifile)
        #pbcs[j] = pb.getPaths(ifile).getDict()
        j += 1
    nfiles = j

    ## Track Tests
    testTrackNo = True
    trackCheckSum = sum(range(1, nfiles + 1))
    trackTrackSum = 0

    ## Album Tests
    testAlbum = testCD(albumName) or testDisc(albumName)
    retval["Multi"] = testAlbum

    retval["Mix"] = testMix(albumName)

    ## Title Tests
    testTitle = True
    for j in range(nfiles):
        ifile = ifiles[j]
        tag = tags[j]
        #pbc = pbcs[j]

        ###############################################################################################
        ## Album Tests
        ###############################################################################################
        albumTag = tag.get("Album")
        if albumTag is None:
            print("Album Name Error ==> [{0}]".format("No Album Tag"))
            retval["Album"] = True
            break

        try:
            albumName = albumTag[0]
            albumName = albumName.replace("/", " ")
        except:
            print("Track Number Error ==> [{0}]".format("No Value"))
            trackNo = ""
        if len(albumName) == 0:
            retval["Album"] = True
            break

        dirvals = getDirBasics(getDirname(ifile))
        if albumName not in dirvals:
            retval["Album"] = True

        ###############################################################################################
        ## Track Number Tests
        ###############################################################################################
        trkTag = tag.get("TrackNo")
        if trkTag is None:
            print("Track Number Error ==> [{0}]".format("No TrackNo Tag"))
            retval["Track"] = True
            break

        try:
            trackNo = trkTag[0]
        except:
            print("Track Number Error ==> [{0}]".format("No Value"))
            trackNo = ""
        if len(trackNo) == 0:
            retval["Track"] = True
            break

        trackNumberValue = None
        try:
            trackNumberValue = int(trackNo)
        except:
            try:
                trackVals = [int(x) for x in trackNo.split("/")]
                trackNumberValue = trackVals[0]
            except:
                print("Track Number Error ==> [{0}]".format(trackNo))
        try:
            trackTrackSum += trackNumberValue
        except:
            pass

        ###############################################################################################
        ## Title Number Tests
        ###############################################################################################
        titleTag = tag.get("Title")
        if titleTag is None:
            print("Title Error ==> [{0}]".format("No Title Tag"))
            retval["Title"] = True
            break
        try:
            title = titleTag[0]
        except:
            print("Title Error ==> [{0}]".format(titleTag))
            testTitle = False
            break

        if testMix(title):
            print("Possible Mix ==> [{0}]".format(title))
            retval["Mix"] = True
            break

        fileName = getBaseFilename(ifile)
        if not any([title in fileName, fileName in title]):
            print("Title Error ==> [{0}] not [{1}]".format(title, fileName))
            retval["Title"] = True
            break

    if sum(retval.values()) == 0:
        if trackTrackSum != trackCheckSum:
            print("Problem with track numbering...")
            print("  Expected {0} and found {1}".format(
                trackCheckSum, trackTrackSum))
            retval["Track"] = True

    #print(retval)
    return retval
Exemplo n.º 8
0
def testArtist(artistDir):
    artistName = getDirBasics(artistDir)[-1]
    if artistName in skipDirs():
        return None
Exemplo n.º 9
0
def genMIDTags(albumDir, artistDir, files, args):

    retval = {
        "Track": False,
        "Album": False,
        "Title": False,
        "Multi": False,
        "Skip": False,
        "Extra": False,
        "Mix": False
    }

    artistName = getDirBasics(artistDir)[-1]
    albumName = albumDir.replace(artistDir, "")[1:]

    #print("albumName",albumName)

    j = 0
    tags = {}

    print("\t-----> Album Info: {0} / {1} \t ==> {2} Songs".format(
        artistName, albumName, len(files)))

    ifiles = []
    for jf, ifile in enumerate(files):
        results = MusicID(ifile, debug=args.debug)
        if results.skip is True:
            continue
        tags[j] = results.getInfo()
        ifiles.append(ifile)
        #pbcs[j] = pb.getPaths(ifile).getDict()
        j += 1
    nfiles = j

    fixVals = {}
    for j in range(nfiles):
        ifile = ifiles[j]
        tag = tags[j]

        trackname = getBaseFilename(ifile)

        newtags = {"TrackNo": None, "Title": None}

        tracks = guessTrackNumber(trackname)
        retval = getBestVal(tracks)
        if retval is not None:
            if retval.get('Val') is not None:
                newtags["TrackNo"] = retval["Val"]
                trackname = stripName(retval["Rep"])

        titles = guessTitle(trackname)
        retval = getBestVal(titles)
        if retval is not None:
            if retval.get('Val') is not None:
                newtags["Title"] = retval["Val"]
                trackname = stripName(retval["Rep"])

        #if tags[j]["TrackNo"] is None:
        if newtags["TrackNo"] is not None:
            if fixVals.get(ifile) is None:
                fixVals[ifile] = {}
            fixVals[ifile]["track"] = newtags["TrackNo"]

        #if tags[j]["Title"] is None:
        if args.ignoretitle is False:
            if newtags["Title"] is not None:
                if fixVals.get(ifile) is None:
                    fixVals[ifile] = {}
                fixVals[ifile]["title"] = newtags["Title"]

        if args.tryalbum:
            if fixVals.get(ifile) is None:
                fixVals[ifile] = {}
            fixVals[ifile]["album"] = albumName

    if len(fixVals) > 0:
        print("")

    for ifile in fixVals.keys():
        print("mid -f \"{0}\" ".format(ifile), end="")
        for tag, val in fixVals[ifile].items():
            print(" -{0} \"{1}\"".format(tag, val), end="")
        print("\n")

    if len(fixVals) > 0:
        print("")
Exemplo n.º 10
0
 def getMatchedPrimeAlbumDirs(self, primeDir, matchedDirs):
     dirvals     = getFlatList([findDirs(setDir(matchedDir, primeDir)) for matchedDir in matchedDirs])
     artistNames = [normalize('NFC', getDirBasics(dirval)[-1]) for dirval in dirvals]
     return list(zip(artistNames, dirvals))
Exemplo n.º 11
0
 def getVolumeName(self, baseDir):
     vals = getDirBasics(baseDir)
     return vals[2]