Example #1
0
def delete_folder(dir):
	if not exclude_in_file_reorg(dir):
		pr.print_(dir, "deltree")
		if not cf.debug:
			shutil.rmtree(dir)
	else:
		pr.print_(dir, "delskip")
def create_contact_sheet(file_info):

    pr.print_(file_info.fullfilename, "start")

    cs_filename = file_info.fullfilename[:-len(file_info.extension
                                               )] + cf.contact_ext

    if cf.debug:
        pr.print_(cs_filename, "done", True)
        pr.print_("")
        return

    vid_attr = vid_attribute(file_info)

    header_height, thumb_height, template_image = img.create_image_template(
        file_info)
    thumbs = cap.capture_thumbnails(vid_attr)

    cf.thumb_height = thumb_height

    counter = 0
    thumbs_keys = list(thumbs.keys())
    thumbnail_scale = (cf.thumb_height * 1.0) / thumbs[thumbs_keys[0]].shape[0]
    x_offset = cf.thumb_spacing
    y_offset = header_height

    for y in range(1, cf.thumbs_vertical + 1):

        for x in range(1, cf.thumbs_horizontal + 1):

            thumbnail = thumbs[thumbs_keys[counter]]
            thumbnail_scaled = cv2.resize(thumbnail,
                                          (cf.thumb_width, cf.thumb_height),
                                          interpolation=cv2.INTER_AREA)
            template_image[y_offset:y_offset + thumbnail_scaled.shape[0],
                           x_offset:x_offset +
                           thumbnail_scaled.shape[1]] = thumbnail_scaled

            x_offset += cf.thumb_spacing + cf.thumb_width
            counter += 1

        x_offset = cf.thumb_spacing
        y_offset += (cf.thumb_height + cf.thumb_spacing)

    cv2.imwrite(cs_filename, template_image)

    pr.print_(cs_filename, "done", True)
    pr.print_("")
def rename_move():

    # rename video file name and move to parent
    allfiles = list(fs.get_all_files(cf.working_dir))

    # move video files to working folder root
    for file in allfiles:

        # object to parse out file path parts
        fileinfo = file_info(file, cf.working_dir)

        # skip file is not video or marked for omit reorg
        if (fileinfo.extension not in cf.video_ext) \
         or fileinfo.isatroot \
         or fileinfo.excludefilereorg:
            continue

        # unique counter
        iterator = 0
        newfilename = os.path.join(fileinfo.rootfolder, fileinfo.parentfoldername) \
         + fileinfo.extension

        # make filename unique if exists in destination
        while os.path.isfile(newfilename):
            newfilename = os.path.join(fileinfo.rootfolder, fileinfo.parentfoldername) + "-" + \
             ("%02d" % (iterator,)) + fileinfo.extension
            iterator += 1

        # move / rename file to parent root dir
        pr.print_(fileinfo.fullfilename)
        pr.print_(newfilename)
        fs.move_file(fileinfo.fullfilename, newfilename)

    # delete subdirs
    all_sub_dirs = fs.get_all_subdir(cf.working_dir)
    for dir in all_sub_dirs:
        if len(list(fs.get_all_files(dir))) == 0:
            delete_folder(dir)
Example #4
0
def delete_unwanted_files():

	allfiles = list(fs.get_all_files(cf.working_dir))

	# delete unwanted files
	for file in allfiles:
	
		fileinfo = file_info(file, cf.working_dir)
		
		# skip is exclude pattern found
		if fileinfo.excludefilereorg: 
			pr.print_(fileinfo.fullfilename, "delskip")
			continue

		# if contact sheet
		if (fileinfo.extension == cf.contact_ext):
			# make sure matching video file exists
			if not corresponding_video_file_exists(fs.filename_only(file), allfiles):
				# if no matching video file, delete
				fs.delete_file(file)
		# if is not contact sheet or video file, delete
		elif (fileinfo.extension not in cf.video_ext) or ('sample' in fileinfo.filename.lower()):
			fs.delete_file(file)
import os
import sys

import rtconfig as cf
import rtfunctions as fn
import rtprint as pr

if cf.debug: pr.print_("Debug mode is on\n\n")

# handle if folder path is passed in
if (len(sys.argv) > 1):
    in_path = str(sys.argv[1]).strip().replace('"', '')
    if os.path.isdir(sys.argv[1]):
        cf.reorg_paths = [in_path]
        pr.print_("Folder: " + in_path)
        resp = raw_input("Reorganize folder? (y/n): ")
        pr.print_("")
        cf.reorg = resp.strip().lower() == "y"
    else:
        pr.print_("Parameter not recognized as folder, exiting")
        sys.exit()

