def findMyMusic(self, primeDir=None, artistName=None): artistAlbums = {} if primeDir is None and artistName is None: ts = timestat("Find PrimeDir Artist Paths") pdPaths = { pd: pdpath for pd, pdpath in {pd: setDir(self.musicDir, pd) for pd in self.pdDirs}.items() if dirUtil(pdpath).isDir() } pdArtistPaths = { pd: findDirs(pdpath) for pd, pdpath in pdPaths.items() } artistPaths = { fsap.name: fsap.path for fsap in [dirUtil(ap) for ap in getFlatList(pdArtistPaths.values())] } artistAlbums = { artistName: self.getArtistPathData(artistName, artistPath) for artistName, artistPath in artistPaths.items() } print(" Found {0} Artists From {1} Prime Directories".format( len(artistAlbums), len(pdArtistPaths))) ts.stop() elif primeDir is not None: ts = timestat( "Finding All Artist Albums From [{0}] Prime Directory".format( primeDir)) pdPaths = { pd: pdpath for pd, pdpath in {pd: setDir(self.musicDir, pd) for pd in [primeDir]}.items() if dirUtil(pdpath).isDir() } pdArtistPaths = { pd: findDirs(pdpath) for pd, pdpath in pdPaths.items() } artistPaths = { fsap.name: fsap.path for fsap in [dirUtil(ap) for ap in getFlatList(pdArtistPaths.values())] } artistAlbums = { artistName: self.getArtistPathData(artistName, artistPath) for artistName, artistPath in artistPaths.items() } print(" Found {0} Artists From [{1}] Prime Directory".format( len(artistAlbums), primeDir)) ts.stop() elif artistName is not None: ts = timestat("Finding [{0}] Artist Albums".format(artistName)) artistAlbums = self.getArtistPathData(artistName) ts.stop() self.artistAlbums = artistAlbums return artistAlbums
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
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
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
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.album is True: pb = pathBasics(albumDir=args.dir) files = pb.getFiles() artistDir = getDirname(args.dir) for albumDir, filevals in files.items(): retval = testAlbum(albumDir, artistDir, files=filevals) actionOnAlbum(albumDir, artistDir, retval) #print(retval) if args.artist is True: artistDir = args.dir pb = pathBasics(artistDir=artistDir) files = pb.getFiles() print("\n") print("=" * 60) print("===", artistDir, "===") print("=" * 60) for albumDir, filevals in files.items(): retval = testAlbum(albumDir, artistDir, files=filevals) actionOnAlbum(albumDir, artistDir, retval) #print(retval) if args.cls is True: artistDirs = findDirs(args.dir) for artistDir in artistDirs: pb = pathBasics(artistDir=artistDir) files = pb.getFiles() print("\n") print("=" * 60) print("===", artistDir, "===") print("=" * 60) for albumDir, filevals in files.items(): retval = testAlbum(albumDir, artistDir, files=filevals) actionOnAlbum(albumDir, artistDir, retval)
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))
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))
def getMyOtherMusicAlbums(self, dirval, mname): return getFlatList([[p for p in findDirs(setDir(dirval, mdirval))] for mdirval in self.mdirmap.getMapping(mname)])
def getMyUnmatchedMusicAlbums(self, dirval): return [ x for x in findDirs(dirval) if dirUtil(x).name not in self.mdirmap.getMappingDirs() ]
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))