def getMp3sWithoutArtist(allMp3s): numRead = 0 stringToPrint = "" mp3sWithoutArtists = [] numFound = 0 numMP3s = 0 global knownArtists for fullFileName in allMp3s: #print fullFileName numMP3s += 1 try: mp3File = id3(fullFileName) if mp3File is None or not("artist" in mp3File): mp3sWithoutArtists.append(fullFileName) numFound += 1 numRead += 1 if numRead % 10 == 0: backspaces = repeatChar('\b',len(stringToPrint) + 1) stringToPrint = "Done processing " + str(numRead) + " files. Found " + str(numFound) + " files without an artist." print backspaces + stringToPrint, #print stringToPrint #raw_input() except IOError,e: pass except Exception,e: print "Exception:",e
def populateKnownArtistsFromDirectory(path): numMP3s = 0 allMp3s = populateMP3sFromDirectory(path) numRead = 0 stringToPrint = "" global knownArtists for fullFileName in allMp3s: # print fullFileName numMP3s += 1 try: mp3File = id3(fullFileName) if mp3File is None: print "No tags" if "artist" in mp3File: currArtist = str(mp3File["artist"])[3:-2] if currArtist in knownArtists: knownArtists[currArtist] += 1 else: knownArtists[currArtist] = 1 numRead += 1 if numRead % 10 == 0: backspaces = repeatChar("\b", len(stringToPrint) + 1) stringToPrint = "Done processing " + str(numRead) + " files" print backspaces + stringToPrint, # print stringToPrint # raw_input() except IOError, e: pass except Exception, e: print "Exception:", e
def __organize_file(self, f, method, target_folder=None): created_folders= set() if not target_folder: target_folder = os.path.dirname(f) frmt = f.split('.')[-1] if frmt not in self.__supported_formats: self.__errors.append(f) created_folders.update([self.__handle_errors(method, target_folder)]) return created_folders if frmt == 'mp3': f_attr = id3(f) elif frmt == 'flac': f_attr = flac(f) elif frmt == 'ogg': f_attr = ogg(f) self.songs += 1 artist = f_attr['artist'][0].replace('/', '-') album = f_attr['album'][0].replace('/', '-') title = f_attr['title'][0].replace('/', '-') try: os.makedirs(os.path.join(self.archive, artist, album)) except OSError: pass self.__cmethod(f, '%s.%s' % ( os.path.join(self.archive, artist, album, title), frmt), method) created_folders.update([os.path.join(self.archive, artist)]) clean(self.archive) return created_folders
def populateKnownArtistsFromDirectory(path): numMP3s = 0 allMp3s = populateMP3sFromDirectory(path) numRead = 0 stringToPrint = "" global knownArtists for fullFileName in allMp3s: #print fullFileName numMP3s += 1 try: mp3File = id3(fullFileName) if mp3File is None: print "No tags" if "artist" in mp3File: currArtist = str(mp3File["artist"])[3:-2] if currArtist in knownArtists: knownArtists[currArtist] += 1 else: knownArtists[currArtist] = 1 numRead += 1 if numRead % 10 == 0: backspaces = repeatChar('\b',len(stringToPrint) + 1) stringToPrint = "Done processing " + str(numRead) + " files" print backspaces + stringToPrint, #print stringToPrint #raw_input() except IOError,e: pass except Exception,e: print "Exception:",e
def getMp3sWithoutTitles(allMp3s): numRead = 0 stringToPrint = "" mp3sWithoutTitles = [] numFound = 0 numMP3s = 0 global knownArtists for fullFileName in allMp3s: # print fullFileName numMP3s += 1 try: mp3File = id3(fullFileName) if mp3File is None or not ("title" in mp3File): mp3sWithoutTitles.append(fullFileName) numFound += 1 numRead += 1 if numRead % 10 == 0: backspaces = repeatChar("\b", len(stringToPrint) + 1) stringToPrint = ( "Done processing " + str(numRead) + " files. Found " + str(numFound) + " files without an artist." ) print backspaces + stringToPrint, except IOError, e: pass except Exception, e: print "Exception:", e
def countlyrics(): nolyr = 0 lyr = 0 f = open("lyrics/nolyr.txt", "w") for root, dirs, files in os.walk(directory): for name in files: if name.endswith(".flac"): track = FLAC(os.path.join(root, name)) if not os.path.isfile(os.path.join(root, name[:-5] + ".lrc")): nolyr += 1 artist = track["artist"][0] album = track["album"][0] title = track["title"][0] f.write(artist + " - " + album + " - " + title + "\n") else: lyr += 1 elif name.endswith(".mp3"): track = id3(os.path.join(root, name)) if not os.path.isfile(os.path.join(root, name[:-4] + ".lrc")): artist = track["artist"][0] album = track["album"][0] title = track["title"][0] f.write(artist + " - " + album + " - " + title + "\n") nolyr += 1 else: lyr += 1 print(str(lyr) + " with lyrics, " + str(nolyr) + " without") print(str(round(100 * lyr / (nolyr + lyr), 1)) + "% with lyrics") f.close()
def get_tags(f): os.path.abspath(f) try: audio = id3(f) artist = audio['artist'][0] title = audio['title'][0] return (artist, title) except: return (f, None)
def thefolderiser(filename): global count, count2 if filename.endswith(".mp3") or filename.endswith(".flac"): if filename.endswith(".flac"): track = FLAC(directory + filename) else: track = id3(directory + filename) artist = track["artist"][0] album = track["album"][0] title = track["title"][0] artist = deco(''.join(c for c in artist if c not in invalidchars)) album = deco(''.join(c for c in album if c not in invalidchars)) title = deco(''.join(c for c in title if c not in invalidchars)) if filename.endswith(".flac"): extension = ".flac" else: extension = ".mp3" if not (os.path.isdir(directory + artist)): os.mkdir(directory + artist) if not (os.path.isdir(directory + artist + "/" + album)): os.mkdir(directory + artist + "/" + album) if not os.path.isfile(directory + artist + "/" + album + "/" + title + extension): os.rename( directory + filename, directory + artist + "/" + album + "/" + title + extension) if filename.endswith(".mp3") and os.path.isfile(directory + filename[:-4] + ".lrc"): os.rename( directory + filename[:-4] + ".lrc", directory + artist + "/" + album + "/" + title + ".lrc") elif filename.endswith(".flac") and os.path.isfile(directory + filename[:-5] + ".lrc"): os.rename( directory + filename[:-5] + ".lrc", directory + artist + "/" + album + "/" + title + ".lrc") count += 1 else: print(title + " already exists in target dir, skipping") count2 += 1 # print(filename + " >> " + title + extension) print("moved " + str(count) + " files, skipped " + str(count2) + " files ", end="\r")
def printMP3sInDir(): path = raw_input("Path to Search?: ") for path, dirs, files in os.walk(path): files.sort() for filename in files: if not filename.lower().endswith(".mp3"): continue fullFileName = os.path.join(path, filename) try: mp3File = id3(fullFileName) print mp3File print fullFileName raw_input() except Exception: rep.error(fullFileName) else: print "Success"
def printMP3sInDir(): path = raw_input("Path to Search?: ") for path, dirs, files in os.walk(path): files.sort() for filename in files: if not filename.lower().endswith('.mp3'): continue fullFileName = os.path.join(path, filename) try: mp3File = id3(fullFileName) print mp3File print fullFileName raw_input() except Exception: rep.error(fullFileName) else: print "Success"
def __organize_folder(self, folder, method, target_folder=None): created_folders = set() if not target_folder: target_folder = folder for root, folders, files in os.walk(folder): if target_folder in root and target_folder != folder: # this folder is already organized continue for f in files: frmt = f.split('.')[-1] f = os.path.join(root, f) if not frmt in self.__supported_formats: self.__errors.append(f) continue self.ui.printg(f) # try ? if frmt == 'mp3': f_attr = id3(f) elif frmt == 'flac': f_attr = flac(f) elif frmt == 'ogg': f_attr = ogg(f) self.songs += 1 artist = f_attr['artist'][0].replace('/', '-') album = f_attr['album'][0].replace('/', '-') title = f_attr['title'][0].replace('/', '-') try: os.makedirs(os.path.join(self.archive, artist, album)) except OSError: # there is already a folder pass self.__cmethod(f, '%s.%s' % ( os.path.join(self.archive, artist, album, title), frmt), method) created_folders.update([os.path.join(self.archive, artist)]) # buraya dikkat created_folders.update([self.__handle_errors(method, self.archive)]) if self.cover: self.__download_albumcover(created_folders) clean(self.archive) return created_folders
def __init__(self, location=None): """Pass in pathname, prefer full pathname to relative names""" self.pathname = unicode(location) if location == None: try: self.metadata = '' raise Exception ("NoFileError") except Exception as inst: print inst.args[0] elif location.endswith('mp3'): try: self.metadata = id3(location) except Exception as inst: self.metadata = None print inst.args else: try: self.metadata = mutagen.File(location) except Exception as inst: self.metadata = None print inst.args
def thelyriciser(filename): global count, count2 if filename.endswith( ".mp3" ): # because of how i am doing lyrics i don't actually need any flacs here? if not (os.path.isfile(directory + "lyrics/" + filename[:-4] + ".lrc")): return track = id3(directory + "lyrics/" + filename) artist = track["artist"][0] album = track["album"][0] title = track["title"][0] artist = deco(''.join(c for c in artist if c not in invalidchars)) album = deco(''.join(c for c in album if c not in invalidchars)) title = deco(''.join(c for c in title if c not in invalidchars)) extension = ".lrc" if os.path.isfile( directory + artist + "/" + album + "/" + title + extension ): # assume lyrics folder is better quality, you may not want this! os.remove(directory + artist + "/" + album + "/" + title + extension) if os.path.isdir(directory + artist + "/" + album): os.rename( directory + "lyrics/" + filename[:-4] + ".lrc", directory + artist + "/" + album + "/" + title + extension) count += 1 else: count2 += 1 # print(filename + " >> " + title + extension) print("moved " + str(count) + " files, skipped " + str(count2) + " files ", end="\r")
def main(self): for ana_dizin, dizinler, dosyalar in os.walk(self.yer): for dosya in dosyalar: Format = dosya.split(".")[-1] if Format in self.supported_formats: _dosya = os.path.join(ana_dizin, dosya) if self.hedef in ana_dizin and self.hedef != self.yer: continue printg("%s " % _dosya) try: if Format == "mp3": dosya = id3(_dosya) elif Format == "flac": dosya = flac(_dosya) elif Format == "ogg": dosya = ogg(_dosya) self.songs += 1 artist = dosya["artist"][0].replace("/", "-") album = dosya["album"][0].replace("/", "-") title = dosya["title"][0].replace("/", "-") try: os.makedirs(os.path.join(self.hedef, artist, album)) except OSError: pass self.method(_dosya, "%s.%s" % (os.path.join(self.hedef, artist, album, title), Format)) printg("ok..\n") except: self.errors.append(_dosya) printg("error..\n") else: self.errors.append(os.path.join(ana_dizin, dosya)) yield True self.download_albumcover() self.handle_errors() self.clean() yield False
def duzenle(yer, hedef, yontem=cp): """ Ana fonksiyon. Yer'deki tum dosyalari os.walk yardimi ile gezer. Formata uyan dosyalarin bilgilerini Mutagen yardimiyla okur. Gerekli klasorleri olusturur, belirtilen yonteme gore tasir veya kopyalar. """ if not os.path.isdir(yer): print u"Arsiv konumu hatali." exit() if not os.path.isdir(hedef): os.mkdir(hedef) print u"Hedef klasor olusturuluyor.." errors = [] songs = 0 supported_formats = ["mp3", "flac", "ogg"] for ana_dizin, dizinler, dosyalar in os.walk(yer): for dosya in dosyalar: Format = dosya.split(".")[-1] if Format in supported_formats: _dosya = os.path.join(ana_dizin, dosya) print _dosya, try: if Format == "mp3": dosya = id3(_dosya) elif Format == "flac": dosya = flac(_dosya) elif Format == "ogg": dosya = ogg(_dosya) songs += 1 artist = dosya["artist"][0].replace("/", "-") album = dosya["album"][0].replace("/", "-") title = dosya["title"][0].replace("/", "-") try: os.makedirs(os.path.join(hedef, artist, album)) except OSError: pass yontem(_dosya, "%s.%s" % (os.path.join(hedef, artist, album, title), Format)) print "tamam.." except: errors.append(_dosya) print "hata.." else: errors.append(os.path.join(ana_dizin, dosya)) print "digerleri..", for dosya in errors: try: os.mkdir(os.path.join(hedef, "_DIGER")) except: pass _hedef = os.path.join(hedef, "_DIGER") yeni = dosya.split(os.path.sep)[-1] yontem(dosya, os.path.join(_hedef, yeni)) songs += 1 print "tamam.." print "log dosyasi..", log = open(os.path.join(hedef, "log.txt"), "w") log.write("%s kopyalandi.\n\n" % songs) error_count = 0 for error in errors: error_count += 1 log.write("%s\n" % error) log.write("\n\ttoplam: %s hata." % error_count) log.close() print "tamam.."
def writeMp3(filename,artist,title): mp3File = id3(filename) mp3File["title"] = title mp3File["artist"] = artist mp3File.save()
def writeMp3(filename, artist, title): mp3File = id3(filename) mp3File["title"] = title mp3File["artist"] = artist mp3File.save()