gh-98 Update calls to metadata to check that type is dict

This commit is contained in:
Jaisen Mathai 2016-04-15 14:54:15 -07:00
parent 1a1a50e656
commit e27fb951bc
4 changed files with 26 additions and 7 deletions

View File

@ -73,7 +73,7 @@ class Base(object):
if(not self.is_valid()):
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
source = self.source

View File

@ -33,7 +33,8 @@ class Text(Base):
def get_album(self):
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 self.metadata_line['album']
@ -55,7 +56,8 @@ class Text(Base):
self.parse_metadata_line()
# 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'])
# If there's no date_taken in the metadata we return
@ -73,7 +75,8 @@ class Text(Base):
def get_title(self):
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 self.metadata_line['title']
@ -104,7 +107,7 @@ class Text(Base):
return status
def parse_metadata_line(self):
if self.metadata_line:
if isinstance(self.metadata_line, dict):
return self.metadata_line
source = self.source
@ -134,7 +137,7 @@ class Text(Base):
# Check if self.metadata_line is set and use that instead
metadata_line = {}
has_metadata = False
if self.metadata_line:
if isinstance(self.metadata_line, dict):
metadata_line = self.metadata_line
has_metadata = True

View File

@ -390,7 +390,8 @@ class Video(Media):
# clobbers it
source_media = Base.get_class_by_file(source, [self.__class__])
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'])
# Copy file information from original source to temporary file

View 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
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():
temporary_folder, folder = helper.create_working_folder()