diff --git a/crawl_videos.py b/crawl_videos.py deleted file mode 100755 index 292be7c..0000000 --- a/crawl_videos.py +++ /dev/null @@ -1,33 +0,0 @@ -#!/usr/bin/env python - -import os -import shutil -import sys - -from elodie.media.video import Video -from elodie.filesystem import FileSystem - -destination = '%s/tmp' % os.path.expanduser('~') - -filesystem = FileSystem() - -for video_file in filesystem.get_all_files('/Users/jaisenmathai/Pictures/Videos/', Video.get_valid_extensions()): - video = Video(video_file) - - filesystem.set_date_from_path_video(video) - - metadata = video.get_metadata() - - directory_name = filesystem.get_folder_name_by_date(metadata['date_taken']) - dest_directory = '%s/%s' % (destination, directory_name) - # TODO remove the day prefix of the file that was there prior to the crawl - file_name = filesystem.get_file_name_for_video(video) - dest_path = '%s/%s' % (dest_directory, file_name) - - filesystem.create_directory(dest_directory) - - print '%s -> %s' % (video_file, dest_path) - shutil.copy2(video_file, dest_path) - - - diff --git a/elodie/arguments.py b/elodie/arguments.py new file mode 100644 index 0000000..49fe42b --- /dev/null +++ b/elodie/arguments.py @@ -0,0 +1,24 @@ +""" +""" +import sys, getopt +from re import sub + +def parse(argv, options, long_options, usage): + def help(): + print 'Usage: %s' % usage + + try: + opts, args = getopt.getopt(argv, options, long_options) + except getopt.GetoptError: + print 'Unknown arguments' + help() + sys.exit(2) + + return_arguments = {} + for opt, arg in opts: + if opt == '-h': + help() + sys.exit() + else: + return_arguments[sub('^-+', '', opt)] = arg + return return_arguments diff --git a/elodie/filesystem.py b/elodie/filesystem.py index 647dc1a..7978f86 100644 --- a/elodie/filesystem.py +++ b/elodie/filesystem.py @@ -60,7 +60,7 @@ class FileSystem: return None file_name = '%s-%s.%s' % (time.strftime('%Y-%m-%d_%H-%M-%S', metadata['date_taken']), metadata['base_name'], metadata['extension']) - return file_name + return file_name.lower() """ Get date based folder name. diff --git a/import.py b/import.py new file mode 100755 index 0000000..b27e7b6 --- /dev/null +++ b/import.py @@ -0,0 +1,39 @@ +#!/usr/bin/env python + +import os +import shutil +import sys + +from elodie import arguments +from elodie.media.video import Video +from elodie.filesystem import FileSystem + +def main(argv): + + args = arguments.parse(argv, None, ['source=','destination='], './import.py --source= -destination=') + + source = args['source'] + destination = args['destination'] + + filesystem = FileSystem() + + for video_file in filesystem.get_all_files(source, Video.get_valid_extensions()): + video = Video(video_file) + + filesystem.set_date_from_path_video(video) + + metadata = video.get_metadata() + + directory_name = filesystem.get_folder_name_by_date(metadata['date_taken']) + dest_directory = '%s/%s' % (destination, directory_name) + # TODO remove the day prefix of the file that was there prior to the crawl + file_name = filesystem.get_file_name_for_video(video) + dest_path = '%s/%s' % (dest_directory, file_name) + + filesystem.create_directory(dest_directory) + + print '%s -> %s' % (video_file, dest_path) + shutil.copy2(video_file, dest_path) + +if __name__ == '__main__': + main(sys.argv[1:])