PICARD-1892: Fixed deleting totaldiscs / totaltracks from Vorbis tags

Deleting failed if the file only contained disctotal or tracktotal tags, but not also totaldiscs or totaltracks.
This commit is contained in:
Philipp Wolfer
2020-07-20 08:26:41 +02:00
parent 048651fa41
commit dd2acaf6ee
2 changed files with 20 additions and 2 deletions

View File

@@ -327,7 +327,7 @@ class VCommentFile(File):
existing_tags.remove(item)
tags[real_name] = existing_tags
else:
if tag in ('totaldiscs', 'totaltracks'):
if tag in ('totaldiscs', 'totaltracks') and tag in tags:
# both tag and real_name are to be deleted in this case
del tags[tag]
del tags[real_name]

View File

@@ -2,7 +2,7 @@
#
# Picard, the next-generation MusicBrainz tagger
#
# Copyright (C) 2019 Philipp Wolfer
# Copyright (C) 2019-2020 Philipp Wolfer
# Copyright (C) 2020 Laurent Monin
#
# This program is free software; you can redistribute it and/or
@@ -156,6 +156,24 @@ class CommonVorbisTests:
self.assertTrue(self.format.supports_tag('lyrics:foó'))
self.assertTrue(self.format.supports_tag('comment:foó'))
@skipUnlessTestfile
def test_delete_totaldiscs_totaltracks(self):
# Create a test file that contains only disctotal / tracktotal,
# but not totaldiscs and totaltracks
save_raw(self.filename, {
'disctotal': '3',
'tracktotal': '2',
})
metadata = Metadata()
del metadata['totaldiscs']
del metadata['totaltracks']
save_metadata(self.filename, metadata)
loaded_metadata = load_raw(self.filename)
self.assertNotIn('disctotal', loaded_metadata)
self.assertNotIn('totaldiscs', loaded_metadata)
self.assertNotIn('tracktotal', loaded_metadata)
self.assertNotIn('totaltracks', loaded_metadata)
class FLACTest(CommonVorbisTests.VorbisTestCase):
testfile = 'test.flac'