Exemple #1
0
 def get_server_info(self):
     config = DeejaydConfig()
     return {
         "server_version": __version__,
         "protocol_version": DEEJAYD_PROTOCOL_VERSION,
         "video_support": config.getboolean("video", "enabled")
     }
Exemple #2
0
    def __init__(self, player):
        super(DeejaydWebradio, self).__init__()
        self.player = player

        self.wb_sources = {"local": WebradioLocalSource()}
        if DeejaydConfig().getboolean("webradio", "icecast"):
            self.wb_sources["icecast"] = IceCastSource()
Exemple #3
0
    def __init__(self, start_inotify=True, library_update=True):
        super(DeejayDaemonCore, self).__init__()
        config = DeejaydConfig()

        self.player = player.init(config)
        self.put_sub_handler('player', self.player)

        self.audiolib, self.videolib, self.watcher = library.init(self.player,
                                                                  config)
        self.put_sub_handler('audiolib', self.audiolib)
        if self.videolib is not None:
            self.put_sub_handler('videolib', self.videolib)

        self.recpls = DeejaydRecordedPlaylist(self.audiolib)
        self.put_sub_handler('recpls', self.recpls)

        # add audio queue/playlist and video playlist
        self.sources = sources.init(self.player, self.audiolib,
                                    self.videolib, config)
        for source in list(self.sources.sources.values()):
            self.put_sub_handler(source.name, source)
            setattr(self, source.name, source)

        # add webradio if player can play http stream
        if self.player.is_supported_uri("http"):
            self.webradio = DeejaydWebradio(self.player)
            self.put_sub_handler('webradio', self.webradio)
        else:
            log.err(_("Player is not able to play http streams"))
            self.webradio = None

        if library_update:
            self.audiolib.update()
            if self.videolib is not None:
                self.videolib.update()

        # enable JSON-RPC introspection
        self.put_sub_handler('introspection', JSONRPCIntrospection(self))

        # start inotify thread when we are sure that all init stuff are ok
        if self.watcher and start_inotify:
            log.debug(_("Start inotify watcher"))
            self.watcher.start()
        # record changes and close session after the initialization
        Session.commit()
        Session.remove()
Exemple #4
0
    def setUpClass(cls):
        super(TestCaseWithDeejaydCore, cls).setUpClass()
        if cls.inotify_support or cls.media_backend == "gstreamer":
            testdeejayd.utils.twreactor.need_twisted_reactor()

        # configure database connection
        uri = DeejaydConfig().get("database", "uri")
        connection.init(uri)

        # init deejayd core
        from deejayd.server.core import DeejayDaemonCore
        cls.deejayd = DeejayDaemonCore(start_inotify=cls.inotify_support,
                                       library_update=False)
        cls.deejayd.audiolib.update(sync=True)
        cls.deejayd.videolib.update(sync=True)
        cls.is_running = True
        connection.Session.remove()
Exemple #5
0
    def setUpClass(cls):
        cls.testdata = TestData()

        # load translation files
        from deejayd.ui.i18n import DeejaydTranslations
        t = DeejaydTranslations()
        t.install()

        # prepare config object
        custom_conf = os.path.join(os.path.dirname(__file__), 
                                   "utils", "defaults.conf")
        cls.config = DeejaydConfig()
        cls.config.read([custom_conf])
        cls.config.set("general", "media_backend", cls.media_backend)

        rnd_str = cls.testdata.get_random_string()
        cls.dbfilename = '/tmp/testdeejayddb-' + rnd_str + '.db'
        cls.config.set('database', 'uri', "sqlite:///"+cls.dbfilename)

        # disable all plugins for tests
        cls.config.set('general', 'enabled_plugins', '')

        # disable icecast, not supported in test
        cls.config.set('webradio', 'icecast', 'no')
Exemple #6
0
def set_log_level():
    global log_level
    level = DeejaydConfig().get("general", "log")
    log_level = {"error": ERROR, "info": INFO, "debug": DEBUG}[level]
    return
Exemple #7
0
    def __reload_list(self):
        log.msg(_("Start to reload icecast webradio source"))
        url = DeejaydConfig().get("webradio", "icecast_url")
        try:
            page_handle = urllib.request.urlopen(url, timeout=TIMEOUT)
            xml_page = page_handle.read()
        except Exception:
            raise DeejaydError(_("Unable to connect to icecast website"))

        # try to parse result
        try:
            root = ET.fromstring(xml_page)
        except ET.XMLSyntaxError:
            raise DeejaydError(_("Unable to parse icecast webradio list"))
        except Exception:
            raise DeejaydError(
                _("Unable to read result from icecast "
                  "webradio list"))
        finally:
            page_handle.close()

        DatabaseLock.acquire()
        session = Session()
        source = session.query(WebradioSource)\
                        .filter(WebradioSource.name == self.NAME)\
                        .one()
        # delete old entries from the database
        session.query(Webradio)\
               .filter(Webradio.source_id == source.id)\
               .delete(synchronize_session='fetch')
        session.query(WebradioCategory)\
               .filter(WebradioCategory.source_id == source.id)\
               .delete(synchronize_session='fetch')

        categories = {}
        webradios = {}
        for station in root:
            try:
                server_type = station.find("server_type").text
                listen_url = station.find("listen_url").text
                genres = station.find("genre").text
                name = station.find("server_name").text
            except TypeError:
                continue

            if server_type.startswith("audio") or \
                    (server_type == "application/ogg" and
                     not listen_url.endswith("ogv")):
                if name not in webradios:
                    genres = genres.split(" ")
                    webradios[name] = Webradio(source=source, name=name)
                    for genre in genres:
                        if len(genre) <= 2 or genre.startswith("."):
                            continue
                        genre = genre.capitalize()
                        if genre not in categories:
                            categories[genre] = WebradioCategory(name=genre,
                                                                 source=source)
                        webradios[name].categories.append(categories[genre])
                    session.add(webradios[name])
                webradios[name].entries.append(WebradioEntry(url=listen_url))
                log.debug('Added icecast webradio %s' % name)
        session.commit()
        Session.remove()
        DatabaseLock.release()

        log.msg(_("Finish to reload icecast webradio source"))
        return {
            "wb_count": len(webradios),
            "cat_count": len(categories),
        }