Example #1
0
    def __init__(self, msg_queue):
        self.config = read_config()
        self.prefetching = self.config.getboolean("sonar", "prefetching")
        self.sonar_dir = os.path.join(self.config["sonar"]["sonar_dir"])
        self.cache_dir = os.path.join(self.sonar_dir, "cache")
        self.cache_limit = self.config.getint("sonar", "cache_limit")
        os.makedirs(self.sonar_dir, exist_ok=True)
        os.makedirs(self.cache_dir, exist_ok=True)

        try:
            self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
            self.socket.bind(("", int(self.config['server']['port'])))
            self.socket.listen(1)
            self.socket.setblocking(0)
            self.socket_is_open = True
        except OSError as e:
            print("\nCould not start server socket.")
            print("%s\n" % e)
            sys.exit(0)

        subsonic = Subsonic()
        self.subsonic = subsonic.connection
        self.player = PlayerThread(subsonic, msg_queue)

        self.current_song = None
        self.queue = []

        self.shuffle = False
        self.repeat = False

        self.msg_queue = msg_queue
Example #2
0
File: sonar.py Project: n1ck3/sonar
    def __init__(self, subsonic):
        self.config = read_config()

        self.socket = None
        self.subsonic = subsonic.connection
        self.cached_results = os.path.join(CACHE_DIR, "results.cache")

        self.is_interactive = False
Example #3
0
    def __init__(self, subsonic):
        self.config = read_config()

        self.sonar_dir = os.path.join(self.config["sonar"]["sonar_dir"])
        os.makedirs(self.sonar_dir, exist_ok=True)

        self.cache_dir = os.path.join(self.sonar_dir, "cache")
        os.makedirs(self.cache_dir, exist_ok=True)

        self.socket = None
        self.subsonic = subsonic.connection
        self.cached_results = os.path.join(self.sonar_dir, "results.cache")

        self.is_interactive = False
Example #4
0
    def __init__(self, msg_queue):
        # Read config and setup the server accordingly
        self.config = read_config()

        subsonic = Subsonic()
        self.subsonic = subsonic.connection
        self.player = PlayerThread(subsonic, msg_queue)

        self.current_song = None
        self.queue = []

        self.shuffle = False
        self.repeat = False

        self.msg_queue = msg_queue
Example #5
0
    def __init__(self, subsonic, msg_queue):
        # Read config and setup the player accordingly
        self.config = read_config()

        self.download_queue = []

        subsonic = Subsonic()
        self.subsonic = subsonic.connection
        self.mplayer = MPlayer(
            args=("-really-quiet", "-msglevel", "global=6", "-nolirc")
        )
        self.mplayer.stdout.connect(self._handle_data)

        self.msg_queue = msg_queue

        super(PlayerThread, self).__init__()
Example #6
0
    def __init__(self, subsonic, msg_queue):
        self.config = read_config()
        self.cache_dir = os.path.join(
            self.config["sonar"]["sonar_dir"],
            "cache"
        )

        self.download_queue = []

        subsonic = Subsonic()
        self.subsonic = subsonic.connection
        self.mplayer = MPlayer(
            args=("-really-quiet", "-msglevel", "global=6", "-nolirc")
        )
        self.mplayer.stdout.connect(self._handle_data)

        self.msg_queue = msg_queue

        super(PlayerThread, self).__init__()
Example #7
0
        self.mplayer.quit()

if __name__ == "__main__":
    args = docopt(__doc__, version=__version__)

    ###
    ## Set loglevel
    ###
    loglevels = ["critical", "error", "warning", "info", "debug"]
    if "--loglevel" in args and args["--loglevel"] in loglevels:
        logger.setLevel(getattr(logging, args["--loglevel"].upper()))
    else:
        logger.critical("Invalid loglevel. Exiting...")
        sys.exit(1)

    config = read_config()
    sonar_dir = os.path.join(config["sonar"]["sonar_dir"])
    os.makedirs(sonar_dir, exist_ok=True)

    # Check if another instance of sonar-server is running.
    pidfile = os.path.join(sonar_dir, "sonar-server.pid")
    pid = str(os.getpid())
    if os.path.isfile(pidfile):
        # Hmm, pidfile already exists. Either it is already running
        # in which case we should not start another instance of the
        # server, or the pidfile is stale (sonar-server did not exit
        # gracefully) and we should overwrite the pidfile and start
        # the server.
        pf = open(pidfile, "rt")
        existing_pid = pf.readline()
        pf.close()