diff --git a/elodie/media/text.py b/elodie/media/text.py index a5b5ed5..7219591 100644 --- a/elodie/media/text.py +++ b/elodie/media/text.py @@ -119,7 +119,8 @@ class Text(Base): try: parsed_json = loads(first_line) - self.metadata_line = parsed_json + if isinstance(parsed_json, dict): + self.metadata_line = parsed_json except ValueError: if(constants.debug is True): print 'Could not parse JSON from first line: %s' % first_line diff --git a/elodie/tests/files/valid-with-numeric-header.txt b/elodie/tests/files/valid-with-numeric-header.txt new file mode 100644 index 0000000..a9f9d8b --- /dev/null +++ b/elodie/tests/files/valid-with-numeric-header.txt @@ -0,0 +1,4 @@ +1234567890 + + +See gh-98 diff --git a/elodie/tests/media/text_test.py b/elodie/tests/media/text_test.py index 2cc5bdd..3e558cd 100644 --- a/elodie/tests/media/text_test.py +++ b/elodie/tests/media/text_test.py @@ -72,6 +72,16 @@ def test_get_date_taken_from_invalid(): assert date_taken == expected_date_taken, date_taken +def test_get_metadata_with_numeric_header(): + # See gh-98 for details + text = Text(helper.get_file('valid-with-numeric-header.txt')) + + # Should not throw error + # TypeError: argument of type 'int' is not iterable + metadata = text.get_metadata() + + assert metadata['mime_type'] == 'text/plain' + def test_set_album(): temporary_folder, folder = helper.create_working_folder()