Skip to content

Commit

Permalink
Merge pull request #28 from pat1/python3
Browse files Browse the repository at this point in the history
Python3
  • Loading branch information
pat1 authored Jan 14, 2020
2 parents c1aa1d9 + a1ef269 commit 0bea6a1
Show file tree
Hide file tree
Showing 88 changed files with 1,824 additions and 1,635 deletions.
66 changes: 42 additions & 24 deletions autoplayergui
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
# -*- coding: utf-8 -*-
# GPL. (C) 2013 Paolo Patruno.

from __future__ import division
from __future__ import print_function
from future import standard_library
standard_library.install_aliases()
from builtins import range
from builtins import object
from past.utils import old_div
from autoradio.mpris2.mediaplayer2 import MediaPlayer2
from autoradio.mpris2.player import Player
from autoradio.mpris2.tracklist import TrackList
Expand All @@ -10,12 +17,23 @@ from autoradio.mpris2.some_players import Some_Players
from autoradio.mpris2.utils import get_players_uri
from autoradio.mpris2.utils import get_session
from dbus.mainloop.glib import DBusGMainLoop
import pygtk, gtk
import os,stat,time,urlparse,urllib,optparse,sys
#import pygtk
try:
from gi import pygtkcompat
except ImportError:
pygtkcompat = None

if pygtkcompat is not None:
pygtkcompat.enable()
pygtkcompat.enable_gtk(version='3.0')

import gtk

import os,stat,time,urllib.parse,urllib.request,urllib.parse,urllib.error,optparse,sys
import gobject
import dbus
import autoradio.settings
import urlparse
import urllib.parse
import traceback

busaddress=autoradio.settings.busaddressplayer
Expand All @@ -38,11 +56,11 @@ class Main(object):
return False

def playhandler(self, *args, **kw):
#print args, kw
playbackstatus = args[2].get("PlaybackStatus",None)
position = args[2].get("Position",None)
playbackstatus = args[1].get("PlaybackStatus",None)
position = args[1].get("Position",None)

if playbackstatus is not None:
print "PlaybackStatus",playbackstatus
print("PlaybackStatus",playbackstatus)

if playbackstatus == "Stopped":
self.play_button.set_sensitive(True)
Expand All @@ -63,7 +81,7 @@ class Main(object):
if id is not None:
length=self.tl.GetTracksMetadata((id,))[0].get(u'mpris:length',None)
if position <= length and length != 0:
frac = float(position)/float(length)
frac = old_div(float(position),float(length))
else:
frac = 0
else:
Expand Down Expand Up @@ -92,7 +110,7 @@ class Main(object):
self.mp2 = MediaPlayer2(dbus_interface_info={'dbus_uri': uri,'dbus_session':bus})
self.play = Player(dbus_interface_info={'dbus_uri': uri,'dbus_session':bus})
else:
print "No players availables"
print("No players availables")
return

if hasattr (self.mp2, 'HasTrackList'):
Expand Down Expand Up @@ -144,7 +162,7 @@ class Main(object):

# Create the ProgressBar
self.pbar = gtk.ProgressBar()
self.pbar.set_orientation(gtk.PROGRESS_LEFT_TO_RIGHT)
self.pbar.set_inverted(False)
self.pbar.set_fraction(.5)
hbox.pack_start(self.pbar)
self.pbar.show()
Expand Down Expand Up @@ -188,7 +206,7 @@ class Main(object):
#gobject.timeout_add(6000,self.update)

def update(self, *args, **kw):
print "update gtktree"
print("update gtktree")
try:
new_model = self.make_list()
self.treeview.set_model(new_model)
Expand All @@ -215,15 +233,15 @@ class Main(object):
for path in paths:
iter = model.get_iter(path)
# Remove the ListStore row referenced by iter
print "remove: ",model.get_value(iter, 0)
print("remove: ",model.get_value(iter, 0))
self.tl.RemoveTrack(model.get_value(iter, 0))
#model.remove(iter)


