Index: action.py ================================================================== --- action.py +++ action.py @@ -46,22 +46,27 @@ # streamlink formats lt = {"asx":"video/x-ms-asf", "pls":"audio/x-scpls", "m3u":"audio/x-mpegurl", "xspf":"application/xspf+xml", "href":"url/http", "ram":"audio/x-pn-realaudio", "smil":"application/smil"} # media formats mf = {"mp3":"audio/mp3", "ogg":"audio/ogg", "aac":"audio/aac"} - - + + # web @staticmethod def browser(url): __print__( conf.browser ) - os.system(conf.browser + " '" + action.quote(url) + "' &") + action.run(conf.browser + " " + action.quote(url)) + + # os shell cmd escaping @staticmethod def quote(s): - return "%r" % s + if conf.windows: + return s # should actually be "\\\"%s\\\"" % s + else: + return "%r" % s # calls player for stream url and format @staticmethod def play(url, audioformat="audio/mp3", listformat="text/x-href"): @@ -74,15 +79,19 @@ __print__( "play", url, cmd ) try: action.run( action.interpol(cmd, url) ) except: pass + + # exec wrapper @staticmethod def run(cmd): - __print__( cmd ) - os.system(cmd + (" &" if platform.system()!="Windows" else "")) + if conf.windows: + os.system("start \"%s\"") + else: + os.system(cmd + " &") # streamripper @staticmethod def record(url, audioformat="audio/mp3", listformat="text/x-href", append="", row={}): @@ -221,12 +230,12 @@ stream_id = stream_id and stream_id.group(1) or "XXXXXX" try: channelname = main.current_channel except: channelname = "unknown" - return (conf.tmp+"/streamtuner2."+channelname+"."+stream_id+".m3u", len(stream_id) > 3 and stream_id != "XXXXXX") - + return (conf.tmp + os.sep + "streamtuner2."+channelname+"."+stream_id+".m3u", len(stream_id) > 3 and stream_id != "XXXXXX") + # check if there are any urls in a given file @staticmethod def has_urls(tmp_fn): if os.path.exists(tmp_fn): return open(tmp_fn, "r").read().find("http://") > 0 @@ -262,11 +271,11 @@ # open help browser @staticmethod def help(*args): - os.system("yelp /usr/share/doc/streamtuner2/help/ &") + action.run("yelp /usr/share/doc/streamtuner2/help/") #or action.browser("/usr/share/doc/streamtuner2/") #class action Index: config.py ================================================================== --- config.py +++ config.py @@ -17,10 +17,11 @@ import os import sys import pson import gzip +import platform #-- create a single instance of config object conf = object() @@ -84,10 +85,11 @@ self.theme = "" #"MountainDew" self.debug = False self.channel_order = "shoutcast, xiph, internet_radio_org_uk, jamendo, myoggradio, .." self.reuse_m3u = 1 self.google_homepage = 1 + self.windows = platform.system()=="Windows" # each plugin has a .config dict list, we add defaults here def add_plugin_defaults(self, config, module=""): @@ -103,14 +105,14 @@ # http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html def xdg(self): home = os.environ.get("HOME", self.tmp) - config = os.environ.get("XDG_CONFIG_HOME", home+"/.config") + config = os.environ.get("XDG_CONFIG_HOME", os.environ.get("APPDATA", home+"/.config")) # storage dir - self.dir = config + "/" + "streamtuner2" + self.dir = config + "/streamtuner2" # create if necessary if (not os.path.exists(self.dir)): os.makedirs(self.dir)