elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.
 
Inicio Ayuda Buscar Ingresar Registrarse
29 Mayo 2012, 05:18  


Tema destacado: Personaliza-Escoge el diseño del foro que más te guste.

+  Foro de elhacker.net
|-+  Programación
| |-+  Scripting (Moderadores: Novlucker, Leo Gutiérrez., EleKtro H@cker)
| | |-+  Reproductor cli en python
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: Reproductor cli en python  (Leído 228 veces)
Daemon Freedom
Wiki

Desconectado Desconectado

Mensajes: 488


typedef struct Nodo


Ver Perfil WWW
Reproductor cli en python
« en: 10 Diciembre 2011, 17:51 »

Hola a tod@s:

Estoy haciendo con un conocido un reproductor de música en línea de comandos muy sencillo: Recoge un diccionario con todas las canciones y las reproduce aleatoriamente. Pero tenemos un problema, sólo reproduce la 1ª canción: no pasa a la siguiente ¿Alguien ve el fallo?

Código
 
#!/usr/bin/env python2
#-*- coding: UTF-8 -*-
 
import os, gobject
import pygst
pygst.require("0.10")
import gst
 
from os.path import join, getsize
from mimetypes import guess_type
from random import shuffle
 
gobject.threads_init()
 
class AllFromDirectory():
 
def __init__(self, directory):
self.directory = directory
self.biblio = dict()
self.autoid = 0
 
def get(self):
for root, dirs, files in os.walk(self.directory):
for self.filen in files:
self.mime = guess_type(self.filen)
self.auxmime = str(self.mime[0])
self.endmime = self.auxmime.split(os.sep)
if self.endmime[0] == "audio":
self.biblio[self.autoid] = root+os.sep+self.filen
self.autoid = self.autoid + 1
 
return self.biblio
 
def getLen(self):
return len(self.biblio)
 
 
class Player():
def __init__(self):
 
# Obtenemos la lista de archivos
x = AllFromDirectory(directory)
self.biblio = x.get()
self.total_tracks = x.getLen()
self.numeros = range(0, int(self.total_tracks))
shuffle(self.numeros)
self.n = 0
 
self.create_pipeline()
 
def create_pipeline(self):
 
n = self.numeros[0]
 
self.song = self.biblio[n].split(os.sep)
print 'Reproduciendo: '+self.song[-1]
 
cdsrc = 'filesrc location="%s" name=file ! decodebin ! volume name=volume ! alsasink' % (self.biblio[n])
self.pipeline = gst.parse_launch(cdsrc)
 
bus = self.pipeline.get_bus()
 
bus.add_signal_watch()
 
bus.connect("message::tag", self.bus_message_tag)
bus.connect("message::error", self.bus_message_error)
bus.connect("message::eos", self.nexts)
 
self.pipeline.set_state(gst.STATE_PLAYING)
 
self.loop = gobject.MainLoop()
self.loop.run()
 
def bus_message_error(self, bus, message):
e, d = message.parse_error()
print "ERROR:", e
#exit(1)
 
def bus_message_tag(self, bus, message):
 
"""Esta es la función encargada de recoger los datos del bus de Gstreamer, principalmente los tags de los ficheros de audio"""
self.tags = ''
#we received a tag message
taglist = message.parse_tag()
#put the keys in the dictionary
for key in taglist.keys():
try:
self.file_tags[key] = taglist[key]
except:
return False
 
try:
self.tags += self.file_tags['title'] + " "
except:
self.tags += "Título desconocido."
 
try:
self.tags += "de: "+self.file_tags['artist']+"\n"
except:
self.tags += "Artista desconocido."
 
self.song = self.tags.split(os.sep)
print 'Reproduciendo', self.song[-1]
 
def nexts(self, w, *args):
 
if self.n < self.total_tracks:
self.n += 1
else:
self.n = 0
 
n = self.numeros[self.n]
self.song = self.biblio[n].split(os.sep)
print 'Reproduciendo: '+self.song[-1]
 
self.loop.quit()
self.pipeline.set_state(gst.STATE_NULL)
self.pipeline.get_by_name('file').set_property('location', self.biblio[n])
self.pipeline.set_state(gst.STATE_PLAYING)
self.loop.run()
 
directory = '/media/HD/Música'
mega = list()
 
p = Player()
 
 


« Última modificación: 10 Diciembre 2011, 18:10 por Daemon Freedom » En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
(Python)Existen ventanas de entrada y salida de datos en python
Scripting
tonilogar 11 4,346 Último mensaje 29 Noviembre 2009, 00:49
por tonilogar
[Python] Abrir una página web con comandos de Python. « 1 2 »
Scripting
CaronteGold 28 8,120 Último mensaje 7 Enero 2010, 17:04
por ^Tifa^
[python]VideoTraining Aprende A Programar En Python desde 0 « 1 2 »
Scripting
juh 22 5,571 Último mensaje 16 Octubre 2010, 13:12
por sheevalum
[Python] Importar Funciones de C++ a Modulo de Python
Scripting
Di6it4Lj4ck4L 2 899 Último mensaje 2 Mayo 2011, 19:08
por Di6it4Lj4ck4L
[Python] Kaley, Keylogger simple en Python
Scripting
Fyrox 0 1,072 Último mensaje 21 Septiembre 2011, 23:24
por Fyrox
Powered by SMF 1.1.16 | SMF © 2006-2008, Simple Machines