示例#1
0
    def moveMyMatchedMusicAlbums(self, show=False):
        rename = True
        albumsToMove = getFile(ifile=self.moveFilename)
        print("Found {0} music <-> discogs albums maps".format(
            len(albumsToMove)))

        for db, dbValues in albumsToMove.items():
            if dbValues is None:
                continue
            for artistName, artistAlbums in dbValues.items():
                print("==>", artistName)
                for myAlbumName, albumVals in artistAlbums.items():
                    dirval = albumVals["Dir"]
                    albumVal = albumVals["Album"]
                    ratio = albumVals["Ratio"]

                    dbAlbumName = albumVal["Name"]
                    dbAlbumCode = albumVal["Code"]
                    mediaType = albumVal["MediaType"]

                    matchedDir = setDir(dirval, "Match")
                    mkDir(matchedDir)

                    srcName = myAlbumName
                    srcDir = setDir(dirval, srcName)
                    if not isDir(srcDir):
                        print("{0} does not exist".format(srcDir))
                        continue

                    mediaDir = setDir(matchedDir, self.discConv(mediaType))
                    mkDir(mediaDir)

                    if rename is True:
                        dstName = self.getMatchedDirName(
                            self.discConv(dbAlbumName), dbAlbumCode, db)
                    else:
                        dstName = self.getMatchedDirName(
                            myAlbumName, dbAlbumCode, db)

                    if show is True:
                        print('\t{0}'.format(mediaDir))
                        print("\t\t[{0}]".format(srcName))
                        print("\t\t[{0}]".format(dstName))
                        continue

                    dstDir = setDir(mediaDir, dstName)
                    if isDir(dstDir):
                        print("{0} already exists".format(dstDir))
                        continue

                    print("\tMoving {0}  --->  {1}".format(srcDir, dstDir))
                    moveDir(srcDir, dstDir, debug=True)
示例#2
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)
示例#3
0
文件: dbBase.py 项目: tgadf/dbdata
 def moveAlbumFilesToNewModValue(self, newModValue, oldModValue):
     filedir = self.getAlbumsDir()
     dutils = discogsUtils()
     for modVal in range(oldModValue):
         modValue = dutils.getDiscIDHashMod(
             discID=modVal, modval=newModValue)  #disc.getMaxModVal())
         if modVal == modValue:
             sleep(1)
             continue
         else:
             dirs = glob(join(filedir, str(modVal), "*"))
             print("Moving {0} directories from {1} to {2}".format(
                 len(dirs), modVal, modValue))
             for idir in dirs:
                 dname = getDirname(idir)
                 src = idir
                 dst = join(filedir, str(modValue), dname)
                 print(src)
                 print(dst)
                 1 / 0
                 moveDir(src, dst)
示例#4
0
def main(args):
    
    ########################
    ## Sep
    ######################## 
    if args.sep is not None:
        sep  = args.sep
        print("Delimiter = [{0}]".format(sep))

        if args.files is not None:
            print("Fixing Files not Directories")
            
            for fname in findPattern("./", pattern=args.files):
                fname = fname[2:]
                vals = fname.split(sep)
                if len(vals) >= 2:
                    newName = sep.join(vals[1:])
                    if isFile(fname):
                        if not isFile(newName):
                            moveFile(fname, newName, debug=True)
                        else:
                            print("Cannot move [{0}]".format(fname))
                    else:
                        print("Not moving [{0}] to [{1}]".format(fname, newName))
        else:
            for dname in findDirs("./"):
                dname = dname[2:]
                vals = dname.split(sep)
                if len(vals) >= 2:
                    newName = sep.join(vals[1:])
                    if isDir(dname):
                        if not isDir(newName):
                            moveDir(dname, newName, debug=True)
                        else:
                            print("Cannot move [{0}]".format(dname))
                    else:
                        print("Not moving [{0}] to [{1}]".format(dname, newName))


    ########################
    ## Remove/Replace
    ######################## 
    if args.remove is not None or args.replace is not None:
        print("Remove  = [{0}]".format(args.remove))
        print("Replace = [{0}]".format(args.replace))
        if args.files is not None:
            print("Fixing Files not Directories")
            for fname in findPattern("./", pattern=args.files):
                fname = fname[2:]
                if args.replace is not None:
                    newName = fname.replace(args.remove, args.replace)
                else:
                    newName = fname.replace(args.remove, "")
                if isFile(fname):
                    if not isFile(newName):
                        moveFile(fname, newName, debug=True)
                    else:
                        print("Cannot move [{0}]".format(fname))
                else:
                    print("Not moving [{0}] to [{1}]".format(fname, newName))
        else:
            for dname in findDirs("./"):
                dname = dname[2:]
                if args.replace is not None:
                    newName = dname.replace(args.remove, args.replace)
                else:
                    newName = dname.replace(args.remove, "")                    
                if isDir(dname):
                    if not isDir(newName):
                        moveDir(dname, newName, debug=True)
                    else:
                        print("Cannot move [{0}]".format(dname))
                else:
                    print("Not moving [{0}] to [{1}]".format(dname, newName))
                             

    ########################
    ## Add
    ######################## 
    if args.add is not None:
        print("Add = [{0}]".format(args.add))
        if args.files is not None:
            print("Fixing Files not Directories")
            for fname in findPattern("./", pattern=args.files):
                fname = fname[2:]
                fname = "{0} {1}".format(fname, args.add)
                if isFile(fname):
                    if not isFile(newName):
                        moveFile(fname, newName, debug=True)
                    else:
                        print("Cannot move [{0}]".format(fname))
                else:
                    print("Not moving [{0}] to [{1}]".format(fname, newName))
        else:
            for dname in findDirs("./"):
                dname = dname[2:]
                newName = "{0} {1}".format(dname, args.add)
                if isDir(dname):
                    if not isDir(newName):
                        moveDir(dname, newName, debug=True)
                    else:
                        print("Cannot move [{0}]".format(dname))
                else:
                    print("Not moving [{0}] to [{1}]".format(dname, newName))
