Can seek to any point of song

git-svn-id: file:///home/anna/Desktop/ocarina-legacy/mithos/ocarina@44 1daee41c-8060-4895-b1f0-2197c00d777a
This commit is contained in:
bjschuma 2009-07-04 20:18:53 +00:00
parent 4dcd210f3e
commit 57393a9150
16 changed files with 79 additions and 77 deletions

View File

@ -11,7 +11,9 @@ clean:
rm *~ rm *~
install: install:
rsync src/ ~/bin/ocarina-bin/ # mkdir ~/bin/ocarina-bin
rsync -avz src/ ~/bin/ocarina-bin/src
rsync -avs images/ ~/bin/ocarina-bin/images
# rsync *.py ~/bin/ocarina-bin/ # rsync *.py ~/bin/ocarina-bin/
cp ocarina ~/bin/ocarina-bin/ cp ocarina ~/bin/ocarina-bin/
rm ~/bin/ocarina rm ~/bin/ocarina

View File

@ -1,23 +1,22 @@
import pygtk
pygtk.require('2.0')
import gtk import gtk
from image import Image
class Button(gtk.Button): class Button(gtk.Button):
def __init__(self,name,image,text,func): def __init__(self,name,image,text,func):
gtk.Button.__init__(self) gtk.Button.__init__(self)
self.set_relief(gtk.RELIEF_NONE) self.set_relief(gtk.RELIEF_NONE)
box = gtk.HBox(True,0) box = gtk.HBox(True,0)
# Add an image if we were given one
if image!= None: if image!= None:
box.pack_start(image,True,True,0) box.pack_start(image,True,True,0)
#box.add(image) # Add text if we were given some
if text != None: if text != None:
label = gtk.Label(text) label = gtk.Label(text)
label.set_line_wrap(True) label.set_line_wrap(True)
label.set_size_request(100,100) label.set_size_request(100,100)
label.show() label.show()
box.pack_start(label,True,True,0) box.pack_start(label,True,True,0)
# Show and add callback function
box.show() box.show()
self.add(box) self.add(box)
self.connect("clicked",func,name) self.connect("clicked",func,name)

View File

@ -1,5 +1,3 @@
import pygtk
pygtk.require('2.0')
import gtk import gtk

View File

@ -1,7 +1,7 @@
import os import os
import gobject import gobject
import pygtk #import pygtk
pygtk.require('2.0') #pygtk.require('2.0')
import gtk import gtk
from button import Button from button import Button
@ -37,11 +37,23 @@ class ControlPanel(gtk.HBox):
vbox = gtk.VBox() vbox = gtk.VBox()
pbar = gtk.ProgressBar() pbar = gtk.ProgressBar()
pbar.set_fraction(0) pbar.set_fraction(0)
vbox.pack_start(pbar,True,False,0) event = gtk.EventBox()
event.add(pbar)
vbox.pack_start(event,True,False,0)
#vbox.pack_start(pbar,True,False,0)
self.pack_start(vbox,True,True,0) self.pack_start(vbox,True,True,0)
event.connect("button_release_event",self.pbarclick,pbar)
event.show()
vbox.show() vbox.show()
pbar.show() pbar.show()
gobject.timeout_add(100,self.updatePBar,pbar) gobject.timeout_add(1000,self.updatePBar,pbar)
def pbarclick(self,widgit,data,pbar):
if data.button == 1:
prcnt = float(data.x) / float(pbar.get_allocation()[2])
self.data.song.seek(int(prcnt * self.data.song.info.duration * 1000000000))
#print float(data.x)/float(pbar.get_allocation()[0])
# Play/Pause function # Play/Pause function
@ -66,12 +78,13 @@ class ControlPanel(gtk.HBox):
# Update time/progress of the progress bar # Update time/progress of the progress bar
def updatePBar(self,pbar): def updatePBar(self,pbar):
if self.data.song and (self.data.song.playing == False):
return True
try: try:
(success,time) = self.data.song.curTime() (success,time) = self.data.song.curTime()
except: except:
success = False success = False
if success == True: if success == True:
#time = time/1000000000
pbar.set_fraction(float(time)/self.data.song.info.duration) pbar.set_fraction(float(time)/self.data.song.info.duration)
pbar.set_text(self.data.song.info.fixTime(time) + " / " + self.data.song.info.length) pbar.set_text(self.data.song.info.fixTime(time) + " / " + self.data.song.info.length)
return True return True

View File