def on_file_selected(self, widget):
multimedia_file = self.load_file.get_filename()
url=urlparse.urlsplit(multimedia_file)
uri=urlparse.urljoin("file://",urllib.unquote(url.path))
url=urllib.parse.urlsplit(multimedia_file)
uri=urllib.parse.urljoin("file://",urllib.parse.unquote(url.path))
new_model = self.make_list()
self.treeview.set_model(new_model)
self.tl.AddTrack(uri, self.play.Metadata.get(u'mpris:trackid',""), False)
Expand All @@ -238,7 +256,7 @@ class Main(object):
def open_file(self, treeview, path, column):
model = treeview.get_model()
iter = model.get_iter(path)
print "goto: ",model.get_value(iter, 0)
print("goto: ",model.get_value(iter, 0))
self.tl.GoTo(model.get_value(iter, 0))
new_model = self.make_list()
self.treeview.set_model(new_model)
Expand All @@ -253,34 +271,34 @@ class Main(object):
for track in self.tl.GetTracksMetadata( self.tl.Tracks):
listmodel.append([track.get(u'mpris:trackid',"")])
except:
print traceback.format_exc()
print "Error getting player playlist"
print(traceback.format_exc())
print("Error getting player playlist")
gtk.main_quit()

return listmodel

def id(self, column, cell, model, iter):
def id(self, column, cell, model, iter, data=None):
cell.set_property('text', model.get_value(iter, 0))
if model.get_value(iter, 0) == self.play.Metadata.get(u'mpris:trackid',None):
cell.set_property('cell-background',"red")
else:
cell.set_property('cell-background',"green")
return

def Len(self, column, cell, model, iter):
def Len(self, column, cell, model, iter, data=None):
track=self.tl.GetTracksMetadata((model.get_value(iter, 0),))
cell.set_property('text', convert_ns(track[0].get(u'mpris:length',"")))
return

def Artist(self, column, cell, model, iter):
def Artist(self, column, cell, model, iter, data=None):
track=self.tl.GetTracksMetadata((model.get_value(iter, 0),))
dir=os.path.dirname(urlparse.urlparse(track[0].get(u'xesam:url',"")).path).split('/')[-1]
dir=os.path.dirname(urllib.parse.urlparse(track[0].get(u'xesam:url',"")).path).split('/')[-1]
cell.set_property('text', track[0].get(u'xesam:artist', dir))
return

def Title(self, column, cell, model, iter):
def Title(self, column, cell, model, iter, data=None):
track=self.tl.GetTracksMetadata((model.get_value(iter, 0),))
file=os.path.basename(urlparse.urlparse(track[0].get(u'xesam:url',"")).path)
file=os.path.basename(urllib.parse.urlparse(track[0].get(u'xesam:url',"")).path)
cell.set_property('text', track[0].get(u'xesam:title',file))
return

Expand All @@ -302,5 +320,5 @@ if __name__ == "__main__":
gtk.main()
except KeyboardInterrupt :
# Clean up
print 'Keyboard Exiting'
print('Keyboard Exiting')
gtk.main_quit()
2 changes: 1 addition & 1 deletion autoradio-site.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ minelab=180
# to adjust the programming you have to make changes minsched minutes before
minsched=5

locale="it_IT.UTF-8"
locale="C.UTF-8"

user = autoradio
group = autoradio
Expand Down
2 changes: 1 addition & 1 deletion autoradio.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ minelab=180
# to adjust the programming you have to make changes minsched minutes before
minsched=5

locale="it_IT.UTF-8"
locale="C.UTF-8"

#user = pat1
#group = pat1
Expand Down
2 changes: 1 addition & 1 deletion autoradio/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
_version_="2.8.10"
_version_="3.2"
14 changes: 9 additions & 5 deletions autoradio/audaciousweb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@
"""
Show audacious playlist on a simple web server.
"""
from __future__ import print_function

from builtins import str
from builtins import range
from builtins import object
maxplele=100 # max number of elements in playlist
port=8888 # server port

