Created
January 13, 2020 02:57
-
-
Save bmitchinson/af9dd92c43d73fcf077adb6b16b87248 to your computer and use it in GitHub Desktop.
Python script to perform bash operations on specified file types found recursively
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
from datetime import datetime | |
import subprocess | |
# logfile = open("convert_log.txt", "w+") | |
# def log(s): | |
# print(s + "\n") | |
# logfile.write(s + '\n') | |
path = "/Volumes/Mitchinson/FamilyBackup/MomMyBook/New/originals" #/(2008) 12-1-2008" | |
types = {} | |
# typesToDelete = ['m2ts'] # ['db', 'Sony_PMBrowser3000_BrowserDiskCache', 'idx', 'modd', 'moff', 'lnk', 'ini'] | |
typesToMove = ['jpeg', 'png', 'mov', '3gp', 'mp4', 'heic'] | |
deletionCount = 0 | |
moveCount = 0 | |
toConvert = [] | |
print("\n") | |
print("----------------") | |
print("Starting script @ " + datetime.now().strftime("%d/%m/%Y %H:%M:%S")) | |
print("----------------") | |
print("Looking @ Path: " + path) | |
for dirPath, dirNames, fileNames in os.walk(path): | |
for f in fileNames: | |
if f[0] != '.': | |
t = f.split('.')[-1] | |
# mp4equl = f[:-4] + 'mp4' | |
# if t == 'm2ts' and mp4equl not in fileNames: | |
# toConvert.append(dirPath + '/' + f) | |
if types.get(t): | |
types[t] += 1 | |
else: | |
types[t] = 1 | |
if t in typesToMove: | |
print('moving ' + dirPath + '/' + f) | |
moveCount += 1 | |
org = dirPath + '/' + f | |
new = '/Volumes/Mitchinson/FamilyBackup/MomMyBook/iCloud/2020extract/' + f | |
r = subprocess.check_call(['cp', org, new]) | |
# 'mv dirPath + '/' + f | |
# if t in typesToDelete: | |
# print('Deleting ' + dirPath + '/' + f) | |
# deletionCount += 1 | |
# try: | |
# os.remove(dirPath + '/' + f) | |
# except: | |
# pass | |
# log('Deleted ' + str(deletionCount) + ' files.') | |
print('----------------') | |
print('types:') | |
print(types) | |
print('moved ' + str(moveCount)) | |
print('----------------\n') | |
# log('Beginning ' + str(len(toConvert)) + ' conversions.') | |
# converted = 1 | |
# for f in toConvert: | |
# mp4equl = f[:-4] + 'mp4' | |
# log('Starting @ ' + datetime.now().strftime("%d/%m/%Y %H:%M:%S")) | |
# log('Converting file ' + str(converted) + ' / ' + str(len(toConvert)) + ': ' + f) | |
# r = subprocess.check_call(['ffmpeg', '-i', f, '-vcodec', 'libx264', '-crf', '20', '-acodec', 'ac3', '-vf', 'yadif', mp4equl]) | |
# log('Done @ ' + datetime.now().strftime("%d/%m/%Y %H:%M:%S")) | |
# converted += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment