HACKERS ELITE
Bienvenido a HACKERS ELITE
porfavor registrate o inicia secion para ver todo el contenido del foro, disfruta tu visita!
Últimos temas
» Virus Informaticos
Mar Mayo 08, 2012 7:10 am por Sokoleonardo

» Servicio al PC 2010 [Hardware Reparacion y Mantenimiento De Pc's y Portatiles]
Lun Mayo 07, 2012 6:48 pm por ilcanale

» Como Hackear Facebook 2011 muy Facil Paso a Paso
Miér Mayo 02, 2012 2:47 pm por d(>_<)b

» Nueva seccion
Miér Mayo 02, 2012 2:40 pm por d(>_<)b

» Necesito ayuda en forma de contacto
Sáb Abr 28, 2012 8:54 am por JFlores

» Crear menus profecionales en Tkinter. by Sokoleonardo
Jue Mar 01, 2012 6:59 am por Sokoleonardo

» Se deberia poder fijar un tema a la cabeza del subforo.
Dom Feb 26, 2012 11:20 pm por milaras21

» Tema de prueba 2
Vie Feb 24, 2012 6:28 pm por milaras21

» Imagico. Enconvierte imagenes JPG y PNG. BMP, a *.ico
Vie Feb 24, 2012 12:25 pm por Sokoleonardo

» Hardwipe 1.5.0
Vie Feb 24, 2012 1:37 am por [D]ement<<<

» Sandboxie 3.64
Vie Feb 24, 2012 1:32 am por [D]ement<<<

Buscar
 
 

Resultados por:
 


Rechercher Búsqueda avanzada

Mayo 2012
LunMarMiérJueVieSábDom
 123456
78910111213
14151617181920
21222324252627
28293031   

Calendario Calendario


[Python-Tkinter] EasyMp3Edit

Ver el tema anterior Ver el tema siguiente Ir abajo

[Python-Tkinter] EasyMp3Edit

Mensaje por Sokoleonardo el Dom Ene 29, 2012 2:37 pm

Este es un editor de informacion de etiquetas mp3 que hice.


Código:

# -*- coding: cp1252 -*-
from Tkinter import *
from tkFileDialog import askopenfilename
from tkMessageBox import showerror, showwarning
from tkFont import Font
from mutagen.mp3 import EasyMP3 as MP3
from os.path import getsize, exists, splitdrive
from sys import argv
from platform import system as OS_NAME

MIDISCO = splitdrive(argv[0])[0]+"\\"

TiposMode = ["Stereo", "Joint Stereo", "DualChannel", "Mono"]#0-3

def GetSizeToString(bytes):
    #Pasa los bytes 7589108 a 7.23Mb
    Mb = str(bytes / 1024.0 / 1024.0)
    if "." in Mb: cifra1, cifra2 = Mb.split(".")
    else: cifra1, cifra2 = Mb, "0"
    tamanio = (cifra1 if int(cifra1) < 1024 else str(int(cifra1)/1000))+"."+(cifra2[:2] if len(cifra2) > 1 else cifra2[0])+("Mb" if int(cifra1) < 1024 else "Gb")
    return tamanio


def GetTimerString(inSegs):
    """enconvert segs 377 to 06:17
        >>> GetTimeNormalTrack(3600) #1 HS
        1:00:00"""
    hours = 0
    mins = 0
    segs = 0
    for i in range(int(inSegs)):
        segs += 1
        if segs > 59:
            segs = 0
            mins += 1
            if mins > 59:
                mins = 0
                hours += 1
    return (str(hours)+":" if hours != 0 else "")+(str(mins) if mins > 9 else "0"+str(mins))+":"+(str(segs) if segs > 9 else "0"+str(segs))

def ArchivoErrorBox(file):
    showerror("Error", 'El archivo "'+file+'" no funciona en EasyTagEdit')

class Body:
    def __init__(self):
        self.ventana = Tk()
        self.ventana.geometry("440x330")
        self.ventana.title('EasyMp3Edit - presiona el boton "Abrir nuevo"')
        self.ventana.resizable(False, False)
        icono = "EasyTagEdit."+("ico" if OS_NAME() == "Windows" else "png")
        try:
            self.ventana.iconbitmap(icono)
            ERROR_ICON = False
        except:
            ERROR_ICON = True
        #MENU TOP
        self.BaseMenus = LabelFrame(self.ventana, bg = "gray60", relief = "raised")
        self.BaseMenus.pack(side = TOP, fill = X)
        self.Boton_Menu_Archivo = Menubutton(self.BaseMenus, text = "Archivo", bg = "gray65", fg = "white", activebackground = "gray70", activeforeground = "white")
        self.Boton_Menu_Archivo.pack(side = LEFT)
        self.Menu_Archivo = Menu(self.Boton_Menu_Archivo, tearoff = False, bg = "gray65", fg = "white", activebackground = "gray90", activeforeground = "black")
        self.Menu_Archivo.add_command(label="Abrir nuevo MP3", command=self.AbrirArchivoMp3)
        self.Menu_Archivo.add_command(label="Cerrar MP3", state="disable", command=self.CerrarMp3)
        self.Menu_Archivo.add_command(label="Guardar", state="disable", command=self.GuardarActualEnActual)
        self.Menu_Archivo.add_command(label="Guardar en", state="disable", command=self.GuardarMp3Tag)
        self.Boton_Menu_Archivo["menu"] = self.Menu_Archivo
        self.Boton_Menu_Ayuda = Menubutton(self.BaseMenus, text = "Ayuda", bg = "gray65", fg = "white", activebackground = "gray70", activeforeground = "white")
        self.Boton_Menu_Ayuda.pack(side = LEFT)
        self.Menu_Ayuda = Menu(self.Boton_Menu_Ayuda, tearoff = False, bg = "gray65", fg = "white", activebackground = "gray90", activeforeground = "black")
        self.Menu_Ayuda.add_command(label="Acerca de...", command=self.AcercaDE)
        self.Boton_Menu_Ayuda["menu"] = self.Menu_Ayuda
        fontSpecial = Font(size=8, weight="bold")
        self.fondo = Canvas(self.ventana, bg="gray80", highlightbackground = "gray70")
        self.fondo.place(x=0, y=30, width=440, height=300)
        self.fondo.create_line(8,6, 430,6, fill="#000000")
        self.fondo.create_line(8,294, 430,294, fill="#000000")
        for i in range(10,290,5):
            self.fondo.create_text(7, i, fill="#FFFFFF", text="..", font=fontSpecial)
            self.fondo.create_text(431, i, fill="#FFFFFF", text="..", font=fontSpecial)
        self.BotonAbrirNuevo = Button(self.ventana, font=fontSpecial, bg="gray70", activebackground="gray60", fg="#222222", activeforeground="#222222", text="Abrir nuevo", underline=0, command=self.AbrirArchivoMp3)
        self.BotonAbrirNuevo.place(x=15, y=40, width=80, height=40)
        self.BotonCerrarActual = Button(self.ventana, font=fontSpecial, bg="gray70", activebackground="gray60", fg="#222222", activeforeground="#222222", state="disabled", text="Cerrar mp3", underline=0, command=self.CerrarMp3)
        self.BotonCerrarActual.place(x=97, y=40, width=80, height=40)
        self.BotonGuardar = Button(self.ventana, font=fontSpecial, bg="gray70", activebackground="gray60", fg="#222222", activeforeground="#222222", state="disabled", text="Guardar", underline=0, command=self.GuardarActualEnActual)
        self.BotonGuardar.place(x=179, y=40, width=80, height=40)
        self.BotonGuardarActualEn = Button(self.ventana, font=fontSpecial, bg="gray70", activebackground="gray60", fg="#222222", activeforeground="#222222", state="disabled", text="Guardar en", underline=0, command=self.GuardarMp3Tag)
        self.BotonGuardarActualEn.place(x=261, y=40, width=80, height=40)
        self.BotonAcercaDe = Button(self.ventana, font=fontSpecial, bg="gray70", activebackground="gray60", fg="#222222", activeforeground="#222222", text="Acerca de...", underline=0, command=self.AcercaDE)
        self.BotonAcercaDe.place(x=343, y=40, width=80, height=40)
        self.fondo.create_line(20,54, 418,54, fill="#000000")
        #########InfoTrack#########
        self.MarcoInfo = LabelFrame(self.ventana, bg="gray80", font=fontSpecial, text="Info MP3", fg="#000000", relief="groove")
        self.MarcoInfo.place(x=20, y=90, width=398, height=75)
        self.InfoDuracion = Label(self.MarcoInfo, bg="gray80", font=fontSpecial, text="Duracion:", fg="#472F13")
        self.InfoDuracion.place(x=10, y=0)
        self.InfoTamanyo = Label(self.MarcoInfo, bg="gray80", font=fontSpecial, text="Tamaño en disco:", fg="#472F13")
        self.InfoTamanyo.place(x=10, y=17)
        self.InfoCalidad = Label(self.MarcoInfo, bg="gray80", font=fontSpecial, text="Calidad:", fg="#472F13")
        self.InfoCalidad.place(x=10, y=34)
        #########InputInfoTrack########
        self.MarcoInputInfo = LabelFrame(self.ventana, bg="gray80", font=fontSpecial, text="Edit Info MP3", fg="#000000", relief="groove")
        self.MarcoInputInfo.place(x=20, y=170, width=398, height=145)
        Label(self.MarcoInputInfo, bg="gray80", text="Titulo:", fg="#000000").place(x=5, y=5)
        self.TituloInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.TituloInput.place(x=55, y=5, width=330)
        Label(self.MarcoInputInfo, bg="gray80", text="Artista:", fg="#000000").place(x=5, y=27)
        self.ArtistaInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.ArtistaInput.place(x=55, y=27, width=330)
        Label(self.MarcoInputInfo, bg="gray80", text="Album:", fg="#000000").place(x=5, y=49)
        self.AlbumInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.AlbumInput.place(x=55, y=49, width=130)
        Label(self.MarcoInputInfo, bg="gray80", text="Año:", fg="#000000").place(x=190, y=49)
        self.AnyoInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.AnyoInput.place(x=230, y=49, width=85)
        Label(self.MarcoInputInfo, bg="gray80", text="Pista:", fg="#000000").place(x=315, y=49)
        self.PistaInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.PistaInput.place(x=350, y=49, width=35)
        Label(self.MarcoInputInfo, bg="gray80", text="Genero:", fg="#000000").place(x=5, y=71)
        self.GeneroInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.GeneroInput.place(x=55, y=71, width=130)
        Label(self.MarcoInputInfo, bg="gray80", text="Grupo:", fg="#000000").place(x=190, y=71)
        self.GrupoInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.GrupoInput.place(x=230, y=71, width=155)
        Label(self.MarcoInputInfo, bg="gray80", text="Copyright:", fg="#000000").place(x=2, y=93)
        self.DerechosInput = Entry(self.MarcoInputInfo, bg="#FFFFFF", fg="#000000", state="disabled", relief="groove", disabledbackground="#FFFFFF")
        self.DerechosInput.place(x=55, y=93, width=330)
        self.TodasEntradas = (self.TituloInput, self.ArtistaInput, self.AlbumInput, self.AnyoInput, self.PistaInput, self.GeneroInput, self.GrupoInput, self.DerechosInput)
        #Sistema del archivo MP3:
        self.FileNameMp3 = ""
        #Chequeos:
        def ShowErrorIcon():
            if exists(icono):
                error = "'"+icono+"' es un icono corrupto, los iconos se deben hacer con programas echos para crear iconos."
            else:
                error = "'"+icono+"' no se encuentra"
            showwarning("EasyTagEdit - error en icono", error)
        if ERROR_ICON: self.ventana.after(2000, ShowErrorIcon)
        if len(argv) > 1: self.ventana.after(1000, self.AbrirArchivoArgumentado)
       

    def CerrarMp3(self):
        self.LimpiarDatos()
        for objeto in (self.BotonCerrarActual, self.BotonGuardar, self.BotonGuardarActualEn)+self.TodasEntradas:
            objeto["state"] = "disable"

    def GuardarMp3Tag(self, FILE=None):
        if not FILE:
            file = askopenfilename(title="Abrir un archivo MP3", initialdir=MIDISCO, filetypes = (("Sound","*.mp3"),))
        else:
            file = FILE
        if file:
            try:
                self.FileNameMp3 = file
                Tag = MP3(self.FileNameMp3)
                Tag["title"] = self.TituloInput.get()
                Tag["artist"] = self.ArtistaInput.get()
                Tag["album"] = self.AlbumInput.get()
                Tag["date"] = self.AnyoInput.get()
                Tag["tracknumber"] = self.PistaInput.get()
                Tag["genre"] = self.GeneroInput.get()
                Tag["performer"] = self.GrupoInput.get()
                Tag["copyright"] = self.DerechosInput.get()
                Tag.save()
            except:
                ArchivoErrorBox(file)

    def GuardarActualEnActual(self):
        self.GuardarMp3Tag(self.FileNameMp3)
       
    def LimpiarDatos(self):
        self.FileNameMp3 = ""
        for entrada in self.TodasEntradas:
            entrada.delete(0, "end")
        self.InfoDuracion["text"] = "Duracion:"
        self.InfoTamanyo["text"] = "Tamaño en disco:"
        self.InfoCalidad["text"] = "Calidad:"
        for menu in range(1,5):
            self.Menu_Archivo.entryconfigure(menu, state="disable")

    def AbrirArchivoMp3(self, FILE=None):
        if not FILE:
            file = askopenfilename(title="Abrir un archivo MP3", initialdir=MIDISCO, filetypes = (("Sound","*.mp3"),))
        else:
            file = FILE
        if file:
            try:
                self.LimpiarDatos()
                self.FileNameMp3 = file
                Tag = MP3(self.FileNameMp3)
                TagInfo = Tag.info
                anyo = Tag["date"][0] if Tag.has_key("date") else ""
                pista = Tag["tracknumber"][0] if Tag.has_key("tracknumber") else ""
                grupo = Tag["performer"][0] if Tag.has_key("performer") else ""
                compositor = Tag["composer"][0] if Tag.has_key("composer") else ""
                album = Tag["album"][0] if Tag.has_key("album") else ""
                derechos = Tag["copyright"][0] if Tag.has_key("copyright") else ""
                genero = Tag["genre"][0] if Tag.has_key("genre") else ""
                artista = Tag["artist"][0] if Tag.has_key("artist") else ""
                titulo = Tag["title"][0] if Tag.has_key("title") else ""
                segs = TagInfo.length
                self.InfoDuracion["text"] = "Duracion: "+GetTimerString(int(segs))+"  -  segs: "+str(segs)
                self.InfoTamanyo["text"] = "Tamaño en disco: "+GetSizeToString(getsize(file))
                self.InfoCalidad["text"] = "Calidad: "+str(TagInfo.sample_rate/1000)+"kHz, "+str(TagInfo.bitrate/1000)+"kbps, "+TiposMode[TagInfo.mode]
                for objeto in (self.BotonCerrarActual, self.BotonGuardar, self.BotonGuardarActualEn)+self.TodasEntradas:
                    objeto["state"] = "normal"
                for menu in range(1,5):
                    self.Menu_Archivo.entryconfigure(menu, state="normal")
                self.TituloInput.insert(0, titulo)
                self.ArtistaInput.insert(0, artista)
                self.AlbumInput.insert(0, album)
                self.AnyoInput.insert(0, anyo)
                self.PistaInput.insert(0, pista)
                self.GeneroInput.insert(0, genero)
                self.GrupoInput.insert(0, grupo)
                self.DerechosInput.insert(0, derechos)
            except:
                self.LimpiarDatos()
                for objeto in (self.BotonCerrarActual, self.BotonGuardar, self.BotonGuardarActualEn)+self.TodasEntradas:
                    objeto["state"] = "disabled"
                ArchivoErrorBox(file)
            self.ventana.title('EasyMp3Edit')

    def AbrirArchivoArgumentado(self):
        self.AbrirArchivoMp3(argv[1])

    def AcercaDE(self):
        GEOMETRY = tuple([int(str)+40 for str in self.ventana.geometry().split("+")[1:]])
        ventanaAcercaDE = Tk()
        ventanaAcercaDE.geometry("250x250+%d+%d" % GEOMETRY)
        ventanaAcercaDE.title("Acerca de EasyMp3Edit")
        ventanaAcercaDE.resizable(False, False)
        icono = "EasyTagEdit."+("ico" if OS_NAME() == "Windows" else "png")
        try:
            ventanaAcercaDE.iconbitmap(icono)
        except: pass
        Frame(ventanaAcercaDE, bg="gray10").place(x=0, y=0, width=250, height=250)
        Texto = Text(ventanaAcercaDE, bg="gray90", fg="#000000")
        Texto.place(x=5,y=5, width=240, height=240)
        Texto.insert("0.0", "Version: 1.0\nLenguaje de programacion usado: Python 2.5.0\nCreador: Leonardo A. Reichert\nFecha: 2011\nModulos usados con Python:\n  Tkinter\n  tkFileDialog\n  tkMessageBox\n  tkFont\n  mutagen.mp3\n  os.path\n  sys\n  platform\n\nPara la linea de comandos usa:\n  C:\\EasyTagEdit.py archivo.mp3\n\nGracias por usar EasyMp3Edit")
        Texto["state"] = "disabled"

       
Machine = Body()
Machine.ventana.mainloop()



Saludos!

Sokoleonardo
Moderador de Seccion
Moderador de Seccion

Mensajes: 52
Nivel: 138
Reputación: 4
Fecha de inscripción: 04/08/2011
Vive en Vive en: Argentina

Volver arriba Ir abajo

Ver el tema anterior Ver el tema siguiente Volver arriba

- Temas similares

Permiso de este foro:
No puedes responder a temas en este foro.