-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 569cbe9
Showing
3 changed files
with
248 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# video_extract | ||
# keytonic | ||
# 18 Aug 24 | ||
# | ||
# will loop through the contents of the current directory | ||
# any folder it finds it will enter, look for '.mp4's and move them | ||
# out one folder to the working dir. so i can batch pull downloaded | ||
# movies from folders to the root directory | ||
|
||
|
||
class bcolors: | ||
HEADER = '\033[95m' | ||
OKBLUE = '\033[94m' | ||
OKCYAN = '\033[96m' | ||
OKGREEN = '\033[92m' | ||
WARNING = '\033[93m' | ||
FAIL = '\033[91m' | ||
ENDC = '\033[0m' | ||
BOLD = '\033[1m' | ||
UNDERLINE = '\033[4m' | ||
|
||
|
||
import sys | ||
import os | ||
import os.path | ||
|
||
working_dir = sys.path[0] #C:\Users\keytonic\Documents\video_renamer | ||
current_dir = "" #C:\Users\keytonic\Documents\video_renamer\poop | ||
|
||
def move_it(name): | ||
#if its not a folder, bail, should not have a period in the name | ||
#if(name.rfind('.') != -1): | ||
# return | ||
if(os.path.isdir(name) == False): | ||
return | ||
|
||
#working dir plus folder name | ||
current_dir = "{}\\{}".format(working_dir,name) | ||
#print(current_dir) | ||
#print(working_dir) | ||
|
||
#getting contents of current dir | ||
list = os.listdir(name) | ||
|
||
#looping through contents | ||
for file in list: | ||
|
||
#movies only | ||
if(file.rfind('.mp4') == -1 and file.rfind('.mkv') == -1): | ||
continue | ||
|
||
#calc locations | ||
old_location = "{}\\{}".format(current_dir,file) | ||
new_location = "{}\\{}".format(working_dir,file) | ||
|
||
#lets go! | ||
print(bcolors.OKGREEN + "[Info]" + bcolors.ENDC + " Moving from {} to {}".format(old_location,new_location)) | ||
os.rename(old_location,new_location) | ||
|
||
|
||
#get the list of all files and directories in the current working directory | ||
file_list = os.listdir() | ||
#looping throught them all | ||
for file in file_list: | ||
#ignore this script file name | ||
if(file != os.path.basename(__file__)): | ||
move_it(file) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# video_organize | ||
# keytonic | ||
# 18 Aug 24 | ||
# | ||
# a simple script that loops through all the movies in a folder | ||
# and organizes them into folders named A through Z based on the title, | ||
# folder named # for non alphabetic first character | ||
|
||
|
||
class bcolors: | ||
HEADER = '\033[95m' | ||
OKBLUE = '\033[94m' | ||
OKCYAN = '\033[96m' | ||
OKGREEN = '\033[92m' | ||
WARNING = '\033[93m' | ||
FAIL = '\033[91m' | ||
ENDC = '\033[0m' | ||
BOLD = '\033[1m' | ||
UNDERLINE = '\033[4m' | ||
|
||
import sys | ||
import os | ||
import os.path | ||
|
||
def move_it(name): | ||
|
||
#skip over python scripts | ||
if (name.find(".py") != -1) : | ||
return | ||
|
||
#movies only | ||
if(name.rfind('.mp4') == -1 and name.rfind('.mkv') == -1): | ||
return | ||
|
||
#get first character, # is its not in alphabet | ||
first_char = name[:1].upper() | ||
first_char = first_char if first_char.isalpha() else "#" | ||
|
||
#calc paths | ||
src_location = os.path.abspath(name) | ||
new_location = "Z:\\Movies\\" + first_char + "\\" + name | ||
|
||
try: | ||
os.rename(src_location,new_location) | ||
print(bcolors.OKGREEN + "[Info]" + bcolors.ENDC + " Moving: '" + src_location + "' to '" + new_location + "'") | ||
except: | ||
print(bcolors.FAIL + "[Fail]" + bcolors.ENDC + " Moving: '" + src_location + "' to '" + new_location + "'") | ||
|
||
#get the list of all files and directories in the current working directory | ||
file_list = os.listdir() | ||
#looping throught them all | ||
for file in file_list: | ||
#ignore this script file name | ||
if(file != os.path.basename(__file__) and os.path.isdir(file) == False): | ||
move_it(file) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# video_renamer | ||
# keytonic | ||
# 18 Aug 24 | ||
# | ||
# attempts to itterate current directory and renames all videos correctly | ||
# from: | ||
# Ant-Man.And.The.Wasp.Quantumania.2023.720p.BluRay.x264.AAC-[YTS.MX].mp4 | ||
# The.Iron.Claw.2023.720p.BluRay.x264.AAC-[YTS.MX].mp4 | ||
# to: | ||
# Ant-Man And The Wasp Quantumania (2023).mp4 | ||
# Iron Claw, The (2023).mp4 | ||
# | ||
# Will also take one file name via command line | ||
# eg: python video_renamer.py Ant-Man.And.The.Wasp.Quantumania.2023.720p.BluRay.x264.AAC-[YTS.MX].mp4 | ||
|
||
import sys | ||
import os | ||
#import webbrowser | ||
import requests | ||
|
||
from imdb import Cinemagoer | ||
|
||
ia = Cinemagoer() | ||
|
||
|
||
|
||
class bcolors: | ||
HEADER = '\033[95m' | ||
OKBLUE = '\033[94m' | ||
OKCYAN = '\033[96m' | ||
OKGREEN = '\033[92m' | ||
WARNING = '\033[93m' | ||
FAIL = '\033[91m' | ||
ENDC = '\033[0m' | ||
BOLD = '\033[1m' | ||
UNDERLINE = '\033[4m' | ||
|
||
|
||
|
||
def get_poster(name,year): | ||
|
||
filename = "{} ({}).{}".format(name,year,'jpg') | ||
|
||
try: | ||
movies = ia.search_movie("{} {}".format(name,year)) | ||
movie = ia.get_movie(movies[0].movieID) | ||
img_data = "" | ||
|
||
if(movie.has_key('cover url') == True and movie['cover url'] != ""): | ||
img_data = requests.get(movie['cover url']).content | ||
|
||
if(img_data != ""): | ||
with open(filename, 'wb') as handler: | ||
handler.write(img_data) | ||
print(bcolors.OKGREEN + "[Info]" + bcolors.ENDC + " Creating '" + bcolors.OKCYAN + filename + bcolors.ENDC + "'") | ||
else: | ||
print(bcolors.FAIL + "[Fail]" + bcolors.ENDC + " could not save: '" + filename + "'") | ||
except: | ||
print(bcolors.FAIL + "[Fail]" + bcolors.ENDC + " could not save: '" + filename + "'") | ||
|
||
#input("Press Enter to continue...") | ||
|
||
def rename(name): | ||
|
||
#looking at extention first because if it aint a movie | ||
#then there aint no point in doing anything else | ||
ext = (name[name.rfind('.') + 1:]).strip() | ||
|
||
if(ext != "mp4" and ext != "mkv"): | ||
#return quietly if its a script or folder | ||
#if(ext != "py" and name.rfind('.') != -1): | ||
if(os.path.isdir(name) == False and ext != "py"): | ||
#return loudly if it is a file with a no shit wrong extention | ||
print(bcolors.FAIL + "[Fail]" + bcolors.ENDC + " extention: '{}' name: '{}'".format(ext,name)) | ||
return | ||
|
||
|
||
|
||
#searching for year, looking for first occurance of year_prefix | ||
#hoping year is something like 20xx or 19xx what ever year_prefix is set to | ||
year_prefix = "20" | ||
year = (name[name.find(year_prefix):name.find(year_prefix) + 4]).strip() | ||
|
||
if((year.isnumeric() == False) or (year == "")): | ||
|
||
year_prefix = "19" | ||
year = (name[name.find(year_prefix):name.find(year_prefix) + 4]).strip() | ||
|
||
if((year.isnumeric() == False) or (year == "")): | ||
print(bcolors.FAIL + "[Fail]" + bcolors.ENDC + " year: '{}' name: '{}'".format(year,name)) | ||
#sys.exit() | ||
return | ||
|
||
#getting the title, doing alot of .srip'n just making sure theres no spaces | ||
#also checking for 'the' in the title. if its in the begining the rename accordingly | ||
title = (name[0:name.find(year_prefix)].replace('.', ' ')).strip() | ||
|
||
#removing '(' and ')' incase this file has been processed previously | ||
title = title.replace('(', '').strip() | ||
title = title.replace(')', '').strip() | ||
|
||
#need to fix this... triggers on 'they' etc | ||
if((title.find("The ") != -1) and (title.find("The ") == 0)): | ||
title = "{}, The".format(title[4:]) | ||
|
||
#putting it all together | ||
new_name = "{} ({}).{}".format(title,year,ext) | ||
|
||
#let's go! | ||
print(bcolors.OKGREEN + "[Info]" + bcolors.ENDC + " Renaming '" + bcolors.OKCYAN + new_name + bcolors.ENDC + "'") | ||
os.rename(name,new_name) | ||
get_poster(title,year) | ||
|
||
|
||
#if filename given on commandline then go with it | ||
if(len(sys.argv) > 1): | ||
rename(sys.argv[1]) | ||
#otherwise loop through files in directory and process them | ||
else: | ||
#get the list of all files and directories in the current working directory | ||
file_list = os.listdir() | ||
#looping throught them all | ||
for file in file_list: | ||
#ignore this script file name | ||
if(file != os.path.basename(__file__)): | ||
rename(file) |