Get album updates working for all file types
This commit is contained in:
parent
cf2f6096b5
commit
b372cde326
|
@ -2,3 +2,5 @@ from os import path
|
||||||
|
|
||||||
application_directory = '{}/.elodie'.format(path.expanduser('~'))
|
application_directory = '{}/.elodie'.format(path.expanduser('~'))
|
||||||
hash_db = '{}/hash.json'.format(application_directory)
|
hash_db = '{}/hash.json'.format(application_directory)
|
||||||
|
script_directory = path.dirname(path.dirname(path.abspath(__file__)))
|
||||||
|
exiftool_config = '%s/configs/ExifTool_config' % script_directory
|
||||||
|
|
|
@ -4,9 +4,12 @@ Media package that handles all video operations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# load modules
|
# load modules
|
||||||
from sys import argv
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from distutils.spawn import find_executable
|
||||||
|
from elodie import constants
|
||||||
from fractions import Fraction
|
from fractions import Fraction
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
import LatLon
|
import LatLon
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
|
@ -34,22 +37,18 @@ class Media(object):
|
||||||
'latitude_ref': 'Exif.GPSInfo.GPSLatitudeRef',
|
'latitude_ref': 'Exif.GPSInfo.GPSLatitudeRef',
|
||||||
'longitude': 'Exif.GPSInfo.GPSLongitude',
|
'longitude': 'Exif.GPSInfo.GPSLongitude',
|
||||||
'longitude_ref': 'Exif.GPSInfo.GPSLongitudeRef',
|
'longitude_ref': 'Exif.GPSInfo.GPSLongitudeRef',
|
||||||
'album': 'Xmp.elodie.album'
|
|
||||||
}
|
}
|
||||||
try:
|
self.exiftool_attributes = None
|
||||||
pyexiv2.xmp.register_namespace('https://github.com/jmathai/elodie/', 'elodie')
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
def get_album(self):
|
def get_album(self):
|
||||||
if(not self.is_valid()):
|
if(not self.is_valid()):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
exif = self.get_exif()
|
exiftool_attributes = self.get_exiftool_attributes()
|
||||||
try:
|
if('album' not in exiftool_attributes):
|
||||||
return exif[self.exif_map['album']].value
|
|
||||||
except KeyError:
|
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
return exiftool_attributes['album']
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Get the full path to the video.
|
Get the full path to the video.
|
||||||
|
@ -153,6 +152,30 @@ class Media(object):
|
||||||
|
|
||||||
return self.exif
|
return self.exif
|
||||||
|
|
||||||
|
def get_exiftool_attributes(self):
|
||||||
|
if(self.exiftool_attributes is not None):
|
||||||
|
return self.exiftool_attributes
|
||||||
|
|
||||||
|
exiftool = find_executable('exiftool')
|
||||||
|
if(exiftool is None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
source = self.source
|
||||||
|
process_output = subprocess.Popen(['%s "%s"' % (exiftool, source)], stdout=subprocess.PIPE, shell=True)
|
||||||
|
output = process_output.stdout.read()
|
||||||
|
|
||||||
|
album = None
|
||||||
|
album_regex = re.search('Album +: +(.+)', output)
|
||||||
|
if(album_regex is not None):
|
||||||
|
album = album_regex.group(1)
|
||||||
|
|
||||||
|
self.exiftool_attributes = {
|
||||||
|
'album': album
|
||||||
|
}
|
||||||
|
|
||||||
|
return self.exiftool_attributes
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Get the file extension as a lowercased string.
|
Get the file extension as a lowercased string.
|
||||||
|
|
||||||
|
@ -205,6 +228,31 @@ class Media(object):
|
||||||
|
|
||||||
return mimetype[0]
|
return mimetype[0]
|
||||||
|
|
||||||
|
"""
|
||||||
|
Set album for a photo
|
||||||
|
|
||||||
|
@param, name, string, Name of album
|
||||||
|
|
||||||
|
@returns, boolean
|
||||||
|
"""
|
||||||
|
def set_album(self, name):
|
||||||
|
if(name is None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
exiftool = find_executable('exiftool')
|
||||||
|
if(exiftool is None):
|
||||||
|
return False
|
||||||
|
|
||||||
|
source = self.source
|
||||||
|
exiftool_config = constants.exiftool_config
|
||||||
|
process_output = subprocess.Popen(['%s -config "%s" -xmp-elodie:Album="%s" "%s"' % (exiftool, exiftool_config, name, source)], stdout=subprocess.PIPE, shell=True)
|
||||||
|
streamdata = process_output.communicate()[0]
|
||||||
|
if(process_output.returncode != 0):
|
||||||
|
return False
|
||||||
|
|
||||||
|
os.remove('%s%s' % (source, '_original'))
|
||||||
|
return True
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def get_class_by_file(Media, _file, classes):
|
def get_class_by_file(Media, _file, classes):
|
||||||
extension = os.path.splitext(_file)[1][1:].lower()
|
extension = os.path.splitext(_file)[1][1:].lower()
|
||||||
|
|
|
@ -4,13 +4,15 @@ Photo package that handles all photo operations
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# load modules
|
# load modules
|
||||||
from sys import argv
|
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
from distutils.spawn import find_executable
|
||||||
|
from sys import argv
|
||||||
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import pyexiv2
|
import pyexiv2
|
||||||
import re
|
import re
|
||||||
|
import subprocess
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from media import Media
|
from media import Media
|
||||||
|
@ -48,25 +50,6 @@ class Photo(Media):
|
||||||
return re.search('(\d{2}:\d{2}.\d{2})', key).group(1).replace('.', ':')
|
return re.search('(\d{2}:\d{2}.\d{2})', key).group(1).replace('.', ':')
|
||||||
return None
|
return None
|
||||||
|
|
||||||
"""
|
|
||||||
Set album for a photo
|
|
||||||
|
|
||||||
@param, name, string, Name of album
|
|
||||||
|
|
||||||
@returns, boolean
|
|
||||||
"""
|
|
||||||
def set_album(self, name):
|
|
||||||
if(name is None):
|
|
||||||
return False
|
|
||||||
|
|
||||||
source = self.source
|
|
||||||
exif_metadata = pyexiv2.ImageMetadata(source)
|
|
||||||
exif_metadata.read()
|
|
||||||
|
|
||||||
exif_metadata['Xmp.elodie.album'] = name
|
|
||||||
|
|
||||||
exif_metadata.write()
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Set the date/time a photo was taken
|
Set the date/time a photo was taken
|
||||||
|
|
||||||
|
|
|
@ -137,7 +137,7 @@ class Video(Media):
|
||||||
"date_taken": self.get_date_taken(),
|
"date_taken": self.get_date_taken(),
|
||||||
"latitude": self.get_coordinate('latitude'),
|
"latitude": self.get_coordinate('latitude'),
|
||||||
"longitude": self.get_coordinate('longitude'),
|
"longitude": self.get_coordinate('longitude'),
|
||||||
"album": None,
|
"album": self.get_album(),
|
||||||
#"length": self.get_duration(),
|
#"length": self.get_duration(),
|
||||||
"mime_type": self.get_mimetype(),
|
"mime_type": self.get_mimetype(),
|
||||||
"base_name": os.path.splitext(os.path.basename(source))[0],
|
"base_name": os.path.splitext(os.path.basename(source))[0],
|
||||||
|
@ -146,18 +146,6 @@ class Video(Media):
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
"""
|
|
||||||
Set album for a photo
|
|
||||||
Not yet implemented
|
|
||||||
|
|
||||||
@param, name, string, Name of album
|
|
||||||
|
|
||||||
@returns, boolean
|
|
||||||
"""
|
|
||||||
def set_album(self, name):
|
|
||||||
if(name is None):
|
|
||||||
return False
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Set the date/time a photo was taken
|
Set the date/time a photo was taken
|
||||||
|
|
||||||
|
@ -270,7 +258,7 @@ class Video(Media):
|
||||||
metadata = self.get_metadata()
|
metadata = self.get_metadata()
|
||||||
temp_movie = None
|
temp_movie = None
|
||||||
with tempfile.NamedTemporaryFile() as temp_file:
|
with tempfile.NamedTemporaryFile() as temp_file:
|
||||||
temp_movie = '%s.%s' % (temp_file.name, metadata['extenseon'])
|
temp_movie = '%s.%s' % (temp_file.name, metadata['extension'])
|
||||||
|
|
||||||
# We need to block until the child process completes.
|
# We need to block until the child process completes.
|
||||||
# http://stackoverflow.com/a/5631819/1318758
|
# http://stackoverflow.com/a/5631819/1318758
|
||||||
|
|
Loading…
Reference in New Issue