@ -1,7 +1,6 @@
import pygtk
pygtk.require('2.0')
import gtk import gtk
class Image(gtk.Image): class Image(gtk.Image):
def __init__(self,path): def __init__(self,path):
gtk.Image.__init__(self) gtk.Image.__init__(self)

View File

@ -1,7 +1,4 @@
import pango import pango
import gobject
import pygtk
pygtk.require('2.0')
import gtk import gtk
@ -13,24 +10,24 @@ class InfoView(gtk.VBox):
self.album = self.makeLabel("",10000,400) self.album = self.makeLabel("",10000,400)
self.artist = self.makeLabel("",10000,400) self.artist = self.makeLabel("",10000,400)
self.changeLabels() self.changeLabels()
gobject.timeout_add(1000,self.changeLabels)
self.show() self.show()
# Called when the song changes
def changeLabels(self): def changeLabels(self):
title = "" title = ""
album = "" album = ""
artist = "" artist = ""
if self.data.song: if self.data.song:
title = self.data.song.info.title title = self.data.song.info.title.title()
album = "from "+self.data.song.info.album album = "from "+self.data.song.info.album.title()
artist = "by "+self.data.song.info.artist artist = "by "+self.data.song.info.artist.title()
self.title.set_text(title) self.title.set_text(title)
self.album.set_text(album) self.album.set_text(album)
self.artist.set_text(artist) self.artist.set_text(artist)
return True
# Set the text, font, and weight of a label
def makeLabel(self,text,size,weight): def makeLabel(self,text,size,weight):
label = gtk.Label(text) label = gtk.Label(text)
align = gtk.Alignment(0,1,0,0) align = gtk.Alignment(0,1,0,0)

View File

@ -1,6 +1,4 @@
import gobject import gobject
import pygtk
pygtk.require('2.0')
import gtk import gtk
from menuItem import MenuItem from menuItem import MenuItem
@ -39,10 +37,9 @@ class LibView(gtk.VBox):
for album in self.data.library.artAlb[artist]: for album in self.data.library.artAlb[artist]:
aliter = tree.append(ariter,[album.title(),-1]) aliter = tree.append(ariter,[album.title(),-1])
for track in self.data.library.albTrk[(artist,album)]: for track in self.data.library.albTrk[(artist,album)]:
tree.append(aliter,[self.data.library.files[track].title,self.data.library.files[track].id]) tree.append(aliter,[self.data.library.files[track].title.title(),self.data.library.files[track].id])
tree.set_sort_column_id(0,gtk.SORT_ASCENDING) tree.set_sort_column_id(0,gtk.SORT_ASCENDING)
self.treeview = gtk.TreeView(tree) self.treeview = gtk.TreeView(tree)
#self.treeview.set_hover_expand(True)
self.treeview.set_enable_search(True) self.treeview.set_enable_search(True)
self.treeview.connect("button_release_event",self.clicked) self.treeview.connect("button_release_event",self.clicked)
self.col = gtk.TreeViewColumn('Library ('+str(self.data.library.count)+')') self.col = gtk.TreeViewColumn('Library ('+str(self.data.library.count)+')')

View File

@ -1,7 +1,6 @@
import pygtk
pygtk.require('2.0')
import gtk import gtk
class MenuItem(gtk.MenuItem): class MenuItem(gtk.MenuItem):
# #
def __init__(self,lbl,func,text,data,subs): def __init__(self,lbl,func,text,data,subs):

View File

