Files
Skripte/sort_media.py

47 lines
1.7 KiB
Python

import os
import shutil
from datetime import datetime
# Adjust the import statement based on the correct module structure
# This is a placeholder; replace with the correct import if known
# from ollama import Ollama
def get_earliest_time(file_path):
"""Get the earliest of creation or last modified time."""
stat = os.stat(file_path)
return min(stat.st_ctime, stat.st_mtime)
def sort_media(directory):
"""Sort media files into folders by their earliest time."""
if not os.path.exists(directory):
print(f"Directory {directory} does not exist.")
return
for filename in os.listdir(directory):
file_path = os.path.join(directory, filename)
if os.path.isfile(file_path):
earliest_time = get_earliest_time(file_path)
date_folder = datetime.fromtimestamp(earliest_time).strftime('%Y-%m-%d')
target_folder = os.path.join(directory, date_folder)
if not os.path.exists(target_folder):
os.makedirs(target_folder)
shutil.move(file_path, os.path.join(target_folder, filename))
def compare_images_with_ollama(directory):
"""Compare images using Ollama."""
ollama = Ollama(model="ollama3.2")
for root, _, files in os.walk(directory):
for file in files:
if file.lower().endswith(('.png', '.jpg', '.jpeg')):
file_path = os.path.join(root, file)
# Assuming Ollama has a method to compare images
result = ollama.compare(file_path)
print(f"Comparison result for {file}: {result}")
if __name__ == "__main__":
directory = input("Enter the directory path to sort and compare media: ")
sort_media(directory)
compare_images_with_ollama(directory)