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 __init__(self, info): from mutagen.flac import FLAC as flac self.p = path + name audio = flac(self.p) for key, value in info.items(): audio[key] = value self.id = info['description'] self.audio = audio
def peek(songlist): artlist = [] # artist alblist = [] # album artist = album = "" for song in songlist: extension = os.path.splitext(song)[1].lower() if extension == ".flac": raw = flac(song) else: raw = eid3(song) try: album = raw.get('album')[0] album = parseName(album) except: album = "Unknown Value" if 'artist' in raw: artist = raw.get('artist')[0] elif 'performer' in raw: artist = raw.get('performer')[0] elif 'composer' in raw: artist = raw.get('composer')[0] try: artist = parseName(artist) except: artist = "Unknown Value" artlist.append(artist) alblist.append(album) if not checkEqual(artlist): artist = "VA" if not checkEqual(alblist): album = "Unknown Album" return artist, album
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 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 process(songlist): # mutagen returns a list of values instead of a raw string; be careful with it try: artist, album = peek(songlist) except: return if album == "Unknown Album": printToLog(False, "Different albums within the same folder") return for song in songlist: extension = os.path.splitext(song)[1].lower() if extension == ".flac": raw = flac(song) else: raw = eid3(song) # filename refactor try: track = raw.get('track')[0] title = raw.get('title')[0] if track < 10: track = "0" + track filename = track + " " + title + extension #TODO check if this ALWAYS triggers or something except: filename = os.path.basename(song) try: year = raw.get('date')[0] year = parseDate(year) except: year = "(Unknown Year)" # TODO regex filename # TODO fetch from discogs if artist == album == "Unknown Value" and year == "(Unknown Year)": printToLog(False, "Not enough information") return # create new destination directory # hierarchy : '/artist/(year) album/' ex: /Wisp/(2005) NRTHNDR/ artist_folder = os.path.join(dest_dir, artist) album_folder = os.path.join(artist_folder, year + " " + album) try: os.mkdir(artist_folder) except FileExistsError: pass try: os.mkdir(album_folder) except FileExistsError: pass try: dest = os.path.join(dest_dir, os.path.join(album_folder, filename)) move(song, dest) except FileExistsError: filename += ".bck" dest = os.path.join(dest_dir, os.path.join(album_folder, filename)) printToLog(False, "File already exists, moving as ", dest)