gh-98 Update calls to metadata to check that type is dict
This commit is contained in:
parent
1a1a50e656
commit
e27fb951bc
|
@ -73,7 +73,7 @@ class Base(object):
|
||||||
if(not self.is_valid()):
|
if(not self.is_valid()):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if(self.metadata is not None and update_cache is False):
|
if(isinstance(self.metadata, dict) and update_cache is False):
|
||||||
return self.metadata
|
return self.metadata
|
||||||
|
|
||||||
source = self.source
|
source = self.source
|
||||||
|
|
|
@ -33,7 +33,8 @@ class Text(Base):
|
||||||
|
|
||||||
def get_album(self):
|
def get_album(self):
|
||||||
self.parse_metadata_line()
|
self.parse_metadata_line()
|
||||||
if not self.metadata_line or 'album' not in self.metadata_line:
|
if(not isinstance(self.metadata_line, dict) or
|
||||||
|
'album' not in self.metadata_line):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.metadata_line['album']
|
return self.metadata_line['album']
|
||||||
|
@ -55,7 +56,8 @@ class Text(Base):
|
||||||
self.parse_metadata_line()
|
self.parse_metadata_line()
|
||||||
|
|
||||||
# We return the value if found in metadata
|
# We return the value if found in metadata
|
||||||
if self.metadata_line and 'date_taken' in self.metadata_line:
|
if(isinstance(self.metadata_line, dict) and
|
||||||
|
'date_taken' in self.metadata_line):
|
||||||
return time.gmtime(self.metadata_line['date_taken'])
|
return time.gmtime(self.metadata_line['date_taken'])
|
||||||
|
|
||||||
# If there's no date_taken in the metadata we return
|
# If there's no date_taken in the metadata we return
|
||||||
|
@ -73,7 +75,8 @@ class Text(Base):
|
||||||
def get_title(self):
|
def get_title(self):
|
||||||
self.parse_metadata_line()
|
self.parse_metadata_line()
|
||||||
|
|
||||||
if not self.metadata_line or 'title' not in self.metadata_line:
|
if(not isinstance(self.metadata_line, dict) or
|
||||||
|
'title' not in self.metadata_line):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
return self.metadata_line['title']
|
return self.metadata_line['title']
|
||||||
|
@ -104,7 +107,7 @@ class Text(Base):
|
||||||
return status
|
return status
|
||||||
|
|
||||||
def parse_metadata_line(self):
|
def parse_metadata_line(self):
|
||||||
if self.metadata_line:
|
if isinstance(self.metadata_line, dict):
|
||||||
return self.metadata_line
|
return self.metadata_line
|
||||||
|
|
||||||
source = self.source
|
source = self.source
|
||||||
|
@ -134,7 +137,7 @@ class Text(Base):
|
||||||
# Check if self.metadata_line is set and use that instead
|
# Check if self.metadata_line is set and use that instead
|
||||||
metadata_line = {}
|
metadata_line = {}
|
||||||
has_metadata = False
|
has_metadata = False
|
||||||
if self.metadata_line:
|
if isinstance(self.metadata_line, dict):
|
||||||
metadata_line = self.metadata_line
|
metadata_line = self.metadata_line
|
||||||
has_metadata = True
|
has_metadata = True
|
||||||
|
|
||||||
|
|
|
@ -390,7 +390,8 @@ class Video(Media):
|
||||||
# clobbers it
|
# clobbers it
|
||||||
source_media = Base.get_class_by_file(source, [self.__class__])
|
source_media = Base.get_class_by_file(source, [self.__class__])
|
||||||
source_metadata = source_media.get_metadata()
|
source_metadata = source_media.get_metadata()
|
||||||
if(source_metadata['album'] is not None):
|
if(isinstance(source_metadata, dict) and
|
||||||
|
source_metadata['album'] is not None):
|
||||||
check_media.set_album(source_metadata['album'])
|
check_media.set_album(source_metadata['album'])
|
||||||
|
|
||||||
# Copy file information from original source to temporary file
|
# Copy file information from original source to temporary file
|
||||||
|
|
|
@ -57,6 +57,21 @@ def test_get_date_taken():
|
||||||
|
|
||||||
assert date_taken == helper.time_convert((2016, 4, 7, 11, 15, 26, 3, 98, 0)), date_taken
|
assert date_taken == helper.time_convert((2016, 4, 7, 11, 15, 26, 3, 98, 0)), date_taken
|
||||||
|
|
||||||
|
def test_get_date_taken_from_invalid():
|
||||||
|
origin = helper.get_file('valid-without-header.txt')
|
||||||
|
text = Text(origin)
|
||||||
|
text.get_metadata()
|
||||||
|
|
||||||
|
date_taken = text.get_date_taken()
|
||||||
|
|
||||||
|
seconds_since_epoch = min(
|
||||||
|
os.path.getmtime(origin),
|
||||||
|
os.path.getctime(origin)
|
||||||
|
)
|
||||||
|
expected_date_taken = time.gmtime(seconds_since_epoch)
|
||||||
|
|
||||||
|
assert date_taken == expected_date_taken, date_taken
|
||||||
|
|
||||||
def test_set_album():
|
def test_set_album():
|
||||||
temporary_folder, folder = helper.create_working_folder()
|
temporary_folder, folder = helper.create_working_folder()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue