Add method to recursively get files and implemented for videos
This commit is contained in:
parent
f276d37e7f
commit
f435eaabe6
|
@ -0,0 +1,23 @@
|
||||||
|
#!/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)
|
||||||
|
metadata = video.get_metadata()
|
||||||
|
|
||||||
|
directory_name = filesystem.get_folder_name_by_date(metadata['date_taken'])
|
||||||
|
dest_directory = '%s/%s' % (destination, directory_name)
|
||||||
|
file_name = filesystem.get_file_name_for_video(video)
|
||||||
|
|
||||||
|
print '%s *** %s' % (video_file, file_name)
|
||||||
|
#print '%s/%s' % (directory_name, file_name)
|
|
@ -1,8 +1,16 @@
|
||||||
import glob
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
|
||||||
class FileSystem:
|
class FileSystem:
|
||||||
|
def get_all_files(self, pattern, extensions=None):
|
||||||
|
files = []
|
||||||
|
for dirname, dirnames, filenames in os.walk(pattern):
|
||||||
|
# print path to all filenames.
|
||||||
|
for filename in filenames:
|
||||||
|
if(extensions == None or filename.lower().endswith(extensions)):
|
||||||
|
files.append('%s/%s' % (dirname, filename))
|
||||||
|
return files
|
||||||
|
|
||||||
def get_current_directory(self):
|
def get_current_directory(self):
|
||||||
return os.getcwd()
|
return os.getcwd()
|
||||||
|
|
||||||
|
@ -14,16 +22,12 @@ class FileSystem:
|
||||||
if(metadata == None):
|
if(metadata == None):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
file_name = '%s-%s-%s.%s' % (time.strftime('%d-%H-%M', metadata['date_taken']), metadata['base_name'], metadata['length'].replace(':', '-'), metadata['extension'])
|
file_name = '%s-%s.%s' % (time.strftime('%Y-%m-%d-%H-%M', metadata['date_taken']), metadata['base_name'], metadata['extension'])
|
||||||
return file_name
|
return file_name
|
||||||
|
|
||||||
def get_folder_name_by_date(self, time_obj):
|
def get_folder_name_by_date(self, time_obj):
|
||||||
return time.strftime('%Y-%m', time_obj)
|
return time.strftime('%Y-%m-%b', time_obj)
|
||||||
|
|
||||||
|
|
||||||
def create_directory(self, directory_path):
|
def create_directory(self, directory_path):
|
||||||
if not os.path.exists(directory_path):
|
if not os.path.exists(directory_path):
|
||||||
os.makedirs(dest_directory)
|
os.makedirs(dest_directory)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,10 +15,10 @@ Video package that handles all video operations
|
||||||
Video class for general video operations
|
Video class for general video operations
|
||||||
"""
|
"""
|
||||||
class Video(object):
|
class Video(object):
|
||||||
|
__valid_extensions = ('avi','m4v','mov','mp4')
|
||||||
|
|
||||||
# Constructor
|
# Constructor
|
||||||
def __init__(self, source=None):
|
def __init__(self, source=None):
|
||||||
self.__valid_extensions = ['avi','m4v','mov','mp4']
|
|
||||||
|
|
||||||
self.source = source
|
self.source = source
|
||||||
|
|
||||||
def get_metadata(self):
|
def get_metadata(self):
|
||||||
|
@ -36,15 +36,10 @@ class Video(object):
|
||||||
|
|
||||||
return metadata
|
return metadata
|
||||||
|
|
||||||
#directory_name = time.strftime('%Y-%m', date_taken)
|
|
||||||
#file_base_name = path_regex.group(1)
|
|
||||||
#file_extension = path_regex.group(2)
|
|
||||||
#file_name = '%s-%s-%s.%s' % (time.strftime('%d-%H-%M', date_taken), file_base_name, video_length, file_extension)
|
|
||||||
|
|
||||||
def is_valid(self):
|
def is_valid(self):
|
||||||
source = self.source
|
source = self.source
|
||||||
# we can't use self.__get_extension else we'll endlessly recurse
|
# we can't use self.__get_extension else we'll endlessly recurse
|
||||||
return os.path.splitext(source)[1][1:].lower() in self.__valid_extensions
|
return os.path.splitext(source)[1][1:].lower() in self.get_valid_extensions()
|
||||||
|
|
||||||
#
|
#
|
||||||
# Private methods
|
# Private methods
|
||||||
|
@ -96,6 +91,10 @@ class Video(object):
|
||||||
|
|
||||||
return mimetype[0]
|
return mimetype[0]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_valid_extensions(Video):
|
||||||
|
return Video.__valid_extensions
|
||||||
|
|
||||||
class Transcode(object):
|
class Transcode(object):
|
||||||
# Constructor takes a video object as it's parameter
|
# Constructor takes a video object as it's parameter
|
||||||
def __init__(self, video=None):
|
def __init__(self, video=None):
|
||||||
|
|
Loading…
Reference in New Issue