mirror of
https://github.com/fergalmoran/picard.git
synced 2026-02-04 14:54:02 +00:00
* Move picard.plugins.picardmutagen to picard.formats
* IFileOpener.open_file now returns only one file * Removed IFileOpener.can_open_file
This commit is contained in:
@@ -27,6 +27,13 @@ from picard.util import LockableObject, needs_write_lock, needs_read_lock, encod
|
||||
|
||||
class File(LockableObject):
|
||||
|
||||
__id_counter = 0
|
||||
|
||||
@staticmethod
|
||||
def new_id():
|
||||
File.__id_counter += 1
|
||||
return File.__id_counter
|
||||
|
||||
NEW = 0
|
||||
CHANGED = 1
|
||||
TO_BE_SAVED = 2
|
||||
@@ -38,23 +45,31 @@ class File(LockableObject):
|
||||
self.filename = filename
|
||||
self.base_filename = os.path.basename(filename)
|
||||
self.state = File.NEW
|
||||
|
||||
self.orig_metadata = Metadata()
|
||||
self.metadata = Metadata()
|
||||
self.user_metadata = Metadata()
|
||||
self.server_metadata = Metadata()
|
||||
self.metadata = self.user_metadata
|
||||
|
||||
self.orig_metadata["~#length"] = 0
|
||||
self.orig_metadata["title"] = os.path.basename(self.filename)
|
||||
|
||||
self.user_metadata.copy(self.orig_metadata)
|
||||
self.server_metadata.copy(self.orig_metadata)
|
||||
|
||||
self.similarity = 1.0
|
||||
self.parent = None
|
||||
|
||||
def __str__(self):
|
||||
return '<File #%d "%s">' % (self.id, self.base_filename)
|
||||
|
||||
__id_counter = 0
|
||||
|
||||
@staticmethod
|
||||
def new_id():
|
||||
File.__id_counter += 1
|
||||
return File.__id_counter
|
||||
def load(self):
|
||||
"""Save the metadata."""
|
||||
self.read()
|
||||
#raise NotImplementedError
|
||||
|
||||
def save(self):
|
||||
"""Save the file."""
|
||||
"""Save the metadata."""
|
||||
raise NotImplementedError
|
||||
|
||||
def save_images(self):
|
||||
|
||||
@@ -79,19 +79,19 @@ mutagen._util.delete_bytes = _delete_bytes
|
||||
|
||||
from picard.api import IFileOpener
|
||||
from picard.component import Component, implements
|
||||
from picard.plugins.picardmutagen.asf import MutagenASFFile
|
||||
from picard.plugins.picardmutagen.mp4 import MP4File
|
||||
from picard.plugins.picardmutagen.id3 import (
|
||||
from picard.formats.asf import MutagenASFFile
|
||||
from picard.formats.mp4 import MP4File
|
||||
from picard.formats.id3 import (
|
||||
MP3File,
|
||||
TrueAudioFile,
|
||||
)
|
||||
from picard.plugins.picardmutagen.apev2 import (
|
||||
from picard.formats.apev2 import (
|
||||
MonkeysAudioFile,
|
||||
MusepackFile,
|
||||
OptimFROGFile,
|
||||
WavPackFile,
|
||||
)
|
||||
from picard.plugins.picardmutagen.vorbis import (
|
||||
from picard.formats.vorbis import (
|
||||
FLACFile,
|
||||
OggFLACFile,
|
||||
OggSpeexFile,
|
||||
@@ -128,16 +128,8 @@ class MutagenComponent(Component):
|
||||
return [(key, value[1]) for key, value in
|
||||
self.__supported_formats.items()]
|
||||
|
||||
def can_open_file(self, filename):
|
||||
for ext in self.__supported_formats.keys():
|
||||
if filename.lower().endswith(ext):
|
||||
return True
|
||||
return False
|
||||
|
||||
def open_file(self, filename):
|
||||
for ext in self.__supported_formats.keys():
|
||||
if filename.lower().endswith(ext):
|
||||
file = self.__supported_formats[ext][0](filename)
|
||||
file.read()
|
||||
return (file,)
|
||||
return self.__supported_formats[ext][0](filename)
|
||||
return None
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
from picard.file import File
|
||||
from picard.util import encode_filename
|
||||
from picard.plugins.picardmutagen.mutagenext.asf import ASF
|
||||
from picard.formats.mutagenext.asf import ASF
|
||||
|
||||
class MutagenASFFile(File):
|
||||
|
||||
@@ -22,7 +22,7 @@ import mutagen.mp3
|
||||
import mutagen.trueaudio
|
||||
from mutagen import id3
|
||||
from picard.file import File
|
||||
from picard.plugins.picardmutagen.mutagenext import compatid3
|
||||
from picard.formats.mutagenext import compatid3
|
||||
from picard.util import encode_filename
|
||||
|
||||
class ID3File(File):
|
||||
@@ -19,6 +19,5 @@
|
||||
|
||||
"""Built-in plugins."""
|
||||
|
||||
import picard.plugins.cuesheet
|
||||
import picard.plugins.csv_opener
|
||||
import picard.plugins.picardmutagen
|
||||
#import picard.plugins.cuesheet
|
||||
#import picard.plugins.csv_opener
|
||||
|
||||
@@ -31,6 +31,7 @@ import imp
|
||||
|
||||
import picard.resources
|
||||
import picard.plugins
|
||||
import picard.formats
|
||||
import picard.tagz
|
||||
|
||||
from picard import musicdns
|
||||
@@ -248,53 +249,35 @@ class Tagger(QtGui.QApplication, ComponentManager, Component):
|
||||
formats.extend(opener.get_supported_formats())
|
||||
return formats
|
||||
|
||||
def add_files(self, files):
|
||||
"""Load and add files."""
|
||||
files = map(os.path.normpath, files)
|
||||
self.log.debug(u"Adding files %r", files)
|
||||
filenames = []
|
||||
for filename in files:
|
||||
not_found = True
|
||||
for file in self.files:
|
||||
if file.filename == filename:
|
||||
not_found = False
|
||||
break
|
||||
if not_found:
|
||||
for opener in self.file_openers:
|
||||
if opener.can_open_file(filename):
|
||||
filenames.append((filename, opener.open_file))
|
||||
if filenames:
|
||||
self.thread_assist.spawn(self.__add_files_thread, filenames,
|
||||
thread=self.load_thread)
|
||||
|
||||
def __add_files_thread(self, filenames):
|
||||
"""Load the files."""
|
||||
files = []
|
||||
for filename, opener in filenames:
|
||||
try:
|
||||
files.extend(opener(filename))
|
||||
except:
|
||||
import traceback; traceback.print_exc()
|
||||
while files:
|
||||
self.thread_assist.proxy_to_main(self.__add_files_finished,
|
||||
files[:100])
|
||||
files = files[100:]
|
||||
|
||||
def __add_files_finished(self, files):
|
||||
"""Add loaded files to the tagger."""
|
||||
for file in files:
|
||||
self.files.append(file)
|
||||
album_id = file.metadata["musicbrainz_albumid"]
|
||||
if album_id:
|
||||
album = self.get_album_by_id(album_id)
|
||||
if not album:
|
||||
album = self.load_album(album_id)
|
||||
if album.loaded:
|
||||
self.match_files_to_album([file], album)
|
||||
else:
|
||||
self._move_to_album.append((file, album))
|
||||
if not file.parent:
|
||||
def add_files(self, filenames):
|
||||
"""Add files to the tagger."""
|
||||
self.log.debug(u"Adding files %r", filenames)
|
||||
for filename in filenames:
|
||||
filename = os.path.normpath(filename)
|
||||
if self.get_file_by_filename(filename):
|
||||
continue
|
||||
for opener in self.file_openers:
|
||||
file = opener.open_file(filename)
|
||||
if not file:
|
||||
continue
|
||||
file.move(self.unmatched_files)
|
||||
self.files.append(file)
|
||||
self.thread_assist.spawn(
|
||||
self.__load_file_thread, file, thread=self.load_thread)
|
||||
|
||||
def __load_file_thread(self, file):
|
||||
"""Load metadata from the file."""
|
||||
self.log.debug(u"Loading file %r", file.filename)
|
||||
file.load()
|
||||
self.thread_assist.proxy_to_main(self.__load_file_finished, file)
|
||||
|
||||
def __load_file_finished(self, file):
|
||||
"""Move loaded file to right album/cluster."""
|
||||
file.update()
|
||||
album_id = file.metadata["musicbrainz_albumid"]
|
||||
if album_id:
|
||||
album = self.load_album(album_id)
|
||||
self.move_files_to_album([file], album)
|
||||
|
||||
def add_directory(self, directory):
|
||||
"""Add all files from the directory ``directory`` to the tagger."""
|
||||
|
||||
Reference in New Issue
Block a user