Merge pull request #90 from jmathai/video-album-title

gh-89 Reapply album to video when updating EXIF via avmetareadwrite
Add failing test for when setting album then title reverts album
This commit is contained in:
Jaisen Mathai 2016-03-14 21:46:42 -07:00
commit 3385c3cc9c
4 changed files with 50 additions and 2 deletions

View File

@ -43,8 +43,7 @@ class Media(object):
'longitude': 'Exif.GPSInfo.GPSLongitude',
'longitude_ref': 'Exif.GPSInfo.GPSLongitudeRef',
}
self.exiftool_attributes = None
self.metadata = None
self.reset_cache()
def get_album(self):
"""Get album from EXIF
@ -211,6 +210,10 @@ class Media(object):
return exiftool_attributes['title']
def reset_cache(self):
self.exiftool_attributes = None
self.metadata = None
def set_album(self, name):
"""Set album for a photo
@ -247,6 +250,7 @@ class Media(object):
os.remove(exiftool_backup_file)
self.set_metadata(album=name)
self.reset_cache()
return True
def set_album_from_folder(self):

View File

@ -160,6 +160,7 @@ class Photo(Media):
exif_metadata[key] = pyexiv2.ExifTag(key, time)
exif_metadata.write()
self.reset_cache()
return True
def set_location(self, latitude, longitude):
@ -182,6 +183,7 @@ class Photo(Media):
exif_metadata['Exif.GPSInfo.GPSLongitudeRef'] = pyexiv2.ExifTag('Exif.GPSInfo.GPSLongitudeRef', 'E' if longitude >= 0 else 'W') # noqa
exif_metadata.write()
self.reset_cache()
return True
def set_title(self, title):
@ -200,4 +202,5 @@ class Photo(Media):
exif_metadata['Xmp.dc.title'] = title
exif_metadata.write()
self.reset_cache()
return True

View File

@ -196,6 +196,7 @@ class Video(Media):
)
)
self.reset_cache()
return result
def set_location(self, latitude, longitude):
@ -210,6 +211,7 @@ class Video(Media):
return False
result = self.__update_using_plist(latitude=latitude, longitude=longitude) # noqa
self.reset_cache()
return result
def set_title(self, title):
@ -222,6 +224,7 @@ class Video(Media):
return False
result = self.__update_using_plist(title=title)
self.reset_cache()
return result
def __update_using_plist(self, **kwargs):
@ -390,6 +393,13 @@ class Video(Media):
if(constants.debug is True):
print 'Something went wrong updating video metadata'
return False
# gh-89 Before we wrap up we check if an album was previously set
# and if so we re-apply that album because avmetareadwrite clobbers it
source_media = Media.get_class_by_file(source, [self.__class__])
source_metadata = source_media.get_metadata()
if('album' in source_metadata and source_metadata['album'] is not None):
check_media.set_album(source_metadata['album'])
# Copy file information from original source to temporary file
# before copying back over

View File

@ -339,3 +339,34 @@ def test_process_file_with_album_and_title_and_location():
assert origin_checksum is not None, origin_checksum
assert origin_checksum == destination_checksum, destination_checksum
assert helper.path_tz_fix(os.path.join('2015-12-Dec','Test Album','2015-12-05_00-59-26-photo-some-title.jpg')) in destination, destination
# gh-89 (setting album then title reverts album)
def test_process_video_with_album_then_title():
if not can_edit_exif():
raise SkipTest('avmetareadwrite executable not found')
filesystem = FileSystem()
temporary_folder, folder = helper.create_working_folder()
origin = os.path.join(folder,'movie.mov')
shutil.copyfile(helper.get_file('video.mov'), origin)
origin_checksum = helper.checksum(origin)
media = Video(origin)
media.set_album('test_album')
media.set_title('test_title')
destination = filesystem.process_file(origin, temporary_folder, media, allowDuplicate=True)
destination_checksum = helper.checksum(destination)
shutil.rmtree(folder)
shutil.rmtree(os.path.dirname(os.path.dirname(destination)))
assert origin_checksum is not None, origin_checksum
assert origin_checksum != destination_checksum, destination_checksum
assert helper.path_tz_fix(os.path.join('2015-01-Jan','test_album','2015-01-19_12-45-11-movie-test_title.mov')) in destination, destination
def can_edit_exif():
video = Video()
return video.get_avmetareadwrite()