mirror of
https://github.com/arsenetar/dupeguru.git
synced 2026-01-22 22:51:39 +00:00
Refactoring: Moved some code from app.DupeGuru to fs.File.
Moved DupeGuru._get_display_info() to File.get_display_info(). This method used none of the app's global state or methods and had nothing to do there.
This commit is contained in:
@@ -5,10 +5,7 @@
|
||||
# which should be included with this package. The terms are also available at
|
||||
# http://www.hardcoded.net/licenses/bsd_license
|
||||
|
||||
from hscommon.util import format_size, format_time
|
||||
|
||||
from core.app import (DupeGuru as DupeGuruBase, format_timestamp,
|
||||
format_perc, format_words, format_dupe_count)
|
||||
from core.app import DupeGuru as DupeGuruBase
|
||||
from . import prioritize
|
||||
from . import __appname__
|
||||
from . import scanner, fs
|
||||
@@ -24,48 +21,6 @@ class DupeGuru(DupeGuruBase):
|
||||
self.scanner = scanner.ScannerME()
|
||||
self.directories.fileclasses = [fs.MusicFile]
|
||||
|
||||
def _get_display_info(self, dupe, group, delta):
|
||||
size = dupe.size
|
||||
duration = dupe.duration
|
||||
bitrate = dupe.bitrate
|
||||
samplerate = dupe.samplerate
|
||||
mtime = dupe.mtime
|
||||
m = group.get_match_of(dupe)
|
||||
if m:
|
||||
percentage = m.percentage
|
||||
dupe_count = 0
|
||||
if delta:
|
||||
r = group.ref
|
||||
size -= r.size
|
||||
duration -= r.duration
|
||||
bitrate -= r.bitrate
|
||||
samplerate -= r.samplerate
|
||||
mtime -= r.mtime
|
||||
else:
|
||||
percentage = group.percentage
|
||||
dupe_count = len(group.dupes)
|
||||
dupe_folder_path = getattr(dupe, 'display_folder_path', dupe.folder_path)
|
||||
return {
|
||||
'name': dupe.name,
|
||||
'folder_path': str(dupe_folder_path),
|
||||
'size': format_size(size, 2, 2, False),
|
||||
'duration': format_time(duration, with_hours=False),
|
||||
'bitrate': str(bitrate),
|
||||
'samplerate': str(samplerate),
|
||||
'extension': dupe.extension,
|
||||
'mtime': format_timestamp(mtime,delta and m),
|
||||
'title': dupe.title,
|
||||
'artist': dupe.artist,
|
||||
'album': dupe.album,
|
||||
'genre': dupe.genre,
|
||||
'year': dupe.year,
|
||||
'track': str(dupe.track),
|
||||
'comment': dupe.comment,
|
||||
'percentage': format_perc(percentage),
|
||||
'words': format_words(dupe.words) if hasattr(dupe, 'words') else '',
|
||||
'dupe_count': format_dupe_count(dupe_count),
|
||||
}
|
||||
|
||||
def _get_dupe_sort_key(self, dupe, get_group, key, delta):
|
||||
if key == 'folder_path':
|
||||
dupe_folder_path = getattr(dupe, 'display_folder_path', dupe.folder_path)
|
||||
|
||||
@@ -7,7 +7,9 @@
|
||||
# http://www.hardcoded.net/licenses/bsd_license
|
||||
|
||||
from hsaudiotag import auto
|
||||
from hscommon.util import get_file_ext
|
||||
from hscommon.util import get_file_ext, format_size, format_time
|
||||
|
||||
from core.app import format_timestamp, format_perc, format_words, format_dupe_count
|
||||
from core import fs
|
||||
|
||||
TAG_FIELDS = {'audiosize', 'duration', 'bitrate', 'samplerate', 'title', 'artist',
|
||||
@@ -36,6 +38,48 @@ class MusicFile(fs.File):
|
||||
return False
|
||||
return get_file_ext(path[-1]) in auto.EXT2CLASS
|
||||
|
||||
def get_display_info(self, group, delta):
|
||||
size = self.size
|
||||
duration = self.duration
|
||||
bitrate = self.bitrate
|
||||
samplerate = self.samplerate
|
||||
mtime = self.mtime
|
||||
m = group.get_match_of(self)
|
||||
if m:
|
||||
percentage = m.percentage
|
||||
dupe_count = 0
|
||||
if delta:
|
||||
r = group.ref
|
||||
size -= r.size
|
||||
duration -= r.duration
|
||||
bitrate -= r.bitrate
|
||||
samplerate -= r.samplerate
|
||||
mtime -= r.mtime
|
||||
else:
|
||||
percentage = group.percentage
|
||||
dupe_count = len(group.dupes)
|
||||
dupe_folder_path = getattr(self, 'display_folder_path', self.folder_path)
|
||||
return {
|
||||
'name': self.name,
|
||||
'folder_path': str(dupe_folder_path),
|
||||
'size': format_size(size, 2, 2, False),
|
||||
'duration': format_time(duration, with_hours=False),
|
||||
'bitrate': str(bitrate),
|
||||
'samplerate': str(samplerate),
|
||||
'extension': self.extension,
|
||||
'mtime': format_timestamp(mtime,delta and m),
|
||||
'title': self.title,
|
||||
'artist': self.artist,
|
||||
'album': self.album,
|
||||
'genre': self.genre,
|
||||
'year': self.year,
|
||||
'track': str(self.track),
|
||||
'comment': self.comment,
|
||||
'percentage': format_perc(percentage),
|
||||
'words': format_words(self.words) if hasattr(self, 'words') else '',
|
||||
'dupe_count': format_dupe_count(dupe_count),
|
||||
}
|
||||
|
||||
def _get_md5partial_offset_and_size(self):
|
||||
f = auto.File(str(self.path))
|
||||
return (f.audio_offset, f.audio_size)
|
||||
|
||||
Reference in New Issue
Block a user