@ -1,9 +1,7 @@
import random import random
import gobject
import pygtk
pygtk.require('2.0')
import gtk import gtk
import thread import thread
import re
from menuItem import MenuItem from menuItem import MenuItem
from song import Song from song import Song
@ -13,11 +11,12 @@ PAFTER = 1
# This is both the playlist and the queue # This is both the playlist and the queue
class PlistView(gtk.Notebook): class PlistView(gtk.Notebook):
def __init__(self,data): def __init__(self,data,info):
gtk.Notebook.__init__(self) gtk.Notebook.__init__(self)
self.connect("switch-page",self.changedTab) self.connect("switch-page",self.changedTab)
self.set_scrollable(True) self.set_scrollable(True)
self.data = data self.data = data
self.info = info
self.controls = None self.controls = None
self.status = CONTINUE self.status = CONTINUE
@ -89,6 +88,7 @@ class PlistView(gtk.Notebook):
self.pfilter.set_visible_func(self.hideRows) self.pfilter.set_visible_func(self.hideRows)
self.psort = gtk.TreeModelSort(self.pfilter) self.psort = gtk.TreeModelSort(self.pfilter)
self.ptree.set_model(self.psort) self.ptree.set_model(self.psort)
#self.pfilter.set_child(self.ptreesel) #self.pfilter.set_child(self.ptreesel)
@ -112,7 +112,7 @@ class PlistView(gtk.Notebook):
i = len(dst) i = len(dst)
for index in src: for index in src:
track = self.data.library.files[index] track = self.data.library.files[index]
dst.insert(i,[track.id,track.title,track.length,track.artist,track.album,track.count]) dst.insert(i,[track.id,track.title.title(),track.length,track.artist.title(),track.album.title(),track.count])
time+=track.duration time+=track.duration
i+=1 i+=1
return time return time
@ -135,7 +135,7 @@ class PlistView(gtk.Notebook):
col = gtk.TreeViewColumn(cols[i],cell) col = gtk.TreeViewColumn(cols[i],cell)
col.add_attribute(cell,'text',i) col.add_attribute(cell,'text',i)
col.set_resizable(True) col.set_resizable(True)
#col.set_sort_column_id(i) col.set_sort_column_id(i)
col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED) col.set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
col.set_min_width(2) col.set_min_width(2)
col.set_max_width(700) col.set_max_width(700)
@ -272,6 +272,7 @@ class PlistView(gtk.Notebook):
if self.data.song: if self.data.song:
self.data.song.close() self.data.song.close()
self.data.song = Song(self.data.library.files[self.data.curSong],self.next) self.data.song = Song(self.data.library.files[self.data.curSong],self.next)
self.info.changeLabels()
if scroll == True: if scroll == True:
self.gotoCurSong() self.gotoCurSong()
@ -299,7 +300,7 @@ class PlistView(gtk.Notebook):
def enqueue(self,widgit,func,data): def enqueue(self,widgit,func,data):
(model,pathlist) = self.ptreesel.get_selected_rows() (model,pathlist) = self.ptreesel.get_selected_rows()
for path in pathlist: for path in pathlist:
q = self.plist[path] q = self.pfilter[path]
self.data.curQ+=[q[0]] self.data.curQ+=[q[0]]
self.qlist.append([q[0],q[1],q[2],q[3],q[4],q[5]]) self.qlist.append([q[0],q[1],q[2],q[3],q[4],q[5]])
self.qtime+=self.data.library.files[q[0]].duration self.qtime+=self.data.library.files[q[0]].duration
@ -323,18 +324,17 @@ class PlistView(gtk.Notebook):
def textTyped(self,entry): def textTyped(self,entry):
self.search = entry.get_text().lower() self.search = entry.get_text().lower()
self.pfilter.refilter() self.pfilter.refilter()
self.gotoCurSong()
def hideRows(self,list,iter): def hideRows(self,list,iter):
if self.search != "": if self.search != "":
title = list[iter][1].lower() file = self.data.library.files[list[iter][0]]
if title.find(self.search) > -1: if re.search(self.search,file.title):
return True return True
artist = list[iter][3].lower() elif re.search(self.search,file.artist):
if artist.find(self.search) > -1:
return True return True
album = list[iter][4].lower() elif re.search(self.search,file.album):
if album.find(self.search) > -1:
return True return True
return False return False
return True return True

View File

@ -1,14 +1,14 @@
import urllib2 import urllib2
import pygtk #import pygtk
pygtk.require('2.0') #pygtk.require('2.0')
import gtk import gtk
import webbrowser import webbrowser
import thread #import thread
import hashlib import hashlib
from button import Button from button import Button
import xml.dom #import xml.dom
from xml.dom import minidom from xml.dom import minidom
@ -58,9 +58,10 @@ class Scrobbler(gtk.VBox):
# Open to authorization page # Open to authorization page
def authorize(self): def authorize(self):
url = "http://www.last.fm/api/auth/?" url = "http://www.last.fm/api/auth/?api_key="+self.key
(url,list) = self.addParam(url,[],"api_key",self.key) #(url,list) = self.addParam(url,[],"api_key",self.key)
(url,list) = self.addParam(url,[],"token",self.token) (url,list) = self.addParam(url,[],"token",self.token)
print url
#url+="&"+self.token #url+="&"+self.token
webbrowser.open(url) webbrowser.open(url)
@ -74,13 +75,13 @@ class Scrobbler(gtk.VBox):
print url print url
#status = self.placeRequest(url) #status = self.placeRequest(url)
return return
attr = status.getAttributeNode("status") #attr = status.getAttributeNode("status")
if attr.value != "ok": #if attr.value != "ok":
return # return
node = status.firstChild.firstChild #node = status.firstChild.firstChild
user = node.data #user = node.data
key = node.nextSibling.data #key = node.nextSibling.data
subscriber = node.nextSibling.nextSibling.data #subscriber = node.nextSibling.nextSibling.data
#print user,key,subscriber #print user,key,subscriber
@ -113,7 +114,7 @@ class Scrobbler(gtk.VBox):
def placeRequest(self,url): def placeRequest(self,url):
print url #print url
req = urllib2.Request(url) req = urllib2.Request(url)
req.add_header('User-Agent','Ocarina') req.add_header('User-Agent','Ocarina')
return minidom.parse(urllib2.urlopen(req)).documentElement return minidom.parse(urllib2.urlopen(req)).documentElement

