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)