Skip to content
Snippets Groups Projects
Commit ae8e954c authored by ale's avatar ale
Browse files

add support for rebuilding metadata of songs with partial tags

parent 3e5d16cf
Branches
No related tags found
No related merge requests found
......@@ -63,15 +63,26 @@ class MetadataFixer(object):
mp3.title = metadata.normalize_string(info['title'])
mp3.artist = metadata.normalize_string(info['artist_name'])
def scan(self):
def scan(self, dry_run, partial):
"""Scan the database for new files."""
n_bad = n_ok = n_err = 0
for mp3 in MP3.get_with_bad_metadata():
if partial:
entries = MP3.query.filter(
(MP3.state == MP3.READY)
& (MP3.has_fingerprint == True)
& ((MP3.artist == None)
| (MP3.artist == '')
| (MP3.title == '')
| (MP3.title == None)))
else:
entries = MP3.get_with_bad_metadata()
for mp3 in entries:
n_bad += 1
log.info('searching metadata for %s' % mp3.sha1)
try:
self.process(mp3)
mp3.state = MP3.READY
if not dry_run:
self.idx.add_mp3(mp3)
log.info('found: %s / %s' % (mp3.artist, mp3.title))
n_ok += 1
......@@ -82,34 +93,38 @@ class MetadataFixer(object):
log.error(traceback.format_exc())
n_err += 1
mp3.state = MP3.ERROR
if not dry_run:
Session.add(mp3)
if not dry_run:
Session.commit()
self.idx.commit()
log.debug('total: %d songs, found: %d' % (n_bad, n_ok))
def run(self, run_once):
def run(self, run_once, dry_run, partial):
while True:
self.scan()
self.scan(dry_run, partial)
if run_once:
break
Session.remove()
time.sleep(600)
def run_fixer(solr_url, echonest_api_key, db_url, run_once):
def run_fixer(solr_url, echonest_api_key, db_url, dry_run, partial, run_once):
socket.setdefaulttimeout(300)
init_db(db_url)
fixer = MetadataFixer(solr_url, echonest_api_key)
fixer.run(run_once)
fixer.run(run_once, dry_run, partial)
def main():
parser = optparse.OptionParser()
parser.add_option('--once', action='store_true')
parser.add_option('--dry_run', action='store_true')
parser.add_option('--solr_url', default='http://localhost:8080/solr')
parser.add_option('--echonest_api_key')
parser.add_option('--db_url')
parser.add_option('--partial', action='store_true')
daemonize.add_standard_options(parser)
utils.read_config_defaults(
parser, os.getenv('DJRANDOM_CONF', '/etc/djrandom.conf'))
......@@ -125,8 +140,8 @@ def main():
opts.foreground = True
daemonize.daemonize(opts, run_fixer,
(opts.solr_url, opts.echonest_api_key,
opts.db_url, opts.once))
(opts.solr_url, opts.echonest_api_key, opts.db_url,
opts.dry_run, opts.partial, opts.once))
if __name__ == '__main__':
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment