2015-10-07 07:35:11 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from elodie import arguments
|
2015-10-10 09:02:53 +02:00
|
|
|
from elodie.media.photo import Photo
|
2015-10-07 07:35:11 +02:00
|
|
|
from elodie.media.video import Video
|
|
|
|
from elodie.filesystem import FileSystem
|
2015-10-10 09:02:53 +02:00
|
|
|
from elodie.localstorage import Db
|
2015-10-07 07:35:11 +02:00
|
|
|
|
2015-10-14 05:26:55 +02:00
|
|
|
def help():
|
|
|
|
return """
|
|
|
|
usage: ./import.py --type=photo --source=/path/to/photos --destination=/path/to/destination
|
|
|
|
|
|
|
|
--type Valid values are 'photo' or 'video'. Only files of *type* are imported.
|
|
|
|
--file Full path to a photo or video to be imported. The --type argument should match the file type of the file.
|
|
|
|
@TODO: Automatically determine *type* from *file*
|
|
|
|
--source Full path to a directory which will be recursively crawled for files of *type*.
|
|
|
|
--destination Full path to a directory where organized photos will be placed.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def parse_arguments(args):
|
|
|
|
config = {
|
|
|
|
'type': 'photo',
|
|
|
|
'file': None,
|
|
|
|
'source': None,
|
|
|
|
'destination': None
|
|
|
|
}
|
|
|
|
|
|
|
|
if('destination' not in args):
|
|
|
|
help()
|
|
|
|
sys.exit(2)
|
|
|
|
|
|
|
|
config.update(args)
|
|
|
|
return config
|
2015-10-10 09:02:53 +02:00
|
|
|
|
2015-10-11 03:24:50 +02:00
|
|
|
def main(argv):
|
2015-10-07 07:35:11 +02:00
|
|
|
|
2015-10-14 05:26:55 +02:00
|
|
|
destination = config['destination']
|
|
|
|
if(config['type'] == 'photo'):
|
2015-10-11 03:24:50 +02:00
|
|
|
media_type = Photo
|
|
|
|
else:
|
|
|
|
media_type = Video
|
2015-10-10 09:02:53 +02:00
|
|
|
|
2015-10-14 05:26:55 +02:00
|
|
|
if(config['source'] is not None):
|
|
|
|
source = config['source']
|
2015-10-10 09:02:53 +02:00
|
|
|
|
2015-10-11 03:24:50 +02:00
|
|
|
for current_file in filesystem.get_all_files(source, media_type.get_valid_extensions()):
|
2015-10-11 09:12:53 +02:00
|
|
|
media = media_type(current_file)
|
|
|
|
|
|
|
|
if(media_type.__name__ == 'Video'):
|
|
|
|
filesystem.set_date_from_path_video(media)
|
|
|
|
|
2015-10-14 05:55:06 +02:00
|
|
|
dest_path = filesystem.process_file(current_file, destination, media, allowDuplicate=False, move=False)
|
2015-10-15 08:41:15 +02:00
|
|
|
if(dest_path is not None):
|
|
|
|
print '%s -> %s' % (current_file, dest_path)
|
2015-10-14 05:26:55 +02:00
|
|
|
elif(config['file'] is not None):
|
|
|
|
media = media_type(config['file'])
|
2015-10-11 09:12:53 +02:00
|
|
|
if(media_type.__name__ == 'Video'):
|
|
|
|
filesystem.set_date_from_path_video(media)
|
|
|
|
|
2015-10-14 09:39:30 +02:00
|
|
|
dest_path = filesystem.process_file(config['file'], destination, media, allowDuplicate=False, move=False)
|
2015-10-15 08:41:15 +02:00
|
|
|
if(dest_path is not None):
|
|
|
|
print '%s -> %s' % (current_file, dest_path)
|
2015-10-14 05:26:55 +02:00
|
|
|
else:
|
|
|
|
help()
|
|
|
|
|
|
|
|
db = Db()
|
|
|
|
filesystem = FileSystem()
|
|
|
|
args = arguments.parse(sys.argv[1:], None, ['file=','type=','source=','destination='], help())
|
|
|
|
config = parse_arguments(args)
|
2015-10-07 07:35:11 +02:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2015-10-14 05:26:55 +02:00
|
|
|
main(config)
|
2015-10-11 03:24:50 +02:00
|
|
|
sys.exit(0)
|