Added rootdir and modified to use shutils

This commit is contained in:
justine 2024-10-02 11:46:43 +02:00
parent d0b512080e
commit 022ca14a00
2 changed files with 35 additions and 27 deletions

View File

@ -2,13 +2,14 @@
A script for sorting pictures (namely, wallpapers) by size.
It looks for a folder named "wallpapers" in its directory. It then moves all pictures into folders it creates, depending on their size. All pictures that do not fit either a predefined format go in the "SD" folder.
We take a folder containing unsorted wallpapers of all sizes and sort them by size by putting them into discrete folders.
# Formats
## 16:9
* hd (1920 x 1080)
* 2k (2560 x 1440)
* 4k (4096 x 2160)
# Use
Create a venv and install requirements:
```
python3 -m venv myvenv
myvenv/bin/activate
pip install -r requirements.txt
```
# 21:9
* 2k (3440 x 1440)
Take a look at the configuration section inside the script and then launch it.

View File

@ -3,6 +3,7 @@
import cv2
import os
from os.path import join
import shutil
def pic_size_find(pic_path: str):
img = cv2.imread(pic_path,0)
@ -15,37 +16,43 @@ def pics_list(path:os.path):
return files
def file_move(file, dest):
os.rename(file, dest)
shutil.move(file, dest)
def main():
#For landscape
#------------------ CONFIG START
#Where the wallpaper folders are, must end in "/"
rootdir = "/home/justine/NAS/Gallery/"
#Folder names for landscape
folder4k = "Wallpapers_4K"
folder2k = "Wallpapers_2k"
folderhd = "Wallpapers_hd"
foldersd = "Wallpapers_sd"
foldersd = "Wallpapers_other_def"
folderuw = "UltrawideWallpapers"
#For portrait
#Folder names for portrait
vert4k = "Vertical_4k"
vert2k = "Vertical_2k"
verthd = "Vertical_hd"
vertuw = "Vertical_ultrawide"
#Resolutions to check against
res4k = (4096, 2160)
reslow4k = (3840, 2160)
res2k = (2560, 1440)
reshd = (1920, 1080)
resuw = (3440, 1440)
#VARS
orig_folder = "VerticalWallpapers"
#Where to look for the unsorted wallpapers
orig_folder = "/home/justine/Pictures/Unsorted"
#------------------ CONFIG END
print("Size begins !")
for folder in [folder4k, folder2k, folderhd, foldersd, folderuw, vert2k, vert4k, verthd, vertuw]:
os.makedirs(join(".", folder), exist_ok=True)
print(f"Folder {folder} created if needed")
os.makedirs(join(rootdir, folder), exist_ok=True)
print(f"Folder {rootdir}{folder} created if needed")
@ -61,37 +68,37 @@ def main():
print(f"{f} => {size}")
#Check landscape first
if size == res4k or size == reslow4k:
file_move(f_path, join(folder4k, f))
file_move(f_path, join(rootdir, folder4k, f))
dest_folder = folder4k
elif size == res2k:
file_move(f_path, join(folder2k, f))
file_move(f_path, join(rootdir, folder2k, f))
dest_folder = folder2k
elif size == reshd:
file_move(f_path, join(folderhd, f))
file_move(f_path, join(rootdir, folderhd, f))
dest_folder = folderhd
elif size == resuw:
file_move(f_path, join(folderuw, f))
file_move(f_path, join(rootdir, folderuw, f))
dest_folder = folderuw
#Check portrait by inverting sizes
elif rsize == res4k or rsize == reslow4k:
file_move(f_path, join(vert4k, f))
file_move(f_path, join(rootdir, vert4k, f))
dest_folder = vert4k
elif rsize == res2k[::-1]:
file_move(f_path, join(vert2k, f))
file_move(f_path, join(rootdir, vert2k, f))
dest_folder = vert2k
elif rsize == reshd[::-1]:
file_move(f_path, join(verthd, f))
file_move(f_path, join(rootdir, verthd, f))
dest_folder = verthd
elif rsize == resuw[::-1]:
file_move(f_path, join(vertuw, f))
file_move(f_path, join(rootdir, vertuw, f))
dest_folder = vertuw
#...Or put in "SD" folder
else:
file_move(f_path, join(foldersd, f))
file_move(f_path, join(rootdir, foldersd, f))
dest_folder = foldersd
print(f"{f} moved to {dest_folder}")
print(f"{f} moved to {rootdir}{dest_folder}")
print("Done, Sayonara")