示例#5
0
def main(args):
    args = addDefault(args)

    print('Artist      = {!r}'.format(args.artist))
    print('Album       = {!r}'.format(args.album))
    print('Class       = {!r}'.format(args.cls))
    print('Dir         = {!r}'.format(args.dir))

    if args.artist is True:
        pb = pathBasics(artistDir=args.dir)
    elif args.album is True:
        pb = pathBasics(albumDir=args.dir)
    elif args.cls is True:
        pb = pathBasics(classDir=args.dir)
    else:
        raise ValueError("Can only run with -artist, -album, or -class!")

    actions = {}

    files = pb.getFiles()
    for i, (dirval, filevals) in enumerate(files.items()):
        print("\nDirectory: {0}".format(dirval))
        header()
        j = 0

        errs = {}
        for jf, ifile in enumerate(filevals):
            results = MusicID(ifile, debug=args.debug)
            if results.skip is True:
                continue
            tags = results.getInfo()
            r = tags
            pbc = pb.getPaths(ifile).getDict()
            errs[ifile] = {}
            j += 1

            p([
                j, r["DiscNo"], r["TrackNo"], r["AlbumArtist"], r["Artist"],
                r["Album"], r["Title"], r["Size"]
            ])
            if args.showpath is True:
                p([
                    j, pbc["pbDisc"], None, pbc["pbArtist"], pbc["pbArtist"],
                    pbc["pbAlbum"], pbc["pbFile"], None
                ])

            #print(pbc)

            if r["AlbumArtist"][0] == pbc["pbArtist"]:
                pass
            else:
                if pbc["pbAlbum"] in skipDirs():
                    pass
                elif tags["AlbumArtist"][0].replace("/",
                                                    "-") == pbc["pbArtist"]:
                    pass
                else:
                    errs[ifile]["Artist"] = {
                        "Tag": r["Artist"][0],
                        "Path": pbc["pbArtist"]
                    }

            if r["Album"][0] == pbc["pbAlbum"]:
                pass
            else:
                if pbc["pbAlbum"] in skipDirs():
                    pass
                else:
                    errs[ifile]["Album"] = {
                        "Tag": r["Album"][0],
                        "Path": pbc["pbAlbum"]
                    }

        if args.force is not None:
            for ifile, fileData in errs.items():
                if actions.get(dirval) is not None:
                    continue
                if not isFile(ifile):
                    continue
                for category, errData in fileData.items():
                    if args.force.title() == category:
                        print("Mismatch: {0}".format(args.force.title()))
                        print("File:     {0}".format(ifile))
                        print("Tag:      [{0}]".format(errData["Tag"]))
                        print("Path:     [{0}]".format(errData["Path"]))
                        if args.usetag is True:
                            srcdir = dirval
                            if "/" in errData["Tag"]:
                                print("Found / in Tag. Converting to -")
                                errData["Tag"] = errData["Tag"].replace(
                                    "/", "-")
                            if "\"" in errData["Tag"]:
                                print("Found \" in Tag. Converting to -")
                                errData["Tag"] = errData["Tag"].replace(
                                    "\"", "")

                            dstdir = setDir(getDirname(dirval), errData["Tag"])
                            print(
                                "Set option to move directory based on the {0} tag"
                                .format(category))
                            print("Moving {0}".format(srcdir))
                            if isDir(dstdir):
                                print("=" * 40)
                                print(
                                    "== Not moving because there is already a directory with that name..."
                                )
                                print("=" * 40)
                                break

                            print("    to {0}".format(dstdir))
                            if "/" in errData["Path"]:
                                print("=" * 40)
                                print(
                                    "== Not moving because there is a sub directory..."
                                )
                                print("=" * 40)
                                break

                            if args.script is False:
                                print("Sleeping for 3 seconds")
                                for i in range(3):
                                    print(".", end="")
                                    sys.stdout.flush()
                                    sleep(1)
                                print("\n")
                                moveDir(srcdir, dstdir)
                                break
                            else:
                                actions[srcdir] = dstdir
                                break
                        else:
                            return

    if args.script is False:
        print("\n", "=" * 60, "\n")
        print("Looks Good")
        print("\n\n")
    else:
        if len(actions) > 0:
            print("#!/bin/sh\n", file=open("actions.sh", "w"))
            for srcdir, dstdir in actions.items():
                print("mv \"{0}\" \"{1}\"".format(srcdir, dstdir),
                      file=open("actions.sh", "a"))
            from os import chmod
            import stat
            chmod("actions.sh", stat.S_IRWXU)
        print("\n", "=" * 60, "\n")
        print("Looks Good")
        print("\n\n")