Permalink
Browse files

basic config file support added

  • Loading branch information...
wendlers committed Sep 21, 2012
1 parent da7834e commit ab93f8315a33e3dfa1ddf95d6e5a7d7dc89427d5
Showing with 149 additions and 44 deletions.
  1. +17 −4 README.md
  2. +35 −0 etc/pyscmpd.conf
  3. +96 −27 src/pyscmpd.py
  4. +1 −1 src/pyscmpd/gstplayer.py
  5. +0 −12 test-src/pygst.py
View
@@ -15,6 +15,18 @@ Python based sound-cloud music server talking MPD protocol.
NOTE: only basic MPD server daemon available yet
------------------------------------------------
+Main features currently supported:
+
+* Browse predfined set of favorite users (see "etc/pyscmpd.conf")
+* Add tracks to current playlist
+* Play tracks from playlist
+* Change song order in current playlist
+* Remove somgs from playlist
+* Clear whole playlist
+* Start/stop/pause/resume songs
+* Controll volume
+* Elapsed song time and current songtime are transmitted to clients
+
Project Directory Layout
------------------------
@@ -43,7 +55,7 @@ Install
A complete installation of the pyscmpd is not supported yet. This section briefly describes what steps
are needed to make the "pyscmpd" runable from its project directory.
-_On Debian Based Linux Systems (e.g. Ubuntu, Respian, ...)_
+__On Debian Based Linux Systems (e.g. Ubuntu, Respian, ...)__
For the following steps, it is assumed, that `$HOME/src`is your working directory:
@@ -65,7 +77,7 @@ run the setup script
cd soundcloud-python
sudo python setup.py install
-Note: internet connection is needed for this step, since the installer will go and fetch some dependencies from the net.
+__Note:__ internet connection is needed for this step, since the installer will go and fetch some dependencies from the net.
*2) Install python-gst and dependencies*
@@ -97,7 +109,7 @@ Or for a GUI based client [sonata] (http://sonata.berlios.de/):
sudo apt-get install sonata
-_On Other Linux Systems_
+__On Other Linux Systems__
To be done ...
@@ -113,4 +125,5 @@ Then connect to the daemon on port "9900", e. g. with ncmcpp:
ncmpcpp -p 9900
-To change the list of your favorite users to browse, edit "favorites" in "./src/pympd.py".
+__Note:__To change basic "pyscmpd" settings, or add the list of your favorite users to browse, edit __etc/pyscmpd.conf__.
+
View
@@ -0,0 +1,35 @@
+;;;;
+;; pyscmpd v0.0.1 config file
+;;;;
+
+##
+# Server settings
+##
+[server]
+
+# tcp port server is listening to
+port=9900
+
+##
+# Logging settings
+##
+[logging]
+
+# level: one of {critical, error, warn, info, debug}
+level=info
+
+# File to which daemon should log. Uncomment to output on stdout
+;file=/tmp/pyscmpd.log
+
+##
+# Favorite users
+#
+# format: <category>: <user1>, <user2>, ...
+##
+[favorites]
+
+electroswing : shemian
+gethoswing : maddecent, barelylegit
+electrosoul : griz
+deephouse : freudeamtanzen, adriatique
+worldtrance : gogmusic
View
@@ -25,45 +25,114 @@
import gobject
import pyscmpd.scmpd as scmpd
+from ConfigParser import SafeConfigParser
+
+PYSCMPD_VERSION="0.0.1"
+
gobject.threads_init()
-mpd = None
-mainloop = None
+class PyScMpd():
-try:
+ mpd = None
+ mainloop = None
+ favorites = None
+ port = 9900
+
+ def __init__(self):
+
+ self.favorites = []
+
+ def __del__(self):
+
+ if not self.mpd == None:
+ self.mpd.quit()
+
+ if not self.mainloop == None:
+ self.mainloop.quit()
+
+ def readConfig(self, cfgFile):
+
+ parser = SafeConfigParser()
+
+ try:
+ parser.read(cfgFile)
+
+ if parser.has_section("server"):
+
+ if parser.has_option("server", "port"):
+ self.port = parser.getint("server", "port")
+
+
+ if parser.has_section("logging"):
+
+ level = "info"
+ logFile = None
+
+ if parser.has_option("logging", "level"):
+ level = parser.get("logging", "level")
+
+ if parser.has_option("logging", "file"):
+ logFile = parser.get("logging", "file")
- # logging.basicConfig(level=logging.DEBUG)
- logging.basicConfig(level=logging.INFO)
+ numeric_level = getattr(logging, level.upper(), None)
- # TODO: do not hardcode favorites :-)
- favorites = [
- {
- "name" : "test",
- "users" : [ "griz", "betamaxx", "freudeamtanzen", ]
- },
- {
- "name" : "more",
- "users" : [ "barelylegit", "maddecent", "therealmccheese", "yellowmice", ]
- },
- ]
+ if not isinstance(numeric_level, int):
+ raise ValueError('Invalid log level: %s' % loglevel)
- mpd = scmpd.ScMpdServerDaemon(favorites)
+ if logFile == None:
- mainloop = gobject.MainLoop()
- mainloop.run()
+ logging.basicConfig(
+ level=numeric_level,
+ format='%(asctime)s %(levelname)-8s %(message)s',
+ datefmt='%m-%d %H:%M',
+ )
+
+ else:
+
+ logging.basicConfig(
+ level=numeric_level,
+ format='%(asctime)s %(name)-3s %(levelname)-8s %(message)s',
+ datefmt='%m-%d %H:%M',
+ filename=logFile,
+ filemode='w'
+ )
+
+ if parser.has_section("favorites"):
+
+ for category, values in parser.items("favorites"):
+
+ usersRaw = values.split(",")
+ users = []
+
+ for user in usersRaw:
+ users.append(user.strip())
+
+ self.favorites.append({"name" : category.strip(), "users" : users})
+
+ except Exception as e:
+
+ logging.warn("Unable to parsre config [%s]: %s" % (cfgFile, `e`))
+
+ def run(self):
+
+ logging.info("pyscmpd v%s started" % PYSCMPD_VERSION)
+
+ mpd = scmpd.ScMpdServerDaemon(self.favorites, self.port)
+
+ self.mainloop = gobject.MainLoop()
+ self.mainloop.run()
+
+try:
+
+ pyscmpd = PyScMpd()
+ pyscmpd.readConfig("./etc/pyscmpd.conf")
+ pyscmpd.run()
except KeyboardInterrupt:
- logging.info("Stopping SoundCloud MPD server")
+ logging.info("pyscmpd v%s ended" % PYSCMPD_VERSION)
except Exception as e:
logging.error("Exception occurred: %s" % `e`)
-finally:
-
- if not mpd == None:
- mpd.quit()
-
- if not mainloop == None:
- mainloop.quit()
View
@@ -231,7 +231,7 @@ def elapsedTime(self):
def setVolume(self, percent):
p = percent / 100.0 + 0.005
- logging.info("Setting volume to %f" % p)
+ logging.debug("Setting volume to %f" % p)
self.player.set_property('volume', p)
def getVolume(self):
View
@@ -4,12 +4,6 @@
import gst
-def on_tag(bus, msg):
- taglist = msg.parse_tag()
- print('on_tag:')
- for key in taglist.keys():
- print('\t%s = %s' % (key, taglist[key]))
-
#our stream to play
music_stream_uri='https://api.soundcloud.com/tracks/58716986/stream?client_id=aa13bebc2d26491f7f8d1e77ae996a64'
@@ -26,11 +20,5 @@ def on_tag(bus, msg):
print "New Volume: ", player.get_property('volume')
-#listen for tags on the message bus; tag event might be called more than once
-bus = player.get_bus()
-bus.enable_sync_message_emission()
-bus.add_signal_watch()
-bus.connect('message::tag', on_tag)
-
#wait and let the music play
raw_input('Press enter to stop playing...')

0 comments on commit ab93f83

Please sign in to comment.