YnM Mp3 Copyright check

Mp3id.py

import os
import acoustid
import schedule
import time
from sopel import plugin

# AcoustID API kulcs (javasolt környezeti változóból beállítani)
API_KEY = os.getenv("ACOUSTID_API_KEY", "abdsfdFSD") # https://acoustid.org/

# Ellenőrző funkció
def check_audio(file_path, log_file_path, bot):
    try:
        print(f"Ellenőrzés folyamatban: {file_path}")
        result = acoustid.match(API_KEY, file_path)
        if not result:
            with open(log_file_path, "a") as log_file:
                log_file.write(f"Hiba: Nincs találat a fájlra: {file_path}\n")
            return False

        for score, recording_id, title, artist in result:
            if score > 0.8:
                # Jogvédett fájl találat
                with open(log_file_path, "a") as log_file:
                    log_file.write(f"Jogvédett fájl: {file_path} - {title} - {artist}\n")
                bot.say(f"Jogvédett tartalom találat! @Zsolt -> {title} - {artist} ({file_path})", '#Magyar')
                os.remove(file_path)  # Jogvédett fájl törlése
                bot.say(f"Törölve: {file_path}", '#Magyar')
                return True

        # Ha nincs jogvédett fájl, False visszatérés
        return False

    except Exception as e:
        with open(log_file_path, "a") as log_file:
            log_file.write(f"Hiba a fájl ellenőrzése közben: {file_path} - {str(e)}\n")
        return False

# Mappa bejárása rekurzívan
def scan_directory(directory, log_file_path, bot):
    for root, _, files in os.walk(directory):
        for file in files:
            if file.endswith(".mp3"):
                file_path = os.path.join(root, file)
                check_audio(file_path, log_file_path, bot)

# Manuális parancs
@plugin.rule(r'\[Markus\]!mp3')
@plugin.rule(r'\[Zsolt\]!mp3')
@plugin.command('scan_mp3')
def scan_mp3_command(bot, trigger):
    directory_to_scan = "/media/mp3/Zsolt"
    log_file_path = "/home/ai/ID/mp3.log"

    bot.say(f"MP3 fájlok ellenőrzése elindult a következő mappában: {directory_to_scan}...", trigger.sender)
    scan_directory(directory_to_scan, log_file_path, bot)
    bot.say("Az MP3 fájlok ellenőrzése befejeződött.", trigger.sender)

# Automatikus napi futtatás
def job(bot):
    directory_to_scan = "/media/mp3/Zsolt"
    log_file_path = "/home/ai/ID/mp3.log"
    bot.say(f"MP3 fájlok ellenőrzése elindult a következő mappában: {directory_to_scan}...", "#Magyar")
    scan_directory(directory_to_scan, log_file_path, bot)
    bot.say("Az MP3 fájlok ellenőrzése befejeződött.", "#Magyar")

# Időzítés beállítása
def setup_schedule(bot):
    schedule.every().day.at("00:00").do(job, bot)

    while True:
        schedule.run_pending()
        time.sleep(60)

# Bot indításakor fut
@plugin.event('READY')
def ready_event(bot):
    setup_schedule(bot)

Mp3 Copyright 1.2

#!/usr/bin/env python3
import os
import acoustid
import schedule
import time
from sopel import plugin

# 🔹 AcoustID API kulcs (érdemes környezeti változóban tárolni)
API_KEY = os.getenv("ACOUSTID_API_KEY", "********")

# 🔹 Ellenőrző funkció
def check_audio(file_path, log_file_path, bot):
    try:
        print(f"🔍 Ellenőrzés folyamatban: {file_path}")
        result = list(acoustid.match(API_KEY, file_path))
        
        if not result:
            with open(log_file_path, "a") as log_file:
                log_file.write(f"Hiba: Nincs találat a fájlra: {file_path}\n")
            return False

        for result_item in result:
            score = result_item[0]
            recording_id = result_item[1]
            title = result_item[2] if len(result_item) > 2 else "Ismeretlen cím"
            artist = result_item[3] if len(result_item) > 3 else "Ismeretlen előadó"

            if score > 0.8:
                # 🔴 Jogvédett fájl találat
                with open(log_file_path, "a") as log_file:
                    log_file.write(f"⚠️ Jogvédett fájl: {file_path} - {title} - {artist}\n")

                for channel in ["#Magyar"]:  # Ide vehetsz fel több csatornát is
                    bot.say(f"⚠️ Jogvédett tartalom találat! @Zsolt -> {title} - {artist} ({file_path})", channel)

                os.remove(file_path)  # Jogvédett fájl törlése
                for channel in ["#Magyar"]:
                    bot.say(f"🗑️ Törölve: {file_path}", channel)

                return True

        return False

    except Exception as e:
        with open(log_file_path, "a") as log_file:
            log_file.write(f"❌ Hiba a fájl ellenőrzése közben: {file_path} - {str(e)}\n")
        return False

# 🔹 Mappa bejárása rekurzívan
def scan_directory(directory, log_file_path, bot):
    try:
        for root, _, files in os.walk(directory):
            for file in files:
                if file.lower().endswith(".mp3"):
                    file_path = os.path.join(root, file)
                    check_audio(file_path, log_file_path, bot)
    except Exception as e:
        bot.say(f"❌ Hiba az MP3 ellenőrzés során: {str(e)}", "#Magyar")

# 🔹 Manuális parancs IRC-ről
@plugin.rule(r'\[Markus\]!mp3')
@plugin.rule(r'\[Zsolt\]!mp3')
@plugin.command('scan_mp3')
def scan_mp3_command(bot, trigger):
    directory_to_scan = "/media/f8/zsolt"
    log_file_path = "/home/ai/ID/mp3.log"

    bot.say(f"📂 MP3 fájlok ellenőrzése elindult a következő mappában: {directory_to_scan}...", trigger.sender)
    scan_directory(directory_to_scan, log_file_path, bot)
    bot.say("✅ Az MP3 fájlok ellenőrzése befejeződött.", trigger.sender)

# 🔹 Automatikus napi futtatás
def job(bot):
    directory_to_scan = "/media/f8/zsolt"
    log_file_path = "/home/ai/ID/mp3.log"
    
    bot.say(f"🕒 Automatikus MP3 ellenőrzés elindult: {directory_to_scan}...", "#Magyar")
    scan_directory(directory_to_scan, log_file_path, bot)
    bot.say("✅ Automatikus ellenőrzés befejezve.", "#Magyar")

# 🔹 Időzítés beállítása
def setup_schedule(bot):
    schedule.every().day.at("00:00").do(job, bot)

    while True:
        schedule.run_pending()
        time.sleep(60)

# 🔹 Bot indításakor időzítés beállítása
@plugin.event('READY')
def ready_event(bot):
    setup_schedule(bot)