diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-01-11 21:14:29 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2013-01-11 21:20:30 +0100 |
commit | 6c89bb616bdddd4b678b9ccf55a99f5648b32da5 (patch) | |
tree | fd252208ee29f36a0bf4b12026b951f6d91c00b0 /backend | |
parent | Properly support WAV files. (diff) | |
download | zmusic-ng-6c89bb616bdddd4b678b9ccf55a99f5648b32da5.tar.xz zmusic-ng-6c89bb616bdddd4b678b9ccf55a99f5648b32da5.zip |
Clean up null titles, wav, and unicode.
Hopefully the last of the encoding issues.
Reported-by: Scott Moak <scott.moak@mybrainoncode.com>
Diffstat (limited to 'backend')
-rw-r--r-- | backend/zmusic/endpoints/query.py | 2 | ||||
-rw-r--r-- | backend/zmusic/endpoints/scan.py | 11 | ||||
-rw-r--r-- | backend/zmusic/picard/file.py | 3 | ||||
-rw-r--r-- | backend/zmusic/picard/formats/wav.py | 10 |
4 files changed, 12 insertions, 14 deletions
diff --git a/backend/zmusic/endpoints/query.py b/backend/zmusic/endpoints/query.py index 6f15ea3..b4a7f34 100644 --- a/backend/zmusic/endpoints/query.py +++ b/backend/zmusic/endpoints/query.py @@ -52,7 +52,7 @@ def query(query): songs = [] for song in query: - if len(song.title.strip()) == 0: + if song.title is None or len(song.title.strip()) == 0: song.title = "Untitled Song" if song.track == 0: song.track = None diff --git a/backend/zmusic/endpoints/scan.py b/backend/zmusic/endpoints/scan.py index 46d59a7..275c7a8 100644 --- a/backend/zmusic/endpoints/scan.py +++ b/backend/zmusic/endpoints/scan.py @@ -2,6 +2,7 @@ from zmusic.login import admin_required from zmusic import app, db from zmusic.database import Song from zmusic.picard.formats import open as readtags +from zmusic.picard.util import encode_filename from flask import Response import time import os @@ -13,11 +14,11 @@ def scan_music(): def do_scan(): yield "%i | Begin.\n" % int(time.time()) all_files = {} - for root, dirs, files in os.walk(app.config["MUSIC_PATH"]): + for root, dirs, files in os.walk(unicode(app.config["MUSIC_PATH"])): if len(files) != 0: - yield "%i | Scanning [%s].\n" % (int(time.time()), root) + yield "%i | Scanning [%s].\n" % (int(time.time()), encode_filename(root)) for name in files: - name = os.path.join(root, name) + name = encode_filename(os.path.join(root, name)) all_files[name] = True song = Song.query.get(name) if song != None: @@ -35,11 +36,11 @@ def scan_music(): continue song.sync_picard(tags) db.session.add(song) - yield "%i | Adding [%s].\n" % (int(time.time()), song.filename) + yield "%i | Adding [%s].\n" % (int(time.time()), encode_filename(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()), str(song.filename)) + yield "%i | Removing [%s].\n" % (int(time.time()), encode_filename(song.filename)) db.session.commit() yield "%i | Done.\n" % int(time.time()) response = Response(do_scan(), mimetype="text/plain", direct_passthrough=True) diff --git a/backend/zmusic/picard/file.py b/backend/zmusic/picard/file.py index dd3e091..0e246eb 100644 --- a/backend/zmusic/picard/file.py +++ b/backend/zmusic/picard/file.py @@ -23,6 +23,9 @@ class File(dict, object): self._load(filename) def _info(self, metadata, file): + if "title" not in metadata or metadata["title"] is None or len(metadata["title"].strip()) == 0: + metadata["title"] = os.path.splitext(os.path.basename(self["filename"]))[0] + self.update(metadata) for mimetype in file.mime: diff --git a/backend/zmusic/picard/formats/wav.py b/backend/zmusic/picard/formats/wav.py index a8dc521..7446376 100644 --- a/backend/zmusic/picard/formats/wav.py +++ b/backend/zmusic/picard/formats/wav.py @@ -18,18 +18,17 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. import wave -import os from zmusic.picard.file import File from zmusic.picard.metadata import Metadata from zmusic.picard.util import encode_filename class WaveInfo(object): def __init__(self, file): - self.length = 1000 * file.getnframes() / file.getframerate() + self.length = file.getnframes() / float(file.getframerate()) class Wave(object): def __init__(self, file): - self.mime = "audio/wav" + self.mime = ["audio/wav"] self.info = WaveInfo(file) class WAVFile(File): @@ -49,11 +48,6 @@ class WAVFile(File): file = Wave(f) self._info(metadata, file) - - metadata["title"] = os.path.splitext(os.path.basename(filename))[0] - metadata["album"] = '' - metadata["artist"] = '' - return metadata def _save(self, filename, metadata, settings): |