1
|
|
|
# -*- coding: utf-8 |
2
|
|
|
# Project imports |
3
|
|
|
from __future__ import print_function |
4
|
|
|
import os |
5
|
|
|
import sys |
6
|
|
|
|
7
|
|
|
import shutil |
8
|
|
|
import tempfile |
9
|
|
|
import time |
10
|
|
|
import datetime |
11
|
|
|
|
12
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))))) |
13
|
|
|
sys.path.insert(0, os.path.abspath(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))) |
14
|
|
|
|
15
|
|
|
import helper |
16
|
|
|
from elodie.media.media import Media |
17
|
|
|
from elodie.media.video import Video |
18
|
|
|
from elodie.media.audio import Audio |
19
|
|
|
from elodie.external.pyexiftool import ExifTool |
20
|
|
|
from elodie.dependencies import get_exiftool |
21
|
|
|
from elodie import constants |
22
|
|
|
|
23
|
|
|
os.environ['TZ'] = 'GMT' |
24
|
|
|
|
25
|
|
|
def setup_module(): |
26
|
|
|
exiftool_addedargs = [ |
27
|
|
|
u'-config', |
28
|
|
|
u'"{}"'.format(constants.exiftool_config) |
29
|
|
|
] |
30
|
|
|
ExifTool(executable_=get_exiftool(), addedargs=exiftool_addedargs).start() |
31
|
|
|
|
32
|
|
|
def teardown_module(): |
33
|
|
|
ExifTool().terminate |
34
|
|
|
|
35
|
|
|
def test_audio_extensions(): |
36
|
|
|
audio = Audio() |
37
|
|
|
extensions = audio.extensions |
38
|
|
|
|
39
|
|
|
assert 'm4a' in extensions |
40
|
|
|
|
41
|
|
|
valid_extensions = Audio.get_valid_extensions() |
42
|
|
|
|
43
|
|
|
assert extensions == valid_extensions, valid_extensions |
44
|
|
|
|
45
|
|
|
def test_get_coordinate(): |
46
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
47
|
|
|
coordinate = audio.get_coordinate() |
48
|
|
|
|
49
|
|
|
assert helper.isclose(coordinate, 29.758938), coordinate |
50
|
|
|
|
51
|
|
|
def test_get_camera_make(): |
52
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
53
|
|
|
coordinate = audio.get_camera_make() |
54
|
|
|
|
55
|
|
|
assert coordinate is None, coordinate |
56
|
|
|
|
57
|
|
|
def test_get_camera_model(): |
58
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
59
|
|
|
coordinate = audio.get_camera_model() |
60
|
|
|
|
61
|
|
|
assert coordinate is None, coordinate |
62
|
|
|
|
63
|
|
|
def test_get_coordinate_latitude(): |
64
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
65
|
|
|
coordinate = audio.get_coordinate('latitude') |
66
|
|
|
|
67
|
|
|
assert helper.isclose(coordinate, 29.758938), coordinate |
68
|
|
|
|
69
|
|
|
def test_get_coordinate_longitude(): |
70
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
71
|
|
|
coordinate = audio.get_coordinate('longitude') |
72
|
|
|
|
73
|
|
|
assert helper.isclose(coordinate, -95.3677), coordinate |
74
|
|
|
|
75
|
|
|
def test_get_date_taken(): |
76
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
77
|
|
|
date_taken = audio.get_date_taken() |
78
|
|
|
|
79
|
|
|
assert date_taken == (2016, 1, 4, 5, 28, 15, 0, 4, 0), date_taken |
80
|
|
|
|
81
|
|
|
def test_get_exiftool_attributes(): |
82
|
|
|
audio = Video(helper.get_file('audio.m4a')) |
83
|
|
|
exif = audio.get_exiftool_attributes() |
84
|
|
|
|
85
|
|
|
assert exif is not None, exif |
86
|
|
|
assert exif is not False, exif |
87
|
|
|
|
88
|
|
|
def test_is_valid(): |
89
|
|
|
audio = Audio(helper.get_file('audio.m4a')) |
90
|
|
|
|
91
|
|
|
assert audio.is_valid() |
92
|
|
|
|
93
|
|
|
def test_is_not_valid(): |
94
|
|
|
audio = Audio(helper.get_file('text.txt')) |
95
|
|
|
|
96
|
|
|
assert not audio.is_valid() |
97
|
|
|
|
98
|
|
View Code Duplication |
def test_set_date_taken(): |
|
|
|
|
99
|
|
|
temporary_folder, folder = helper.create_working_folder() |
100
|
|
|
|
101
|
|
|
origin = '%s/audio.m4a' % folder |
102
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin) |
103
|
|
|
|
104
|
|
|
audio = Audio(origin) |
105
|
|
|
status = audio.set_date_taken(datetime.datetime(2013, 9, 30, 7, 6, 5)) |
106
|
|
|
|
107
|
|
|
assert status == True, status |
108
|
|
|
|
109
|
|
|
audio_new = Audio(origin) |
110
|
|
|
metadata = audio_new.get_metadata() |
111
|
|
|
|
112
|
|
|
date_taken = metadata['date_taken'] |
113
|
|
|
|
114
|
|
|
shutil.rmtree(folder) |
115
|
|
|
|
116
|
|
|
assert date_taken == (2013, 9, 30, 7, 6, 5, 0, 273, 0), metadata['date_taken'] |
117
|
|
|
|
118
|
|
View Code Duplication |
def test_set_location(): |
|
|
|
|
119
|
|
|
temporary_folder, folder = helper.create_working_folder() |
120
|
|
|
|
121
|
|
|
origin = '%s/audio.m4a' % folder |
122
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin) |
123
|
|
|
|
124
|
|
|
audio = Audio(origin) |
125
|
|
|
origin_metadata = audio.get_metadata() |
126
|
|
|
|
127
|
|
|
# Verify that original audio has different location info that what we |
128
|
|
|
# will be setting and checking |
129
|
|
|
assert not helper.isclose(origin_metadata['latitude'], 11.1111111111), origin_metadata['latitude'] |
130
|
|
|
assert not helper.isclose(origin_metadata['longitude'], 99.9999999999), origin_metadata['longitude'] |
131
|
|
|
|
132
|
|
|
status = audio.set_location(11.1111111111, 99.9999999999) |
133
|
|
|
|
134
|
|
|
assert status == True, status |
135
|
|
|
|
136
|
|
|
audio_new = Audio(origin) |
137
|
|
|
metadata = audio_new.get_metadata() |
138
|
|
|
|
139
|
|
|
shutil.rmtree(folder) |
140
|
|
|
|
141
|
|
|
assert helper.isclose(metadata['latitude'], 11.1111111111), metadata['latitude'] |
142
|
|
|
assert helper.isclose(metadata['longitude'], 99.9999999999), metadata['longitude'] |
143
|
|
|
|
144
|
|
View Code Duplication |
def test_set_location_minus(): |
|
|
|
|
145
|
|
|
temporary_folder, folder = helper.create_working_folder() |
146
|
|
|
|
147
|
|
|
origin = '%s/audio.m4a' % folder |
148
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin) |
149
|
|
|
|
150
|
|
|
audio = Audio(origin) |
151
|
|
|
origin_metadata = audio.get_metadata() |
152
|
|
|
|
153
|
|
|
# Verify that original audio has different location info that what we |
154
|
|
|
# will be setting and checking |
155
|
|
|
assert not helper.isclose(origin_metadata['latitude'], 11.111111), origin_metadata['latitude'] |
156
|
|
|
assert not helper.isclose(origin_metadata['longitude'], 99.999999), origin_metadata['longitude'] |
157
|
|
|
|
158
|
|
|
status = audio.set_location(-11.111111, -99.999999) |
159
|
|
|
|
160
|
|
|
assert status == True, status |
161
|
|
|
|
162
|
|
|
audio_new = Audio(origin) |
163
|
|
|
metadata = audio_new.get_metadata() |
164
|
|
|
|
165
|
|
|
shutil.rmtree(folder) |
166
|
|
|
|
167
|
|
|
assert helper.isclose(metadata['latitude'], -11.111111), metadata['latitude'] |
168
|
|
|
assert helper.isclose(metadata['longitude'], -99.999999), metadata['longitude'] |
169
|
|
|
|
170
|
|
View Code Duplication |
def test_set_title(): |
|
|
|
|
171
|
|
|
temporary_folder, folder = helper.create_working_folder() |
172
|
|
|
|
173
|
|
|
origin = '%s/audio.m4a' % folder |
174
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin) |
175
|
|
|
|
176
|
|
|
audio = Audio(origin) |
177
|
|
|
origin_metadata = audio.get_metadata() |
178
|
|
|
|
179
|
|
|
status = audio.set_title('my audio title') |
180
|
|
|
|
181
|
|
|
assert status == True, status |
182
|
|
|
|
183
|
|
|
audio_new = Audio(origin) |
184
|
|
|
metadata = audio_new.get_metadata() |
185
|
|
|
|
186
|
|
|
shutil.rmtree(folder) |
187
|
|
|
|
188
|
|
|
assert metadata['title'] == 'my audio title', metadata['title'] |
189
|
|
|
|
190
|
|
View Code Duplication |
def test_set_title_non_ascii(): |
|
|
|
|
191
|
|
|
temporary_folder, folder = helper.create_working_folder() |
192
|
|
|
|
193
|
|
|
origin = '%s/audio.m4a' % folder |
194
|
|
|
shutil.copyfile(helper.get_file('audio.m4a'), origin) |
195
|
|
|
|
196
|
|
|
audio = Audio(origin) |
197
|
|
|
origin_metadata = audio.get_metadata() |
198
|
|
|
|
199
|
|
|
unicode_title = u'形声字 / 形聲字' |
200
|
|
|
status = audio.set_title(unicode_title) |
201
|
|
|
|
202
|
|
|
assert status == True, status |
203
|
|
|
|
204
|
|
|
audio_new = Audio(origin) |
205
|
|
|
metadata = audio_new.get_metadata() |
206
|
|
|
|
207
|
|
|
shutil.rmtree(folder) |
208
|
|
|
|
209
|
|
|
assert metadata['title'] == unicode_title, metadata['title'] |
210
|
|
|
|