Implementacion de un reproducto de musica
This commit is contained in:
parent
5b8493b67a
commit
9e31b32664
|
@ -3,6 +3,7 @@ from models.SystemStats import SystemStats
|
||||||
from MainView import MainView
|
from MainView import MainView
|
||||||
from models.NetworkingScanner import NetworkScanner
|
from models.NetworkingScanner import NetworkScanner
|
||||||
from models.Sniffer import packet_callback, sniff
|
from models.Sniffer import packet_callback, sniff
|
||||||
|
from models.MusicPlayer import MusicPlayerModel
|
||||||
import tkinter as tk
|
import tkinter as tk
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -15,6 +16,7 @@ class MainController:
|
||||||
self.sniffer_running = False
|
self.sniffer_running = False
|
||||||
self.connect_events()
|
self.connect_events()
|
||||||
self.start_system_updates()
|
self.start_system_updates()
|
||||||
|
self.music_model = MusicPlayerModel()
|
||||||
|
|
||||||
def connect_events(self):
|
def connect_events(self):
|
||||||
"""Conecta los eventos de la vista con las funciones del controlador."""
|
"""Conecta los eventos de la vista con las funciones del controlador."""
|
||||||
|
@ -23,6 +25,10 @@ class MainController:
|
||||||
self.view.button_start_sniffer.config(command=self.start_sniffer_thread)
|
self.view.button_start_sniffer.config(command=self.start_sniffer_thread)
|
||||||
self.view.button_stop_sniffer.config(command=self.stop_sniffer)
|
self.view.button_stop_sniffer.config(command=self.stop_sniffer)
|
||||||
|
|
||||||
|
self.view.button_play_music.config(command=self.play_song)
|
||||||
|
self.view.button_stop_music.config(command=self.stop_song)
|
||||||
|
self.view.button_refresh_music.config(command=self.refresh_songs)
|
||||||
|
|
||||||
|
|
||||||
def start_sniffer_thread(self):
|
def start_sniffer_thread(self):
|
||||||
"""Inicia el sniffer en un hilo separado."""
|
"""Inicia el sniffer en un hilo separado."""
|
||||||
|
@ -142,5 +148,28 @@ class MainController:
|
||||||
time.sleep(1) # Esperar 1 segundo antes de actualizar nuevamente
|
time.sleep(1) # Esperar 1 segundo antes de actualizar nuevamente
|
||||||
|
|
||||||
|
|
||||||
|
def load_songs(self):
|
||||||
|
"""Carga las canciones desde el modelo y las envía a la vista."""
|
||||||
|
self.songs, self.message = self.music_model.load_songs()
|
||||||
|
self.view.populate_music_player(self.songs)
|
||||||
|
|
||||||
|
def play_song(self):
|
||||||
|
"""Reproduce la canción seleccionada."""
|
||||||
|
selected = self.view.music_listbox.curselection()
|
||||||
|
if not selected:
|
||||||
|
self.view.root.bell()
|
||||||
|
return
|
||||||
|
song_name = self.view.music_listbox.get(selected)
|
||||||
|
message = self.music_model.play_song(song_name)
|
||||||
|
print(f"Reproduciendo: {message}")
|
||||||
|
|
||||||
|
def stop_song(self):
|
||||||
|
"""Detiene la reproducción de la canción."""
|
||||||
|
message = self.music_model.stop_song()
|
||||||
|
print(f"Detenido: {message}")
|
||||||
|
|
||||||
|
def refresh_songs(self):
|
||||||
|
"""Actualiza la lista de canciones disponibles."""
|
||||||
|
self.load_songs()
|
||||||
|
print(self.message)
|
||||||
|
|
||||||
|
|
30
MainView.py
30
MainView.py
|
@ -36,6 +36,8 @@ class MainView:
|
||||||
|
|
||||||
# Crear barra de estado en el frame inferior
|
# Crear barra de estado en el frame inferior
|
||||||
self.create_status_bar()
|
self.create_status_bar()
|
||||||
|
|
||||||
|
self.create_music_player()
|
||||||
|
|
||||||
def create_tabs(self):
|
def create_tabs(self):
|
||||||
"""Crea las solapas dentro del notebook."""
|
"""Crea las solapas dentro del notebook."""
|
||||||
|
@ -121,3 +123,31 @@ class MainView:
|
||||||
self.label_bytes_sent.pack(side="left", fill="x", expand=True)
|
self.label_bytes_sent.pack(side="left", fill="x", expand=True)
|
||||||
self.label_uso_memoria.pack(side="left", fill="x", expand=True)
|
self.label_uso_memoria.pack(side="left", fill="x", expand=True)
|
||||||
self.label_fecha_hora.pack(side="right", fill="x", expand=True)
|
self.label_fecha_hora.pack(side="right", fill="x", expand=True)
|
||||||
|
|
||||||
|
|
||||||
|
def create_music_player(self):
|
||||||
|
"""Crea el reproductor de música en el frame derecho."""
|
||||||
|
label = tk.Label(self.frame_right, text="Reproductor de Música", bg="red", fg="white", font=("Arial", 12))
|
||||||
|
label.pack(pady=10)
|
||||||
|
|
||||||
|
# Lista de canciones
|
||||||
|
self.music_listbox = tk.Listbox(self.frame_right, height=15, width=25)
|
||||||
|
self.music_listbox.pack(pady=5)
|
||||||
|
|
||||||
|
# Botones de control organizados verticalmente
|
||||||
|
self.button_play_music = ttk.Button(self.frame_right, text="Reproducir")
|
||||||
|
self.button_play_music.pack(pady=5, fill="x")
|
||||||
|
|
||||||
|
self.button_stop_music = ttk.Button(self.frame_right, text="Detener")
|
||||||
|
self.button_stop_music.pack(pady=5, fill="x")
|
||||||
|
|
||||||
|
self.button_refresh_music = ttk.Button(self.frame_right, text="Actualizar")
|
||||||
|
self.button_refresh_music.pack(pady=5, fill="x")
|
||||||
|
|
||||||
|
|
||||||
|
def populate_music_player(self, songs):
|
||||||
|
"""Llena la lista de canciones en el reproductor."""
|
||||||
|
self.music_listbox.delete(0, tk.END)
|
||||||
|
if songs:
|
||||||
|
for song in songs:
|
||||||
|
self.music_listbox.insert(tk.END, song)
|
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,37 @@
|
||||||
|
import os
|
||||||
|
from pygame import mixer
|
||||||
|
|
||||||
|
class MusicPlayerModel:
|
||||||
|
def __init__(self):
|
||||||
|
self.music_folder = "resources"
|
||||||
|
self.current_song = None
|
||||||
|
mixer.init()
|
||||||
|
|
||||||
|
def load_songs(self):
|
||||||
|
"""Carga las canciones desde la carpeta de recursos."""
|
||||||
|
if not os.path.exists(self.music_folder):
|
||||||
|
os.makedirs(self.music_folder)
|
||||||
|
return [], "Carpeta 'resources' creada. Agrega canciones."
|
||||||
|
|
||||||
|
songs = [f for f in os.listdir(self.music_folder) if f.endswith(".mp3")]
|
||||||
|
if not songs:
|
||||||
|
return [], "No se encontraron archivos MP3 en 'resources'."
|
||||||
|
|
||||||
|
return songs, "Canciones cargadas con éxito."
|
||||||
|
|
||||||
|
def play_song(self, song_name):
|
||||||
|
"""Reproduce una canción por su nombre."""
|
||||||
|
song_path = os.path.join(self.music_folder, song_name)
|
||||||
|
try:
|
||||||
|
mixer.music.load(song_path)
|
||||||
|
mixer.music.play()
|
||||||
|
self.current_song = song_name
|
||||||
|
return f"Reproduciendo: {song_name}"
|
||||||
|
except Exception as e:
|
||||||
|
return f"Error al reproducir: {e}"
|
||||||
|
|
||||||
|
def stop_song(self):
|
||||||
|
"""Detiene la reproducción de música."""
|
||||||
|
mixer.music.stop()
|
||||||
|
self.current_song = None
|
||||||
|
return "Reproducción detenida."
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
98
pruebas.py
98
pruebas.py
|
@ -1,46 +1,60 @@
|
||||||
from scapy.all import sniff
|
import tkinter as tk
|
||||||
from scapy.layers.inet import IP, TCP, UDP, ICMP
|
from tkinter import messagebox, Listbox
|
||||||
from scapy.packet import Raw
|
from models.MusicPlayer import MusicPlayerModel
|
||||||
import os
|
|
||||||
import datetime
|
|
||||||
|
|
||||||
def save_packet_to_file(packet):
|
class MusicPlayerApp:
|
||||||
"""Guarda el paquete en un archivo de registro para análisis posterior."""
|
def __init__(self, root):
|
||||||
with open("packet_log.txt", "a") as log_file:
|
self.root = root
|
||||||
log_file.write(f"{datetime.datetime.now()} - {packet.summary()}\n")
|
self.root.title("Reproductor de Música")
|
||||||
log_file.write(f"{packet.show(dump=True)}\n\n")
|
self.root.geometry("400x300")
|
||||||
|
|
||||||
|
self.player = MusicPlayerModel()
|
||||||
|
self.songs, self.message = self.player.load_songs()
|
||||||
|
|
||||||
|
# Lista de canciones
|
||||||
|
self.song_listbox = Listbox(self.root, bg="white", fg="black", font=("Arial", 12))
|
||||||
|
self.song_listbox.pack(fill=tk.BOTH, expand=True, padx=10, pady=10)
|
||||||
|
self.refresh_song_list()
|
||||||
|
|
||||||
|
# Botones
|
||||||
|
self.button_frame = tk.Frame(self.root)
|
||||||
|
self.button_frame.pack(pady=10)
|
||||||
|
|
||||||
|
self.play_button = tk.Button(self.button_frame, text="Reproducir", command=self.play_song, width=12)
|
||||||
|
self.play_button.grid(row=0, column=0, padx=5)
|
||||||
|
|
||||||
|
self.stop_button = tk.Button(self.button_frame, text="Detener", command=self.stop_song, width=12)
|
||||||
|
self.stop_button.grid(row=0, column=1, padx=5)
|
||||||
|
|
||||||
|
self.refresh_button = tk.Button(self.button_frame, text="Actualizar", command=self.refresh_song_list, width=12)
|
||||||
|
self.refresh_button.grid(row=0, column=2, padx=5)
|
||||||
|
|
||||||
def packet_callback(packet):
|
def refresh_song_list(self):
|
||||||
"""Procesa y retorna información del paquete capturado."""
|
"""Carga las canciones en el Listbox desde la carpeta resources."""
|
||||||
packet_info = []
|
self.songs, self.message = self.player.load_songs()
|
||||||
if IP in packet:
|
self.song_listbox.delete(0, tk.END)
|
||||||
ip_layer = packet[IP]
|
if self.songs:
|
||||||
packet_info.append(f"[+] Capturado un paquete:")
|
for song in self.songs:
|
||||||
packet_info.append(f" Origen: {ip_layer.src}")
|
self.song_listbox.insert(tk.END, song)
|
||||||
packet_info.append(f" Destino: {ip_layer.dst}")
|
else:
|
||||||
packet_info.append(f" Protocolo: {ip_layer.proto}")
|
messagebox.showinfo("Información", self.message)
|
||||||
|
|
||||||
if TCP in packet:
|
def play_song(self):
|
||||||
tcp_layer = packet[TCP]
|
"""Reproduce la canción seleccionada."""
|
||||||
packet_info.append(f" Puerto origen: {tcp_layer.sport}")
|
selected = self.song_listbox.curselection()
|
||||||
packet_info.append(f" Puerto destino: {tcp_layer.dport}")
|
if not selected:
|
||||||
elif UDP in packet:
|
messagebox.showwarning("Advertencia", "Selecciona una canción para reproducir.")
|
||||||
udp_layer = packet[UDP]
|
return
|
||||||
packet_info.append(f" Puerto origen: {udp_layer.sport}")
|
song_name = self.song_listbox.get(selected)
|
||||||
packet_info.append(f" Puerto destino: {udp_layer.dport}")
|
message = self.player.play_song(song_name)
|
||||||
elif ICMP in packet:
|
messagebox.showinfo("Reproduciendo", message)
|
||||||
packet_info.append(" Tipo de ICMP detectado.")
|
|
||||||
|
def stop_song(self):
|
||||||
|
"""Detiene la reproducción."""
|
||||||
|
message = self.player.stop_song()
|
||||||
|
messagebox.showinfo("Detenido", message)
|
||||||
|
|
||||||
if Raw in packet:
|
if __name__ == "__main__":
|
||||||
payload = packet[Raw].load.decode(errors="ignore")
|
root = tk.Tk()
|
||||||
packet_info.append(f" Datos (Raw): {payload}")
|
app = MusicPlayerApp(root)
|
||||||
if "youtube.com" in payload or "YouTube" in payload:
|
root.mainloop()
|
||||||
packet_info.append(f"\n[!!!] Posible enlace de YouTube detectado:")
|
|
||||||
packet_info.append(payload)
|
|
||||||
|
|
||||||
packet_info.append(f"[Paquete completo]: {packet.summary()}")
|
|
||||||
|
|
||||||
# Guardar el paquete en un archivo
|
|
||||||
save_packet_to_file(packet)
|
|
||||||
|
|
||||||
return "\n".join(packet_info)
|
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue