示例#1
0
 def _mux_video_and_audio(self):
     try:
         do_the_linux_command(
             f"ffmpeg -i {self.tmp_video_file.name} -i {self.tmp_audio_file.name} -c:v copy -c:a aac -strict experimental -f mp4 -y {self.tmp_output_file.name}"
         )
     finally:
         self._delete_video_audio_files()
示例#2
0
    def parse_server_info(self):
        """
        Порой json метод не срабатывает и приходится парсить руками
        """
        command = f"{BASE_DIR}/venv/bin/mcstatus {self.ip}:{self.port} status"
        response = do_the_linux_command(command)
        response_lines = response.split('\n')

        players_range_start_phrase = 'players: '
        players_range_end_phrase = ' '

        players_range_start_pos = response_lines[2].find(players_range_start_phrase) + len(players_range_start_phrase)
        players_range_end_pos = response_lines[2].find(players_range_end_phrase, players_range_start_pos)
        players_range = response_lines[2][players_range_start_pos:players_range_end_pos]
        players_range_split = players_range.split('/')
        server_info = {
            'version': response_lines[0][
                       response_lines[0].find('version: v') + len('version: v'):response_lines[0].find('(') - 1],
            'player_count': int(players_range_split[0]),
            'player_max': int(players_range_split[1]),
            'online': True,
            'players': '',
        }
        players_list_pos = response_lines[2].find('[')
        if players_list_pos != -1:
            players_list = response_lines[2][players_list_pos:].replace("[\'", '').replace('\']', '').split(',')
            server_info['players'] = [{
                'name': x[:x.find(' ')]
            } for x in players_list]
        return server_info
示例#3
0
 def get_server_info(self):
     command = f"{BASE_DIR}/venv/bin/mcstatus {self.ip}:{self.port} json"
     server_info_json = json.loads(do_the_linux_command(command))
     server_is_online = server_info_json['online']
     server_is_send_bad_response = 'player_count' not in server_info_json and 'players' not in server_info_json
     if server_is_online and server_is_send_bad_response:
         server_info_json = self.parse_server_info()
     self.server_info = server_info_json
示例#4
0
    def start(self):
        command = "sensors"
        output = do_the_linux_command(command)

        find_text = 'Adapter: ISA adapter\nPackage id 0:'
        output = f"AVG:{output[output.find(find_text) + len(find_text):].replace('(high = +80.0°C, crit = +100.0°C)', '')}"

        return output
示例#5
0
def get_terraria_server_info(port):
    command = "systemctl status terraria"
    response = do_the_linux_command(command)
    index1 = response.find("Active: ") + len("Active: ")
    index2 = response.find("(", index1) - 1
    status = response[index1:index2]
    if status == 'active':
        result = f"Террария запущена ✅ - {MAIN_DOMAIN}:{port}\n"
    else:
        result = "Террария остановлена ⛔"

    return result
示例#6
0
 def start(self):
     return do_the_linux_command(self.event.message.args_str)
示例#7
0
 def _get_download_video_and_audio(self, video_url, audio_url):
     do_the_linux_command(f"curl -o {self.tmp_video_file.name} {video_url}")
     do_the_linux_command(f"curl -o {self.tmp_audio_file.name} {audio_url}")
示例#8
0
 def start(self):
     command = "uptime"
     result = do_the_linux_command(command)
     return result
示例#9
0
 def stop(self):
     do_the_linux_command(f'sudo systemctl stop {self._get_service_name()}')
示例#10
0
 def start(self):
     check_command_time('terraria', 10)
     do_the_linux_command(
         f'sudo systemctl start {self._get_service_name()}')
示例#11
0
 def menu_server(self):
     self.bot.parse_and_send_msgs_thread('Рестартим сервер', self.event.peer_id)
     do_the_linux_command('sudo systemctl reboot -i')
     return 'Рестартим сервер'
示例#12
0
 def menu_web(self):
     self.bot.parse_and_send_msgs_thread('Рестартим веб', self.event.peer_id)
     do_the_linux_command('sudo systemctl restart petrovich_site')
     return 'Рестартим веб'
示例#13
0
 def _start_local(self):
     do_the_linux_command(f'sudo systemctl start {self._get_service_name()}')