Skip to content

Commit

Permalink
ajout traiteemtn fichier sans metadata et réduction de la taille de l…
Browse files Browse the repository at this point in the history
…'image en cas de besoin
  • Loading branch information
Paullux committed Jan 10, 2024
1 parent 8839467 commit 74b24a0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
19 changes: 18 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
elif platform.system() == 'Windows':
import psutil
import tempfile
from PIL import Image
import sys
import os
import random
Expand Down Expand Up @@ -222,6 +223,17 @@ def __init__(self):
self.initUI()
pygame.mixer.init()

def resize_cover(self, cover_path, size=(252, 252)):
with Image.open(cover_path) as img:
# Redimensionner l'image
img.thumbnail(size, Image.LANCZOS)

# Créer un fichier temporaire
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.jpg')
img.save(temp_file.name, 'JPEG')

return temp_file.name

async def envoyer_image(self, chemin_fichier, title, artist):
if is_discord_running():
try:
Expand Down Expand Up @@ -942,10 +954,14 @@ def get_metadata(self, file_path):
audio = WAVE(file_path)
else:
return None # Format non supporté ou inconnu

# Obtenez le nom de base du fichier sans l'extension
base_name = os.path.basename(file_path)
file_title = os.path.splitext(base_name)[0]

# Assurez-vous de récupérer la chaîne complète si la valeur est une liste
metadata['artist'] = ' '.join(audio.get('artist', ['Unknown Artist']))
metadata['title'] = ' '.join(audio.get('title', ['Unknown Title']))
metadata['title'] = ' '.join(audio.get('title', [file_title]))
metadata['album'] = ' '.join(audio.get('album', ['Unknown Album']))
metadata['tracknumber'] = ' '.join(audio.get('tracknumber', ['0'])).split('/')[0]

Expand Down Expand Up @@ -1205,6 +1221,7 @@ def play_track(self, index):
cover_path = image_files[0]
else:
cover_path = os.path.join(self.application_path, 'data', 'Music bot.png')
cover_path = self.resize_cover(cover_path)
pixmap = QPixmap(cover_path)
if cover_path:
self.albumArtLabel.setPixmap(pixmap.scaled(200, 200, Qt.KeepAspectRatio))
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ asyncio
pyimgur
requests
python-dotenv
psutil
psutil
Pillow
Binary file removed temp.wav
Binary file not shown.

0 comments on commit 74b24a0

Please sign in to comment.