2016-01-04 07:10:56 +01:00
|
|
|
# -*- coding: utf-8
|
|
|
|
# Project imports
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import tempfile
|
|
|
|
import time
|
2021-06-20 08:35:28 +02:00
|
|
|
from datetime import datetime
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__)))))
|
|
|
|
|
|
|
|
import helper
|
|
|
|
from elodie.media.media import Media
|
|
|
|
from elodie.media.video import Video
|
|
|
|
from elodie.media.audio import Audio
|
2020-01-14 08:04:33 +01:00
|
|
|
from elodie.external.pyexiftool import ExifTool
|
|
|
|
from elodie.dependencies import get_exiftool
|
|
|
|
from elodie import constants
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
os.environ['TZ'] = 'GMT'
|
|
|
|
|
2020-01-14 08:04:33 +01:00
|
|
|
def setup_module():
|
|
|
|
exiftool_addedargs = [
|
|
|
|
u'-config',
|
|
|
|
u'"{}"'.format(constants.exiftool_config)
|
|
|
|
]
|
|
|
|
ExifTool(executable_=get_exiftool(), addedargs=exiftool_addedargs).start()
|
|
|
|
|
|
|
|
def teardown_module():
|
|
|
|
ExifTool().terminate
|
|
|
|
|
2016-01-04 07:10:56 +01:00
|
|
|
def test_audio_extensions():
|
|
|
|
audio = Audio()
|
|
|
|
extensions = audio.extensions
|
|
|
|
|
|
|
|
assert 'm4a' in extensions
|
|
|
|
|
|
|
|
valid_extensions = Audio.get_valid_extensions()
|
|
|
|
|
|
|
|
assert extensions == valid_extensions, valid_extensions
|
|
|
|
|
|
|
|
def test_get_coordinate():
|
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
coordinate = audio.get_coordinate()
|
|
|
|
|
2016-11-08 08:20:11 +01:00
|
|
|
assert helper.isclose(coordinate, 29.758938), coordinate
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2017-11-15 08:14:26 +01:00
|
|
|
def test_get_camera_make():
|
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
coordinate = audio.get_camera_make()
|
|
|
|
|
|
|
|
assert coordinate is None, coordinate
|
|
|
|
|
|
|
|
def test_get_camera_model():
|
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
coordinate = audio.get_camera_model()
|
|
|
|
|
|
|
|
assert coordinate is None, coordinate
|
|
|
|
|
2016-01-04 07:10:56 +01:00
|
|
|
def test_get_coordinate_latitude():
|
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
coordinate = audio.get_coordinate('latitude')
|
|
|
|
|
2016-11-08 08:20:11 +01:00
|
|
|
assert helper.isclose(coordinate, 29.758938), coordinate
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
def test_get_coordinate_longitude():
|
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
coordinate = audio.get_coordinate('longitude')
|
|
|
|
|
2016-11-08 08:20:11 +01:00
|
|
|
assert helper.isclose(coordinate, -95.3677), coordinate
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2021-04-17 05:08:58 +02:00
|
|
|
def test_get_date_original():
|
2021-06-20 08:35:28 +02:00
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
date_created = audio.get_date_attribute(audio.date_original)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2021-06-20 08:35:28 +02:00
|
|
|
assert date_created.strftime('%Y-%m-%d %H:%M:%S') == '2016-01-03 21:23:39', date_created
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
def test_get_exiftool_attributes():
|
|
|
|
audio = Video(helper.get_file('audio.m4a'))
|
|
|
|
exif = audio.get_exiftool_attributes()
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
assert exif is not None, exif
|
2016-06-21 20:19:40 +02:00
|
|
|
assert exif is not False, exif
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
def test_is_valid():
|
|
|
|
audio = Audio(helper.get_file('audio.m4a'))
|
|
|
|
|
|
|
|
assert audio.is_valid()
|
|
|
|
|
|
|
|
def test_is_not_valid():
|
2021-06-20 08:35:28 +02:00
|
|
|
audio = Audio(helper.get_file('photo.png'))
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
assert not audio.is_valid()
|
|
|
|
|
2021-04-17 05:08:58 +02:00
|
|
|
def test_set_date_original():
|
2016-01-04 07:10:56 +01:00
|
|
|
temporary_folder, folder = helper.create_working_folder()
|
|
|
|
|
|
|
|
origin = '%s/audio.m4a' % folder
|
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin)
|
|
|
|
|
2021-06-20 19:51:21 +02:00
|
|
|
audio = Audio(origin)
|
2021-06-20 08:35:28 +02:00
|
|
|
date = datetime(2013, 9, 30, 7, 6, 5)
|
2021-06-27 07:00:04 +02:00
|
|
|
status = audio.set_date_original(date, origin)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
assert status == True, status
|
|
|
|
|
|
|
|
audio_new = Audio(origin)
|
2021-06-20 19:51:21 +02:00
|
|
|
metadata = audio_new.get_metadata(update_cache=True)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2021-06-20 19:51:21 +02:00
|
|
|
date_original = metadata['date_original']
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
shutil.rmtree(folder)
|
|
|
|
|
2021-06-20 08:35:28 +02:00
|
|
|
assert date_original == date, date_original
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
def test_set_location():
|
|
|
|
temporary_folder, folder = helper.create_working_folder()
|
|
|
|
|
|
|
|
origin = '%s/audio.m4a' % folder
|
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin)
|
|
|
|
|
|
|
|
audio = Audio(origin)
|
|
|
|
origin_metadata = audio.get_metadata()
|
|
|
|
|
2016-03-23 17:34:35 +01:00
|
|
|
# Verify that original audio has different location info that what we
|
|
|
|
# will be setting and checking
|
|
|
|
assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude']
|
|
|
|
assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude']
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2021-06-27 07:00:04 +02:00
|
|
|
status = audio.set_location(11.1111111111, 99.9999999999, origin)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
assert status == True, status
|
|
|
|
|
|
|
|
audio_new = Audio(origin)
|
2021-06-20 19:51:21 +02:00
|
|
|
metadata = audio_new.get_metadata(update_cache=True)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
shutil.rmtree(folder)
|
|
|
|
|
2016-03-23 17:34:35 +01:00
|
|
|
assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude']
|
|
|
|
assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude']
|
2016-01-04 07:10:56 +01:00
|
|
|
|
2016-06-21 20:19:40 +02:00
|
|
|
def test_set_location_minus():
|
|
|
|
temporary_folder, folder = helper.create_working_folder()
|
|
|
|
|
|
|
|
origin = '%s/audio.m4a' % folder
|
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin)
|
|
|
|
|
|
|
|
audio = Audio(origin)
|
|
|
|
origin_metadata = audio.get_metadata()
|
|
|
|
|
|
|
|
# Verify that original audio has different location info that what we
|
|
|
|
# will be setting and checking
|
|
|
|
assert not helper.isclose(origin_metadata['latitude'], 11.111111), origin_metadata['latitude']
|
|
|
|
assert not helper.isclose(origin_metadata['longitude'], 99.999999), origin_metadata['longitude']
|
|
|
|
|
2021-06-27 07:00:04 +02:00
|
|
|
status = audio.set_location(-11.111111, -99.999999, origin)
|
2016-06-21 20:19:40 +02:00
|
|
|
|
|
|
|
assert status == True, status
|
|
|
|
|
|
|
|
audio_new = Audio(origin)
|
2021-06-20 19:51:21 +02:00
|
|
|
metadata = audio_new.get_metadata(update_cache=True)
|
2016-06-21 20:19:40 +02:00
|
|
|
|
|
|
|
shutil.rmtree(folder)
|
|
|
|
|
|
|
|
assert helper.isclose(metadata['latitude'], -11.111111), metadata['latitude']
|
|
|
|
assert helper.isclose(metadata['longitude'], -99.999999), metadata['longitude']
|
|
|
|
|
2016-01-04 07:10:56 +01:00
|
|
|
def test_set_title():
|
|
|
|
temporary_folder, folder = helper.create_working_folder()
|
|
|
|
|
|
|
|
origin = '%s/audio.m4a' % folder
|
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin)
|
|
|
|
|
|
|
|
audio = Audio(origin)
|
|
|
|
origin_metadata = audio.get_metadata()
|
|
|
|
|
2021-06-27 07:00:04 +02:00
|
|
|
status = audio.set_title('my audio title', origin)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
assert status == True, status
|
|
|
|
|
|
|
|
audio_new = Audio(origin)
|
|
|
|
metadata = audio_new.get_metadata()
|
|
|
|
|
|
|
|
shutil.rmtree(folder)
|
|
|
|
|
|
|
|
assert metadata['title'] == 'my audio title', metadata['title']
|
|
|
|
|
|
|
|
def test_set_title_non_ascii():
|
|
|
|
temporary_folder, folder = helper.create_working_folder()
|
|
|
|
|
|
|
|
origin = '%s/audio.m4a' % folder
|
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin)
|
|
|
|
|
|
|
|
audio = Audio(origin)
|
|
|
|
origin_metadata = audio.get_metadata()
|
|
|
|
|
2016-11-08 08:31:36 +01:00
|
|
|
unicode_title = u'形声字 / 形聲字'
|
2021-06-27 07:00:04 +02:00
|
|
|
status = audio.set_title(unicode_title, origin)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
assert status == True, status
|
|
|
|
|
|
|
|
audio_new = Audio(origin)
|
2021-06-20 19:51:21 +02:00
|
|
|
metadata = audio_new.get_metadata(update_cache=True)
|
2016-01-04 07:10:56 +01:00
|
|
|
|
|
|
|
shutil.rmtree(folder)
|
|
|
|
|
2016-11-08 08:31:36 +01:00
|
|
|
assert metadata['title'] == unicode_title, metadata['title']
|