Expand Down Expand Up @@ -57,7 +61,7 @@
</html>
'''

class HomePage:
class HomePage(object):

# def Main(self):
# # Let's link to another method here.
Expand Down Expand Up @@ -141,7 +145,7 @@ def index(self):
htmlresponse+='<table border="1">'
htmlresponse+='<td>posizione</td><td>durata</td><td>brano</td>'

for pos in xrange(0,min(len,maxplele)):
for pos in range(0,min(len,maxplele)):
htmlresponse+='<tr>'
metadata=tracklist.GetMetadata(pos)

Expand Down Expand Up @@ -185,7 +189,7 @@ def index(self):
col="#00FF00"
toend=""

print artist,title
print(artist,title)
if (artist is not None) or (title is not None):
htmlresponse+='<td bgcolor="%s">%i</td><td> %s // %s </td><td><a href="%s">%s // %s</a></td>' % \
(col,pos+1,str(timelength),str(toend),file,artist,title)
Expand Down Expand Up @@ -262,8 +266,8 @@ def start_http_server(iht=False):
try:
start_http_server(iht=True)
except:
print "Error"
print("Error")
raise
finally:
print "Terminated"
print("Terminated")

8 changes: 5 additions & 3 deletions autoradio/autoaudacious.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#!/usr/bin/env python
# GPL. (C) 2007-2009 Paolo Patruno.

from builtins import range
from builtins import object
import dbus
import time
import datetime
Expand All @@ -9,7 +11,7 @@
# ------- dbus interface ---------
import dbus

class audacious:
class audacious(object):


def __init__(self,session=0):
Expand Down Expand Up @@ -107,7 +109,7 @@ def playlist_clear_up(self,atlast=10):
# delete the old ones
if pos > atlast :

for prm in xrange(0,pos-atlast):
for prm in range(0,pos-atlast):
self.tracklist.DelTrack(0)

return True
Expand Down Expand Up @@ -135,7 +137,7 @@ def playlist_clear_down(self,atlast=500):
#elimino il troppo
if length-pos > atlast :

for prm in xrange(length,pos+atlast,-1):
for prm in range(length,pos+atlast,-1):
self.tracklist.DelTrack(prm)

return True
Expand Down
15 changes: 9 additions & 6 deletions autoradio/autoepris.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env python
# GPL. (C) 2007-2009 Paolo Patruno.

from __future__ import print_function
from builtins import range
from builtins import object
import dbus
import time
import datetime
Expand All @@ -10,7 +13,7 @@

import dbus

class mediaplayer:
class mediaplayer(object):


def __init__(self,session=0):
Expand Down Expand Up @@ -40,8 +43,8 @@ def play_ifnot(self):
'''
# I check if mediaplayer is playing .... otherside I try to play

print self.tracklist.ListTracks()
print self.tracklist.Current
print(self.tracklist.ListTracks())
print(self.tracklist.Current)

# if (not self.player.PlaybackStatus == "Playing"):

Expand Down Expand Up @@ -108,7 +111,7 @@ def playlist_clear_up(self,atlast=10):
# delete the old ones
if pos > atlast :

for prm in xrange(0,pos-atlast):
for prm in range(0,pos-atlast):
self.tracklist.DelTrack(0)

return True
Expand Down Expand Up @@ -137,7 +140,7 @@ def playlist_clear_down(self,atlast=500):
#elimino il troppo
if length-pos > atlast :

for prm in xrange(length,pos+atlast,-1):
for prm in range(length,pos+atlast,-1):
self.tracklist.DelTrack(prm)

return True
Expand Down Expand Up @@ -201,7 +204,7 @@ def get_playlist_pos(self):
def main():

mp=mediaplayer()
print mp
print(mp)
mp.play_ifnot()


Expand Down
13 changes: 8 additions & 5 deletions autoradio/autompris.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
# Audacious provide non standard interface to do this
# ----------------------------------------

from builtins import str
from builtins import range
from builtins import object
import dbus
import time
import datetime
Expand All @@ -17,7 +20,7 @@
import dbus


class mediaplayer:
class mediaplayer(object):


def __init__(self,player="audacious",session=0):
Expand Down Expand Up @@ -160,7 +163,7 @@ def playlist_clear_up(self,atlast=10):
# delete the old ones
if pos > atlast :

for prm in xrange(0,pos-atlast):
for prm in range(0,pos-atlast):
self.tracklist.DelTrack(0)

return True
Expand Down Expand Up @@ -188,7 +191,7 @@ def playlist_clear_down(self,atlast=500):
#elimino il troppo
if length-pos > atlast :

for prm in xrange(length,pos+atlast,-1):
for prm in range(length,pos+atlast,-1):
self.tracklist.DelTrack(prm)

return True
Expand Down Expand Up @@ -218,7 +221,7 @@ def get_playlist_posauto(self,autopath,securesec=10):
try:
#Fix how older versions of Audacious misreport the URI of the song.
if metadata is not None:
if metadata.has_key ("URI") and not metadata.has_key ("location"):
if "URI" in metadata and "location" not in metadata:
metadata["location"] = metadata["URI"]

file=metadata["location"]
Expand All @@ -241,7 +244,7 @@ def get_playlist_posauto(self,autopath,securesec=10):

#Fix how older versions of Audacious misreport the URI of the song.
if metadata is not None:
if metadata.has_key ("URI") and not metadata.has_key ("location"):
if "URI" in metadata and "location" not in metadata:
metadata["location"] = metadata["URI"]

file=metadata["location"]
Expand Down
Loading

0 comments on commit 0bea6a1

Please sign in to comment.