Skip to content

Commit 61c2e1f

Browse files
committed
Add option to ignore disc# for single disc albums (#3297)
1 parent 3e3047a commit 61c2e1f

File tree

5 files changed

+25
-8
lines changed

5 files changed

+25
-8
lines changed

data/interfaces/default/config.html

+6-3
Original file line numberDiff line numberDiff line change
@@ -1370,17 +1370,20 @@ <h1 class="clearfix"><i class="fa fa-gear"></i> Settings</h1>
13701370
<div class="row">
13711371
<label>File Format</label>
13721372
<input type="text" name="file_format" value="${config['file_format']}" size="43">
1373-
<small>Use: $Disc/$disc (disc #), $Track/$track (track #), $Title/$title, $Artist/$artist, $Album/$album and $Year/$year. Put optional variables in curly braces, use single-quote marks to escape curly braces literally ('{', '}').</small>
1373+
<small>Use: In addition to the above, there is also $Title/$title (track title), $Track (track #), $Disc (disc #), $DiscTotal.</small>
13741374
</div>
1375-
<div class="checkbox row clearfix">
1375+
<div class="checkbox row left clearfix nopad">
13761376
<input type="checkbox" name="file_underscores" id="file_underscores" value="1" ${config['file_underscores']}/><label>Use underscores instead of spaces</label>
13771377
</div>
1378+
<div class="checkbox row left clearfix nopad">
1379+
<input type="checkbox" name="rename_single_disc_ignore" id="rename_single_disc_ignore" value="1" ${config['rename_single_disc_ignore']}/><label>Don't include disc# for single disc albums</label>
1380+
</div>
13781381
</fieldset>
13791382

13801383
<fieldset>
13811384
<legend>Re-Encoding Options</legend>
13821385
<small class="heading"><i class="fa fa-info-circle"></i> Note: this option requires the lame, ffmpeg or xld encoder</small>
1383-
<div class="checkbox row clearfix">
1386+
<div class="checkbox row left clearfix nopad">
13841387
<input type="checkbox" name="music_encoder" id="music_encoder" value="1" ${config['music_encoder']}/><label>Re-encode downloads during postprocessing</label>
13851388
</div>
13861389
<div id="encoderoptions" class="row clearfix checkbox">

headphones/config.py

+1
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ def __repr__(self):
240240
'QBITTORRENT_PASSWORD': (str, 'QBitTorrent', ''),
241241
'QBITTORRENT_USERNAME': (str, 'QBitTorrent', ''),
242242
'RENAME_FILES': (int, 'General', 0),
243+
'RENAME_SINGLE_DISC_IGNORE': (int, 'General', 0),
243244
'RENAME_UNPROCESSED': (bool_int, 'General', 1),
244245
'RENAME_FROZEN': (bool_int, 'General', 1),
245246
'REPLACE_EXISTING_FOLDERS': (int, 'General', 0),

headphones/metadata.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ class Vars:
7979
Metadata $variable names (only ones set explicitly by headphones).
8080
"""
8181
DISC = '$Disc'
82+
DISC_TOTAL = '$DiscTotal',
8283
TRACK = '$Track'
8384
TITLE = '$Title'
8485
ARTIST = '$Artist'
@@ -171,7 +172,7 @@ def _lower(s):
171172
return None
172173

173174

174-
def file_metadata(path, release):
175+
def file_metadata(path, release, single_disc_ignore=False):
175176
# type: (str,sqlite3.Row)->Tuple[Mapping[str,str],bool]
176177
"""
177178
Prepare metadata dictionary for path substitution, based on file name,
@@ -194,7 +195,13 @@ def file_metadata(path, release):
194195
_row_to_dict(release, res)
195196

196197
date, year = _date_year(release)
197-
if not f.disc:
198+
199+
if not f.disctotal or (f.disctotal == 1 and single_disc_ignore):
200+
disc_total = ''
201+
else:
202+
disc_total = '%d' % f.disctotal
203+
204+
if not f.disc or (f.disctotal == 1 and single_disc_ignore):
198205
disc_number = ''
199206
else:
200207
disc_number = '%d' % f.disc
@@ -226,6 +233,7 @@ def file_metadata(path, release):
226233
album_title = release['AlbumTitle']
227234
override_values = {
228235
Vars.DISC: disc_number,
236+
Vars.DISC_TOTAL: disc_total,
229237
Vars.TRACK: track_number,
230238
Vars.TITLE: title,
231239
Vars.ARTIST: artist_name,

headphones/postprocessor.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,11 @@ def renameFiles(albumpath, downloaded_track_list, release):
10851085
# Until tagging works better I'm going to rely on the already provided metadata
10861086

10871087
for downloaded_track in downloaded_track_list:
1088-
md, from_metadata = metadata.file_metadata(downloaded_track, release)
1088+
md, from_metadata = metadata.file_metadata(
1089+
downloaded_track,
1090+
release,
1091+
headphones.CONFIG.RENAME_SINGLE_DISC_IGNORE
1092+
)
10891093
if md is None:
10901094
# unable to parse media file, skip file
10911095
continue

headphones/webserve.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1268,6 +1268,7 @@ def config(self):
12681268
"cue_split_shntool_path": headphones.CONFIG.CUE_SPLIT_SHNTOOL_PATH,
12691269
"move_files": checked(headphones.CONFIG.MOVE_FILES),
12701270
"rename_files": checked(headphones.CONFIG.RENAME_FILES),
1271+
"rename_single_disc_ignore": checked(headphones.CONFIG.RENAME_SINGLE_DISC_IGNORE),
12711272
"correct_metadata": checked(headphones.CONFIG.CORRECT_METADATA),
12721273
"cleanup_files": checked(headphones.CONFIG.CLEANUP_FILES),
12731274
"keep_nfo": checked(headphones.CONFIG.KEEP_NFO),
@@ -1460,8 +1461,8 @@ def configUpdate(self, **kwargs):
14601461
"use_waffles", "use_rutracker",
14611462
"use_orpheus", "use_redacted", "redacted_use_fltoken", "preferred_bitrate_allow_lossless",
14621463
"detect_bitrate", "ignore_clean_releases", "freeze_db", "cue_split", "move_files",
1463-
"rename_files", "correct_metadata", "cleanup_files", "keep_nfo", "add_album_art",
1464-
"embed_album_art", "embed_lyrics",
1464+
"rename_files", "rename_single_disc_ignore", "correct_metadata", "cleanup_files",
1465+
"keep_nfo", "add_album_art", "embed_album_art", "embed_lyrics",
14651466
"replace_existing_folders", "keep_original_folder", "file_underscores",
14661467
"include_extras", "official_releases_only",
14671468
"wait_until_release_date", "autowant_upcoming", "autowant_all",

0 commit comments

Comments
 (0)