def main(args): files = findExt(getcwd(), ext=".mp3") for ifile in files: fname = getBasename(ifile) dname = getDirname(ifile) fname = fname.replace(args.remove, "").strip() dst = join(dname, fname) if ifile != dst: moveFile(ifile, dst, debug=True)
def suggestRenames(self): movies = glob("/Volumes/Download/MoviesFinished/*.*") for movie in movies: fileInfo = getFileBasics(movie) name = fileInfo[1] ps=["1080", "720", "480"] for p in ps: name = name.replace("{0}p".format(p), "") xs=['264'] for x in xs: name = name.replace("x{0}".format(x), "") ts=["BluRay", "BRrip", "WEBRip", "HDTVRip", "GAZ", "BrRip"] for t in ts: name = name.replace("{0}".format(t), "") vs=["-[YTS.AG]", "-[YTS.AM]", "YIFY", "[YTS.AG]"] for v in vs: name = name.replace("{0}".format(v), "") vs=["of", "and", "the", "a"] for v in vs: name = name.replace(" {0} ".format(v), " {0} ".format(v.title())) name = name.replace(".", " ") name=name.strip() dst = join(fileInfo[0], "".join([name, fileInfo[2]])) if name != fileInfo[1]: moveFile(src=movie, dst=dst, debug=True) movies = glob("/Volumes/Download/MoviesFinished/*.*") for movie in movies: fileInfo = getFileBasics(movie) name = fileInfo[1][:-4].strip() year = fileInfo[1][-4:] try: int(year) name = "{0} [{1}]".format(name, year) except: print("Cannot rename {0}".format(movie)) continue src = movie dst = join(fileInfo[0], "".join([name, fileInfo[2]])) moveFile(src=src, dst=dst, debug=True) print("")
def main(args): cwd = getcwd() albumSegments = {} discSegments = {} for ifile in findPattern("./", pattern="."): mid = mp3ID(ifile) try: mid = mp3ID(ifile) except: print("Error reading file {0}".format(ifile)) continue album = mid.getAlbum() print("Album: {0}".format(album)) if album is not None: album = album[0] if albumSegments.get(album) is None: albumSegments[album] = [] albumSegments[album].append(ifile) disc = mid.getDiscNumber() if disc is not None: disc = disc[0] if discSegments.get(disc) is None: discSegments[disc] = [] discSegments[disc].append(ifile) if args.album is True: print("Album Segments: {0}".format(albumSegments.keys())) for album, albumFiles in albumSegments.items(): albumDir = setDir(cwd, album) mkDir(albumDir) for ifile in albumFiles: src = ifile dst = setFile(albumDir, getBasename(ifile)) print("Moving [{0}] to [{1}]".format(src, dst)) moveFile(src, dst, debug=True) if args.disc is True: print("Disc Segments: {0}".format(discSegments.keys())) for disc, discFiles in discSegments.items(): discDir = setDir(cwd, "Disc {0}".format(disc)) mkDir(discDir) for ifile in discFiles: src = ifile dst = setFile(discDir, getBasename(ifile)) #print("Moving [{0}] to [{1}]".format(src, dst)) moveFile(src, dst, debug=True)
def moveExtArtistFilesToNewModValue(self, newModVal): artistsDir = self.getArtistsDir() extArtistsDir = self.getArtistsExtraDir() dutils = discogsUtils() files = glob(join(extArtistsDir, "*.p")) print("Moving {0} files".format(len(files))) for ifile in files: fbasics = getFileBasics(ifile) fname = getBasename(ifile) discID = fbasics[1].split('-')[0] modValue = dutils.getDiscIDHashMod( discID=discID, modval=newModVal) #disc.getMaxModVal()) src = ifile dst = join(artistsDir, str(modValue), fname) moveFile(src, dst)
def moveArtistFilesToNewModValue(self, newModValue, oldModValue): filedir = self.getArtistsDir() dutils = discogsUtils() for modVal in range(oldModValue): modValue = dutils.getDiscIDHashMod( discID=modVal, modval=newModVal) #disc.getMaxModVal()) if modVal == modValue: sleep(1) continue else: files = glob(join(filedir, str(modVal), "*.p")) print("Moving {0} files from {1} to {2}".format( len(files), modVal, modValue)) for ifile in files: fbasics = getFileBasics(ifile) fname = getBasename(ifile) src = ifile dst = join(artistsDir, str(modValue), fname) moveFile(src, dst)
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 main(args): print(args) args = addDefault(args) if args.artist: print('Artist = {!r}'.format(args.artist)) outdir = mkDir(setDir(args.dir, "Artist")) if args.album: print('Album = {!r}'.format(args.album)) outdir = mkDir(setDir(args.dir, "Album")) if args.albumartist: print('AlbumArtist = {!r}'.format(args.albumartist)) outdir = mkDir(setDir(args.dir, "AlbumArtist")) if args.disc: print('Disc = {!r}'.format(args.disc)) outdir = mkDir(setDir(args.dir, "Disc")) if args.track: print('Track = {!r}'.format(args.track)) outdir = mkDir(setDir(args.dir, "Track")) if args.dir: print('Dir = {!r}'.format(args.dir)) tomove = [] files = findWalk(args.dir) for idir, ifiles in files.items(): for jf, ifile in enumerate(ifiles): results = MusicID(ifile, debug=args.debug) if results.skip is True: continue tags = results.getInfo() if args.artist: if args.artist == tags["Artist"][0]: tomove.append(ifile) continue if args.albumartist: if args.albumartist == tags["AlbumArtist"][0]: tomove.append(ifile) continue if args.album: if args.album == tags["Album"][0]: tomove.append(ifile) continue if args.disc: print(args.disc, tags["DiscNo"][0]) if args.disc == tags["DiscNo"][0]: tomove.append(ifile) continue if args.track: if args.track == tags["TrackNo"][0]: tomove.append(ifile) continue if len(tomove) > 0: for ifile in tomove: src = ifile fname = getBasename(ifile) dst = setFile(outdir, fname) moveFile(src, dst) print("Moved {0} ===> {1}".format(src, dst)) else: removeDir(outdir) print("Didn't find any matching files...")
def main(args): args = addDefault(args) if args.debug is True: print('Show = {!r}'.format(args.show)) print('Search = {!r}'.format(args.search)) print('Artist = {!r}'.format(args.artist)) print('Album = {!r}'.format(args.album)) print('AlbumArtist = {!r}'.format(args.albumartist)) print('Title = {!r}'.format(args.title)) print('DiscNo = {!r}'.format(args.discno)) print('TrackNo = {!r}'.format(args.trackno)) print('File = {!r}'.format(args.file)) print('Dir = {!r}'.format(args.dir)) searchResults = {} files = getFiles(args.file, args.dir) for i,(dirval,filevals) in enumerate(files.items()): searchResults[dirval] = [] j = 0 first = False for jf, ifile in enumerate(filevals): results = MusicID(ifile, debug=args.debug) if results.skip is True: continue if first is False: first = True if first is True: print("\nDirectory: {0}".format(dirval)) header() first = None r = results.getInfo() j += 1 if args.search is True: if args.album is not None: if args.album in r["Album"][0]: searchResults[dirval].append(ifile) continue else: raise ValueError("Can only search for album names right now") if args.show is True: p([j, r["DiscNo"], r["TrackNo"], r["AlbumArtist"], r["Artist"], r["Album"], r["Title"], r["Size"]]) continue ## Artst if args.artist is not None: oldName = r["Artist"] results.setTag("Artist", args.artist) ## Album if args.album is not None: oldName = r["Album"] results.setTag("Album", args.album) ## AlbumArtist if args.albumartist is not None: oldName = r["AlbumArtist"] results.setTag("AlbumArtist", args.albumartist) ## Title if args.title is not None: oldName = r["Title"] results.setTag("Title", args.title) ## DiscNo if args.discno is not None: oldName = r["DiscNo"] results.setTag("DiscNo", args.discno) ## TrackNo if args.trackno is not None: oldName = r["TrackNo"] results.setTag("TrackNo", args.trackno) r = results.getInfo() p([j, r["DiscNo"], r["TrackNo"], r["AlbumArtist"], r["Artist"], r["Album"], r["Title"], r["Size"]]) if args.search is True: for dirval,files in searchResults.items(): tmpDir = mkDir(setDir(dirval, "tmp")) for ifile in files: moveFile(ifile, tmpDir)