Created
April 15, 2024 12:27
-
-
Save ixtk/8bbdd1e252fcd6933e8f4dfac8f8848c to your computer and use it in GitHub Desktop.
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
from pathlib import Path | |
from hachoir.parser import createParser | |
from hachoir.metadata import extractMetadata | |
from datetime import datetime | |
import os | |
import time | |
# dictionary generated by chatGPT | |
c = { | |
"Apr 10": 51, | |
"Apr 07": 50, | |
"Apr 03": 49, | |
"Mar 31": 48, | |
"Mar 27": 47, | |
"Mar 24": 46, | |
"Mar 20": 45, | |
"Mar 17": 44, | |
"Mar 13": 43, | |
"Mar 10": 42, | |
"Mar 06": 41, | |
"Feb 28": 40, | |
"Feb 25": 39, | |
"Feb 21": 38, | |
"Feb 18": 37, | |
"Feb 14": 36, | |
"Feb 11": 35, | |
"Feb 07": 34, | |
"Feb 04": 33, | |
"Jan 31": 32, | |
"Jan 28": 31, | |
"Jan 24": 30, | |
"Jan 21": 29, | |
"Jan 17": 28, | |
"Dec 27": 27, | |
"Dec 24": 26, | |
"Dec 20": 25, | |
"Dec 17": 24, | |
"Dec 13": 23, | |
"Dec 10": 22, | |
"Dec 06": 21, | |
"Dec 03": 20, | |
"Nov 29": 19, | |
"Nov 26": 18, | |
"Nov 22": 17, | |
"Nov 15": 16, | |
"Nov 12": 15, | |
"Nov 08": 14, | |
"Nov 05": 13, | |
"Nov 01": 12, | |
"Oct 29": 11, | |
"Oct 25": 10, | |
"Oct 22": 9, | |
"Oct 18": 8, | |
"Oct 15": 7 | |
} | |
def get_video_creation_date(video_path): | |
ti_c = os.path.getctime(str(video_path)) | |
c_ti = time.ctime(ti_c) | |
# print(c_ti) | |
date_obj = datetime.strptime(c_ti, "%a %b %d %H:%M:%S %Y") | |
formatted_date = date_obj.strftime("%b %d") | |
return formatted_date | |
def rename_videos_with_date(directory): | |
for video_path in Path(directory).glob('*'): | |
if video_path.suffix.lower() in ('.mp4', '.mkv'): | |
creation_date = get_video_creation_date(video_path) | |
# print(creation_date) | |
if creation_date: | |
# print(video_path.stem) | |
new_filename = "{} - {}".format( | |
creation_date, video_path.stem.removesuffix(f' - {directory.name}')) | |
new_path = video_path.parent / new_filename | |
video_path.rename(new_path) | |
print(f"'{video_path.name}' to '{new_filename}'") | |
def move_files_with_suffix(source_directory, suffix, target_directory_name): | |
target_directory = source_directory / target_directory_name | |
target_directory.mkdir(exist_ok=True) | |
for file_path in source_directory.iterdir(): | |
# print(file_path.is_file()) | |
if file_path.is_file() and file_path.name.endswith(suffix): | |
new_path = target_directory / file_path.name | |
file_path.rename(new_path) | |
print(f"TBM '{file_path.name}' to '{target_directory_name}'") | |
def append_mkv(directory): | |
dir_path = Path(directory) | |
for file_path in dir_path.iterdir(): | |
# print(file_path.name) | |
if file_path.is_file(): | |
new_name = f'[{c[file_path.name.split(" - ")[0]]}] {file_path.name}' | |
new_file_path = file_path.with_name(new_name) | |
file_path.rename(new_file_path) | |
print(f"NEW FILE {new_file_path}") | |
def enum_dates(directory): | |
dir_path = Path(directory) | |
for file_path in dir_path.iterdir(): | |
print(file_path.name.split(' - ')[0]) | |
# if file_path.is_file() and not file_path.name.endswith('mkv'): | |
# new_name = file_path.name + '.mkv' | |
# new_file_path = file_path.with_name(new_name) | |
# file_path.rename(new_file_path) | |
# print(f"Renamed {file_path} to {new_file_path}") | |
if __name__ == '__main__': | |
# source_dir = Path('./old') | |
# suffix = "- ჯგუფი I.mp4" | |
# target_dir_name = "ჯგუფი I" | |
# move_files_with_suffix(source_dir, suffix, target_dir_name) | |
# video_directory = Path('./old/ჯგუფი II') | |
# rename_videos_with_date(video_directory) | |
append_mkv('./old/ჯგუფი II') | |
# enum_dates('./old/ჯგუფი II') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment