diff options
| author | 2026-02-21 01:12:33 +0100 | |
|---|---|---|
| committer | 2026-02-21 01:12:33 +0100 | |
| commit | 4fd20ebb3aefd698c0b570ad3d1745aa313188d9 (patch) | |
| tree | 15a7d0c7024b0957dbe425ee3a0add5026ef9d3c | |
| parent | Use standard digit matching, not \d (diff) | |
| download | zmusic-ng-master.tar.xz zmusic-ng-master.zip | |
| -rw-r--r-- | backend/zmusic/endpoints/scan.py | 61 |
1 files changed, 31 insertions, 30 deletions
diff --git a/backend/zmusic/endpoints/scan.py b/backend/zmusic/endpoints/scan.py index d1a3078..621b047 100644 --- a/backend/zmusic/endpoints/scan.py +++ b/backend/zmusic/endpoints/scan.py @@ -12,37 +12,38 @@ import os def scan_music(): db.create_all(); def do_scan(): - yield "%i | Begin.\n" % int(time.time()) - all_files = {} - for root, dirs, files in os.walk(app.config["MUSIC_PATH"]): - if len(files) != 0: - yield "%i | Scanning [%s].\n" % (int(time.time()), root) - for name in files: - name = os.path.join(root, name) - all_files[name] = True - song = Song.query.get(name) - if song != None: - stat = os.stat(name) - if song.lastmodified == stat.st_mtime and song.filesize == stat.st_size: + with app.app_context(): + yield "%i | Begin.\n" % int(time.time()) + all_files = {} + for root, dirs, files in os.walk(app.config["MUSIC_PATH"]): + if len(files) != 0: + yield "%i | Scanning [%s].\n" % (int(time.time()), root) + for name in files: + name = os.path.join(root, name) + all_files[name] = True + song = Song.query.get(name) + if song != None: + stat = os.stat(name) + if song.lastmodified == stat.st_mtime and song.filesize == stat.st_size: + continue + else: + song = Song() + try: + tags = readtags(name) + except: + tags = None + if tags == None: + yield "%i | Skipping [%s].\n" % (int(time.time()), name) continue - else: - song = Song() - try: - tags = readtags(name) - except: - tags = None - if tags == None: - yield "%i | Skipping [%s].\n" % (int(time.time()), name) - continue - song.sync_picard(tags) - db.session.add(song) - yield "%i | Adding [%s].\n" % (int(time.time()), song.filename) - for song in db.session.query(Song.filename): - if song.filename not in all_files: - Song.query.filter(Song.filename == song.filename).delete(False) - yield "%i | Removing [%s].\n" % (int(time.time()), song.filename) - db.session.commit() - yield "%i | Done.\n" % int(time.time()) + song.sync_picard(tags) + db.session.add(song) + yield "%i | Adding [%s].\n" % (int(time.time()), song.filename) + for song in db.session.query(Song.filename): + if song.filename not in all_files: + Song.query.filter(Song.filename == song.filename).delete(False) + yield "%i | Removing [%s].\n" % (int(time.time()), song.filename) + db.session.commit() + yield "%i | Done.\n" % int(time.time()) response = Response(do_scan(), mimetype="text/plain") response.headers.add("X-Accel-Buffering", "no") response.cache_control.no_cache = True |