View File

@ -1,7 +1,7 @@
import os import os
import re import re
import tagpy import tagpy
import cPickle as pickle #import cPickle as pickle
from songInfo import SongInfo from songInfo import SongInfo
import thread import thread
@ -9,7 +9,7 @@ import thread
class Library: class Library:
#def __init__(self,prnt): #def __init__(self,prnt):
def __init__(self): def __init__(self):
self.goodTypes = ["ogg","mp3","wav","avi","flac","mid"]#,"wma"] self.goodTypes = ["ogg","mp3","wav","flac","mid"]#,"wma"]
self.reset() self.reset()
self.scanning = False self.scanning = False
#self.notAdded = open("/home/bjschuma/Desktop/notAdded.txt",'w') #self.notAdded = open("/home/bjschuma/Desktop/notAdded.txt",'w')
@ -104,8 +104,12 @@ class Library:
info.setTime(a.length) info.setTime(a.length)
except: except:
print info.filename print info.filename
artist = info.artist.lower()
album = info.album.lower() info.title = info.title.lower()
info.album = info.album.lower()
info.artist = info.artist.lower()
artist = info.artist
album = info.album
if (artist in self.artAlb.keys()) == False: if (artist in self.artAlb.keys()) == False:

View File

@ -1,16 +1,10 @@
import gobject
import os
import sys import sys
import thread
import pygtk
pygtk.require('2.0')
import gtk import gtk
import gobject
from options import Options from options import Options
from saveddata import SavedData from saveddata import SavedData
from song import Song
from window import Window from window import Window
gobject.threads_init() gobject.threads_init()

View File

@ -1,9 +1,7 @@
import gobject
import os import os
import cPickle as pickle import cPickle as pickle
from library import Library from library import Library
from song import Song
class SavedData: class SavedData:
def __init__(self,options): def __init__(self,options):

View File

@ -1,7 +1,3 @@
import sys
import time
import pygst
pygst.require("0.10")
import gst import gst
@ -10,6 +6,7 @@ class Song():
def __init__(self,info,next): def __init__(self,info,next):
self.next = next self.next = next
self.info = info self.info = info
self.position = 0
self.player = gst.Pipeline("player") self.player = gst.Pipeline("player")
self.bin = gst.element_factory_make("playbin",None) self.bin = gst.element_factory_make("playbin",None)
self.bin.set_property("uri","file://"+self.info.filename) self.bin.set_property("uri","file://"+self.info.filename)
@ -56,7 +53,12 @@ class Song():
self.player.set_state(gst.STATE_PAUSED) self.player.set_state(gst.STATE_PAUSED)
self.playing = False self.playing = False
self.current = 0 self.current = 0
self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current) #self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,self.current)
self.seek(current)
def seek(self,time):
self.player.seek_simple(self.time_format,gst.SEEK_FLAG_FLUSH,time)
# Close the song # Close the song

View File

@ -1,3 +1,5 @@
class SongInfo: class SongInfo:
def __init__(self): def __init__(self):
self.id = 0 self.id = 0

View File

@ -1,6 +1,3 @@
import gobject
import pygtk
pygtk.require('2.0')
import gtk import gtk
import thread import thread
@ -122,7 +119,7 @@ class Window(gtk.Window):
infoview = InfoView(self.data) infoview = InfoView(self.data)
topRight.pack_start(infoview,False,False,0) topRight.pack_start(infoview,False,False,0)
rightPane.pack_start(topRight,False,False,0) rightPane.pack_start(topRight,False,False,0)
self.plistview = PlistView(self.data) self.plistview = PlistView(self.data,infoview)
topRight.pack_end(self.plistview.searchBar,False,False,0) topRight.pack_end(self.plistview.searchBar,False,False,0)
rightPane.add(self.plistview) rightPane.add(self.plistview)
self.makeBottomRow(rightPane) self.makeBottomRow(rightPane)