# delete unwanted files
for dir in cf.reorg_paths:

    cf.working_dir = dir

    fn.delete_unwanted_files()

    if cf.reorg:
        fn.rename_move()
import os
import sys

from rtclasses import *

import rtfilesys as fs
import rtimaging as img
import rtconfig as cf
import rtfunctions as fn
import rtprint as pr

if cf.debug: pr.print_("Debug mode is on\n\n")

if (len(sys.argv) > 1):

    in_path = str(sys.argv[1]).strip().replace('"', '')

    if (len(sys.argv) > 2 and sys.argv[2] == 'skip'):
        cf.remove_lowres = False

    if os.path.isdir(in_path):
        cf.thumb_paths = [in_path]
        pr.print_(in_path, "path")

ii = 1
all_ct = 0
thumb_files = []

for dir in cf.thumb_paths:

    files = list(fs.get_all_files(dir))
Example #7
0
import os
import sys

from rtclasses import *

import rtfilesys as fs
import rtimaging as img
import rtconfig as cf
import rtfunctions as fn
import rtprint as pr

if cf.debug: pr.print_("Debug mode is on\n\n")

if (len(sys.argv) > 1):

    in_path = str(sys.argv[1]).strip().replace('"', '')

    if os.path.isdir(in_path):
        cf.thumb_paths = [in_path]
        pr.print_(in_path, "path")

for dir in cf.thumb_paths:

    files = list(fs.get_all_files(dir))

    for file in files:

        file_nfo = file_info(file, dir)

        if file_nfo.extension in cf.video_ext:
def move_file(src, dest):
    if not cf.debug:
        os.rename(src, dest)

    pr.print_(src, 'move-frm')
    pr.print_(dest, 'move-to')
def delete_file(file_path):
    if not cf.debug:
        os.remove(file_path)
    pr.print_(file_path, 'del')
Example #10
0
def create_contact_sheet(file_info):

    pr.print_(file_info.fullfilename, "start")

    cs_filename = file_info.fullfilename[:-len(file_info.extension
                                               )] + cf.contact_ext

    if cf.debug:
        pr.print_(cs_filename, "done", True)
        pr.print_("")
        return

    vid_attr = vid_attribute(file_info)

    if (vid_attr.height < 400 and cf.remove_lowres):

        vid_attr.vid_cap.release()
        cv2.destroyAllWindows()

        fs.delete_file(vid_attr.file_nfo.fullfilename)
        pr.print_(cs_filename, f" del {vid_attr.height}p", True)
        pr.print_("")
        return

    header_height, thumb_height, template_image = img.create_image_template(
        file_info)
    thumbs = cap.capture_thumbnails(vid_attr)

    cf.thumb_height = thumb_height

    counter = 0
    thumbs_keys = list(thumbs.keys())
    # thumbnail_scale = (cf.thumb_height * 1.0) / thumbs[thumbs_keys[0]].shape[0]
    x_offset = cf.thumb_spacing
    y_offset = header_height

    for y in range(1, cf.thumbs_vertical_new + 1):

        for x in range(1, cf.thumbs_horizontal + 1):

            thumbnail = thumbs[thumbs_keys[counter]]
            thumbnail_scaled = cv2.resize(thumbnail,
                                          (cf.thumb_width, cf.thumb_height),
                                          interpolation=cv2.INTER_AREA)
            template_image[y_offset:y_offset + thumbnail_scaled.shape[0],
                           x_offset:x_offset +
                           thumbnail_scaled.shape[1]] = thumbnail_scaled

            x_offset += cf.thumb_spacing + cf.thumb_width
            counter += 1

        x_offset = cf.thumb_spacing
        y_offset += (cf.thumb_height + cf.thumb_spacing)

    newdim = (
        int(template_image.shape[1] * 0.6),
        int(template_image.shape[0] * 0.6),
    )
    template_image = cv2.resize(template_image,
                                newdim,
                                interpolation=cv2.INTER_AREA)
    cv2.imwrite(cs_filename, template_image, [cv2.IMWRITE_PNG_COMPRESSION, 9])

    os.utime(cs_filename,
             (vid_attr.file_nfo.moddate, vid_attr.file_nfo.moddate))

    pr.print_(cs_filename, "done", True)
    pr.print_("")