def update_ratings(itunes): """Handles synchronizing ratings and addition dates in iTunes :param itunes: `iTunesManager` used for communicating with iTunes. This should already be setup and connected. """ # Setup DB connection db = init_db_conn() # Loop over tracks building the db. Note that prior tracks with # matching MD5 data will all be updated each time a subsequent track # is found. This obviates the need to re-review the data after # processing all tracks. for t in itunes.itunes.tracks(): track_hash = gen_hash(t) print '%s\t%d\t%d\t%s' % (track_hash, t.id(), t.rating(), t.name()) save_track(itunes, db, t)
if not silent: sys.stdout.write('[Total found: %d New: %d]\r' % (total_found, new_found)) if not silent: print '\n' return (successes, failures) if __name__ == '__main__': # Unbuffer stdout, for debugging sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0) # Setup DB db = init_db_conn() # Do it up! (success, failure) = sync_dir(db, DEFAULT_DIR) # Report on our successes and failures, openly. We share. for s in success: try: print 'Added: %s' % s except UnicodeEncodeError: print 'Added: ', print s.encode('utf-16') print '' for f in failure: