def export_db(dbpath, dirpath): conn = sqlite3.connect(dbpath) fields = get_column_names(conn) cursor = execute( conn, 'SELECT %s from audio' % ",".join('"%s"' % f for f in fields)) for values in cursor: values = map(clean_value_for_export, values) new_tag = dict((k, v) for k, v in zip(fields, values)) filepath = new_tag['__path'] new_values = dict(z for z in new_tag.iteritems() if not z[0].startswith('__')) if not issubfolder(dirpath, filepath): logging.info('Skipped %s. Not in dirpath.' % filepath) continue try: logging.info('Updating %s' % filepath) tag = audioinfo.Tag(filepath) except Exception, e: logging.exception(e) else: logging.debug(new_values) for key, value in new_values.iteritems(): if not value and key in tag: del (tag[key]) else: tag[key] = value try: tag.save() audioinfo.setmodtime(tag.filepath, tag.accessed, tag.modified) logging.info('Updated tag to %s' % filepath) except Exception, e: logging.error('Could not save tag to %s' % filepath) logging.exception(e)
def libstuff(dirname): files = [] for filename in os.listdir(dirname): tag = audioinfo.Tag(path.join(dirname, filename)) if tag: files.append(tag) return files
def tag_to_json(audio, fields=None): import puddlestuff.audioinfo as audioinfo if isinstance(audio, basestring): try: audio = audioinfo.Tag(audio) except: logging.exception("Invalid File: " + audio) return if audio is None: return try: if fields: tags = dict((k, audio[k]) for k in fields if k in audio) else: fields = [] tags = audio.tags.copy() except AttributeError: tags = audio.copy() try: if not fields or '__image' in fields: if audio.images: tags['__image'] = map(img_to_b64, audio.images) elif '__image' in tags: tags['__image'] = map(img_to_b64, tags['__image']) except AttributeError: if not fields or '__image' in fields: if '__image' in tags: tags['__image'] = map(img_to_b64, tags['__image']) return tags
def restore_backup(fn): for i, tag in enumerate(json.loads(open(fn, 'r').read())): try: fn = tag['__path'] except KeyError: 'Error: A file was backed up without a file path.' try: audio = audioinfo.Tag(fn) except EnvironmentError, e: "Error: Couldn't restore", fn, str(e) continue except Exception, e: "Error: Couldn't restore", fn, str(e) continue
def getfiles(dirpath): """Sets the values of artists with the artist name as key and a list of the music by that artist as a list.""" #files has key=artist name and value=list of filenames with the same artist. files = defaultdict(lambda: []) for f in os.listdir(dirpath): f = join(dirpath, f) try: tag = audioinfo.Tag(f) except: pass if tag is not None and 'artist' in tag: files[to_string(tag['artist'])].append(f) return files
def import_dir(dbpath, dirpath): conn = initdb(dbpath) cursor = execute(conn, 'SELECT * from audio') columns = get_column_names(conn) for filepath in getfiles(dirpath, True): try: logging.info("Import started: " + filepath) tag = audioinfo.Tag(filepath) except Exception, e: logging.error("Could not import file: " + filepath) logging.exception(e) else: if tag is not None: try: columns = import_tag(tag, conn, columns) logging.info('Imported completed: ' + filepath) except Exception, e: logging.error('Error occured importing file %s' % filepath) logging.exception(e) raise else:
def restore_backup(fn): for i, tag in enumerate( json.loads( open(fn, 'r').read())): try: fn = tag['__path'] except KeyError: 'Error: A file was backed up without a file path.' try: audio = audioinfo.Tag( fn) except EnvironmentError, e: "Error: Couldn't restore", fn, str( e) continue except Exception, e: "Error: Couldn't restore", fn, str( e) continue if '__image' in tag: images = tag[ '__image'] del (tag[ '__image']) audio.images = map( b64_to_img, images) audio.clear() audio.update( tag) audio.save() if __name__ == '__main__': main()
if format is None: text = '\n'.join(header + filenames) else: text = header extinfo = ('#EXTINF: %s, %s' % (str(lnglength(f.length)), encode_fn(tagtofilename(format, f, False))) for f in tags) [text.extend([z,y]) for z,y in zip(extinfo, filenames)] text = '\n'.join(text) playlist = open(tofile, 'w') playlist.write(text) playlist.close() if __name__ == '__main__': app = QApplication(sys.argv) filedlg = QFileDialog() filedlg.setFileMode(filedlg.DirectoryOnly) filename = unicode(filedlg.getExistingDirectory(None, 'Open Folder')) tags = [] for z in os.listdir(filename): try: tag = audioinfo.Tag(os.path.join(filename,z)) if tag: tags.append(tag) except Exception, e: unicode(e) folder = unicode(filedlg.getSaveFileName(None, 'Save File')) exportm3u(tags, folder)
if isinstance(value, basestring): value = [value] elif isinstance(value, (int, float)): value = [unicode(value)] try: if res in u'\\\\'.join(value).lower(): return True except TypeError, e: continue else: return bool(res) return False if __name__ == '__main__': audio = audioinfo.Tag('clen.mp3') #parse(audio, "not p") #parse(audio, 'not missing artist') #parse(audio, '7 greater 6') #parse(audio, '%track% greater 14') #parse(audio, '%track% greater "$add($len(%artist%), 50)"') #t = time.time() #parse(audio, '(not missing artist) and (20 greater 19)') #parse(audio, 'not (20 greater 19)') #print time.time() - t #parse(audio, 'not missing artist and 18 greater 19') #parse(audio, 'artist is "Carl Douglas"') #parse(audio, "artist has aarl") #parse(audio, "artist has Carl") import time t = time.time()
set_status(SUBMIT_ERROR_MSG.arg(unicode(e))) write_log(SUBMIT_ERROR_MSG.arg(unicode(e))) break def retrieve(self, info): return None def applyPrefs(self, args): self.min_score = args[0] / 100.0 self.__user_key = args[1] if not which('fpcalc'): raise ImportError("fpcalc not found on system") info = AcoustID if __name__ == '__main__': x = AcoustID() x.applyPrefs([85, "KEIY0X4P"]) file_dir = '' files = [] for z in os.listdir(file_dir): fn = os.path.join(file_dir, z) try: tag = audioinfo.Tag(fn) if tag is not None: files.append(tag) except: pass x.submit(files)