Exemple #1
0
def cmd_drop_database(bot, user, text, command, parameter):
    global log

    if bot.is_admin(user):
        var.db.drop_table()
        var.db = SettingsDatabase(var.settings_db_path)
        var.music_db.drop_table()
        var.music_db = MusicDatabase(var.settings_db_path)
        log.info("command: database dropped.")
        bot.send_msg(tr('database_dropped'), text)
    else:
        bot.mumble.users[text.actor].send_text_message(tr('not_admin'))
Exemple #2
0
    # ======================
    if args.user:
        username = args.user
    else:
        username = var.config.get("bot", "username")

    sanitized_username = "".join([x if x.isalnum() else "_" for x in username])
    var.settings_db_path = args.db if args.db is not None else util.solve_filepath(
        config.get("bot", "database_path", fallback=f"settings-{sanitized_username}.db"))
    var.music_db_path = args.music_db if args.music_db is not None else util.solve_filepath(
        config.get("bot", "music_database_path", fallback="music.db"))

    var.db = SettingsDatabase(var.settings_db_path)

    if var.config.get("bot", "save_music_library", fallback=True):
        var.music_db = MusicDatabase(var.music_db_path)
    else:
        var.music_db = MusicDatabase(":memory:")

    DatabaseMigration(var.db, var.music_db).migrate()

    var.music_folder = util.solve_filepath(var.config.get('bot', 'music_folder'))
    if not var.music_folder.endswith(os.sep):
        # The file searching logic assumes that the music folder ends in a /
        var.music_folder = var.music_folder + os.sep
    var.tmp_folder = util.solve_filepath(var.config.get('bot', 'tmp_folder'))

    # ======================
    #      Translation
    # ======================
Exemple #3
0
 def __init__(self, configFile: str):
     self.config = loadConfig(configFile)
     self.player = MusicPlayer()
     self.database = MusicDatabase(self.config['database'])
     self.playlist = Playlist()
     thread.start_new_thread(self.primaryThread, ())
Exemple #4
0
        bot_logger.error("Starting in ERROR loglevel")

    logfile = util.solve_filepath(var.config.get('bot', 'logfile'))
    handler = None
    if logfile:
        handler = logging.handlers.RotatingFileHandler(logfile, mode='a', maxBytes=10240)  # Rotate after 10KB
    else:
        handler = logging.StreamHandler()

    handler.setFormatter(formatter)
    bot_logger.addHandler(handler)
    logging.getLogger("root").addHandler(handler)
    var.bot_logger = bot_logger

    if var.config.get("bot", "save_music_library", fallback=True):
        var.music_db = MusicDatabase(var.dbfile)
    else:
        var.music_db = MusicDatabase(":memory:")

    var.cache = MusicCache(var.music_db)

    # load playback mode
    playback_mode = None
    if var.db.has_option("playlist", "playback_mode"):
        playback_mode = var.db.get('playlist', 'playback_mode')
    else:
        playback_mode = var.config.get('bot', 'playback_mode', fallback="one-shot")

    if playback_mode in ["one-shot", "repeat", "random", "autoplay"]:
        var.playlist = media.playlist.get_playlist(playback_mode)
    else:
Exemple #5
0
class PiPlayer:
    def __init__(self, configFile: str):
        self.config = loadConfig(configFile)
        self.player = MusicPlayer()
        self.database = MusicDatabase(self.config['database'])
        self.playlist = Playlist()
        thread.start_new_thread(self.primaryThread, ())

    def connect(self, *, initialize: bool = False):
        self.database.connect(initialize=initialize)

    def disconnect(self):
        self.database.disconnect()

    def playTest(self):
        pass

    def scanLibrary(self):
        def scanDirectory(self, directory: str, recursive: bool = False):
            for path in listdir(directory):
                fullPath = join(directory, path)
                if isdir(fullPath):
                    if recursive:
                        scanDirectory(self, fullPath, recursive)
                else:
                    try:
                        meta = MusicMetadata()
                        meta.loadFile(fullPath)
                        results = self.database.fetchMusicRowResults(
                            'file', fullPath)
                        shouldAdd = results is None or results.count < 1
                        self.database.addMusic(meta, update=not shouldAdd)
                    except:
                        pass

        for directory in self.config['directories']:
            directoryPath = abspath(directory['path'])
            recursive = directory['recursive']
            scanDirectory(self, directoryPath, recursive)

    def primaryThread(self):
        while (self.playlist.state == PlaylistState.Uninitialized):
            sleep(1)
        self.playSong(self.playlist.currentSong())
        self.playlist.state = PlaylistState.Playing
        self.playlist.next()
        while (self.playlist.state != PlaylistState.End):
            if (self.player.state == MusicPlayerState.Ended):
                self.playSong(self.playlist.currentSong())
                self.playlist.next()
            sleep(1)

    def playSong(self, song: MusicMetadata):
        self.player.load(song.file)
        print("Now playing")
        print(song.title)
        print("By " + song.artist)
        print(song.album)
        self.player.play()

    def loadPlaylist(self, playlistName: str):
        try:
            self.playlist.load(self.database.fetchPlaylist(playlistName))
        except:
            pass