Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
xuancong84 committed Mar 21, 2024
1 parent 987952c commit 21d9378
Show file tree
Hide file tree
Showing 35 changed files with 3,597 additions and 709 deletions.
459 changes: 360 additions & 99 deletions app.py

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions cert.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
-----BEGIN CERTIFICATE-----
MIIDrTCCApWgAwIBAgIUCYazL4hmpC1STPDhDnGm1gmjdhowDQYJKoZIhvcNAQEL
BQAwZjELMAkGA1UEBhMCU0cxEjAQBgNVBAgMCVNpbmdhcG9yZTESMBAGA1UEBwwJ
U2luZ2Fwb3JlMQ0wCwYDVQQKDARNT0hUMQwwCgYDVQQLDANEU1QxEjAQBgNVBAMM
CWxvY2FsaG9zdDAeFw0yNDAyMjAwMjM0NDNaFw0zNDAyMTcwMjM0NDNaMGYxCzAJ
BgNVBAYTAlNHMRIwEAYDVQQIDAlTaW5nYXBvcmUxEjAQBgNVBAcMCVNpbmdhcG9y
ZTENMAsGA1UECgwETU9IVDEMMAoGA1UECwwDRFNUMRIwEAYDVQQDDAlsb2NhbGhv
c3QwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQDIbkCFUznTbnoyVcnl
BBVo59KRxX88fmwzz5ZKs77UMXsgXIyr2hM12qISpSRq94HoQNCTC2apkb03iizd
ZQ6uF/lnGxstykCnhmDEh7nAGbAWCCeGRKi2WtKVmlamfF9pfm4Pxn2NWi9HBWyq
fYw9ipbg4BfGyStEW8JDqBSW0MoNdmoBSjQiCRy1yQvVk4JeidVyNoufA5WNu5gj
3UlZDBvLxh682kDNj93BKFFIY3Xf5oisAXfMZx97TvdznBim3y+z1pqbno0cyrYC
c9auCx3FYP3NQVJDt6I4gYTZBxq0cVza28rEeOb0vEJn06aerMbTelNLxARjLXwE
Lj/pAgMBAAGjUzBRMB0GA1UdDgQWBBS5CF9MG9pNxwqesiVU3Es/IxviWTAfBgNV
HSMEGDAWgBS5CF9MG9pNxwqesiVU3Es/IxviWTAPBgNVHRMBAf8EBTADAQH/MA0G
CSqGSIb3DQEBCwUAA4IBAQBU+cha1J8iW0JaT/5a3J9vLlRid1esk65X9zRmRWXA
KqKiO2+WHEWUx+PQD3yCCbm01brodDnnRCMZtWizr81WMTF4q/E/m/azy3i6Sqaq
rDvWkjWw+FVUvFZpwxLq+4+9HesXZHVu9ut1mhBShvzzEFu5dK4ukr5STl1ZJCzV
F2/v/XjN0zkik3/q++P1KbMta6cztJ5d2Y5EhJpf7CPteB/SWPxXp6CC7caxMsHS
pIc+ycofhwOWMjom1Q5gSpVU8/KvFM2GU8SCJhfAd0Yo1VQyPQDqA5QkM4R9aqee
HVFwdWyAF+0MgX+mmzXprkyc43DX22Lxp4+oXZJDhgJv
-----END CERTIFICATE-----
93 changes: 28 additions & 65 deletions karaoke.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import os, sys, io, random, time, json, hashlib
import os, sys, io, random, time, json
import logging, socket, subprocess, threading
import multiprocessing as mp
import shutil, psutil, traceback, tarfile, requests
Expand All @@ -19,7 +19,6 @@
from app import getString

STD_VOL = 65536/8/np.sqrt(2)
TMP_DIR = '/dev/shm'

if get_platform() != "windows":
from signal import SIGALRM, alarm, signal
Expand All @@ -36,13 +35,10 @@ def cleanse_modules(name):


class Karaoke:
raspi_wifi_config_ip = "10.0.0.1"
raspi_wifi_conf_file = "/etc/raspiwifi/raspiwifi.conf"
raspi_wifi_config_installed = os.path.exists(raspi_wifi_conf_file)
ref_W, ref_H = 1920, 1080 # reference screen size, control drawing scale

queue = []
queue_hash = None
queue_json = ''
available_songs = []
rename_history = {}
songname_trans = {} # transliteration is used for sorting and initial letter search
Expand Down Expand Up @@ -71,6 +67,8 @@ class Karaoke:
volume_offset = 0
default_logo_path = os.path.join(base_path, "logo.png")
logical_volume = None # for normalized volume
status_dirty = True
event_dirty = threading.Event()

def __init__(self, args):

Expand Down Expand Up @@ -119,7 +117,7 @@ def __init__(self, args):

logging.debug("IP address (for QR code and splash screen): " + self.ip)

self.url = "http://%s:%s" % (self.ip, self.port)
self.url = "%s://%s:%s" % (('https' if self.ssl else 'http'), self.ip, self.port)

# get songs from download_path
self.get_available_songs()
Expand Down Expand Up @@ -176,12 +174,12 @@ def _cloud_thread(self):
bn, dn = os.path.basename(fn), os.path.dirname(fn)
if os.path.isfile(f'{self.download_path}nonvocal/{bn}.m4a') and os.path.isfile(f'{self.download_path}vocal/{bn}.m4a'):
continue
os.system(f'ffmpeg -y -i "{fn}" -vn -c copy {TMP_DIR}/input.m4a')
with open(f'{TMP_DIR}/input.m4a', 'rb') as f:
r = requests.post(self.cloud, files={'file': f})
with open(f'{TMP_DIR}/output.tar.gz', 'wb') as f:
os.system(f'ffmpeg -y -i "{fn}" -vn -c copy {self.tmp_dir}/input.m4a')
with open(f'{self.tmp_dir}/input.m4a', 'rb') as f:
r = requests.post(self.cloud+'/split_vocal', files={'file': f})
with open(f'{self.tmp_dir}/output.tar.gz', 'wb') as f:
f.write(r.content)
with tarfile.open(f'{TMP_DIR}/output.tar.gz') as tar:
with tarfile.open(f'{self.tmp_dir}/output.tar.gz') as tar:
tar.extract('nonvocal.m4a', f'{self.download_path}nonvocal')
os.rename(f'{self.download_path}nonvocal/nonvocal.m4a', f'{self.download_path}nonvocal/{bn}.m4a')
tar.extract('vocal.m4a', f'{self.download_path}vocal')
Expand All @@ -196,39 +194,14 @@ def get_ip(self):
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
try:
# doesn't even have to be reachable
s.connect(("10.255.255.255", 1))
s.connect(("8.8.8.8", 1))
IP = s.getsockname()[0]
except Exception:
IP = "127.0.0.1"
finally:
s.close()
return IP

def get_raspi_wifi_conf_vals(self):
"""Extract values from the RaspiWiFi configuration file."""
f = open(self.raspi_wifi_conf_file, "r")

# Define default values.
#
# References:
# - https://github.com/jasbur/RaspiWiFi/blob/master/initial_setup.py (see defaults in input prompts)
# - https://github.com/jasbur/RaspiWiFi/blob/master/libs/reset_device/static_files/raspiwifi.conf
#
server_port = "80"
ssid_prefix = "RaspiWiFi Setup"
ssl_enabled = "0"

# Override the default values according to the configuration file.
for line in f.readlines():
if "server_port=" in line:
server_port = line.split("t=")[1].strip()
elif "ssid_prefix=" in line:
ssid_prefix = line.split("x=")[1].strip()
elif "ssl_enabled=" in line:
ssl_enabled = line.split("d=")[1].strip()

return (server_port, ssid_prefix, ssl_enabled)

def get_youtubedl_version(self):
self.youtubedl_version = self.call_yt_dlp(['--version'], True).strip()
return self.youtubedl_version
Expand Down Expand Up @@ -359,28 +332,12 @@ def render_splash_screen(self):
if self.streamer_alive():
text = self.render_font(sysfont_size, getString(50) + self.url.rsplit(":", 1)[0] + ":4000", (255, 255, 255))
self.screen.blit(text[0], self.normalize((qr_size + 35, blitY - 40)))
if not self.firstSongStarted and self.platform != 'osx':
if not self.firstSongStarted:
text = self.render_font(sysfont_size, getString(51), (255, 255, 255))
self.screen.blit(text[0], self.normalize((qr_size + 35, blitY - 120)))
text = self.render_font(sysfont_size, getString(52), (255, 255, 255))
self.screen.blit(text[0], self.normalize((qr_size + 35, blitY - 80)))

if not self.hide_raspiwifi_instructions and self.raspi_wifi_config_installed and self.raspi_wifi_config_ip in self.url:
server_port, ssid_prefix, ssl_enabled = self.get_raspi_wifi_conf_vals()

text1 = self.render_font(sysfont_size, getString(53), (255, 255, 255))
text2 = self.render_font(sysfont_size, getString(54) % ssid_prefix, (255, 255, 255))
text3 = self.render_font(sysfont_size,
getString(55)
% ("https" if ssl_enabled == "1" else "http",
self.raspi_wifi_config_ip,
":%s" % server_port if server_port != "80" else ""),
(255, 255, 255),
)
self.screen.blit(text1[0], self.normalize((10, 10)))
self.screen.blit(text2[0], self.normalize((10, 50)))
self.screen.blit(text3[0], self.normalize((10, 90)))

blitY = 10
if not self.has_video:
logging.debug("Rendering current song to splash screen")
Expand Down Expand Up @@ -681,6 +638,7 @@ def play_file(self, file_path, extra_params = []):
self.omxclient.play_file(file_path)

self.switchingSong = False
self.status_dirty = True
self.render_splash_screen() # remove old previous track

def play_transposed(self, semitones):
Expand Down Expand Up @@ -713,7 +671,7 @@ def enqueue(self, song_path, user = "Pikaraoke"):
else:
logging.info("'%s' is adding song to queue: %s" % (user, song_path))
self.queue.append({"user": user, "file": song_path, "title": self.filename_from_path(song_path)})
self.update_queue_hash()
self.update_queue()
return True

def queue_add_random(self, amount):
Expand All @@ -732,19 +690,20 @@ def queue_add_random(self, amount):
i += 1
songs.pop(r)
if len(songs) == 0:
self.update_queue_hash()
self.update_queue()
logging.warn("Ran out of songs!")
return False
self.update_queue_hash()
self.update_queue()
return True

def update_queue_hash(self):
self.queue_hash = hashlib.md5(json.dumps(self.queue).encode('utf-8')).hexdigest()
def update_queue(self):
self.queue_json = json.dumps(self.queue)
self.status_dirty = True

def queue_clear(self):
logging.info("Clearing queue!")
self.queue = []
self.update_queue_hash()
self.update_queue()
self.skip()

def queue_edit(self, song_name, action, **kwargs):
Expand Down Expand Up @@ -795,7 +754,7 @@ def queue_edit(self, song_name, action, **kwargs):
else:
logging.error("Unrecognized direction: " + action)
return False
self.update_queue_hash()
self.update_queue()
return True

def skip(self):
Expand Down Expand Up @@ -855,6 +814,7 @@ def set_audio_delay(self, delay):
self.vlcclient.command(f"audiodelay&val={self.audio_delay}")
else:
logging.warning("OMXplayer cannot set audio delay!")
self.status_dirty = True
return self.audio_delay
logging.warning("Tried to set audio delay, but no file is playing!")
return False
Expand All @@ -881,6 +841,7 @@ def set_subtitle_delay(self, delay):
self.vlcclient.command(f"subdelay&val={self.subtitle_delay}")
else:
logging.warning("OMXplayer cannot set subtitle delay!")
self.status_dirty = True
return self.subtitle_delay
logging.warning("Tried to set subtitle delay, but no file is playing!")
return False
Expand Down Expand Up @@ -908,6 +869,7 @@ def pause(self):
else:
self.omxclient.play()
self.is_paused = False
self.status_dirty = True
return True
else:
logging.warning("Tried to pause, but no file is playing!")
Expand Down Expand Up @@ -1230,7 +1192,7 @@ def run(self):
self.streamer_restart(1)
self.firstSongStarted = True
self.now_playing_user = head["user"]
self.update_queue_hash()
self.update_queue()
elif (self.full_screen and not pygame.display.get_active()) and not self.is_file_playing():
self.pygame_reset_screen()
self.handle_run_loop()
Expand All @@ -1241,7 +1203,8 @@ def run(self):
# Clean up before quit
self.streamer_stop()
self.vocal_stop()
(self.vlcclient if self.use_vlc else self.omxclient).stop()
vplayer = self.vlcclient if self.use_vlc else self.omxclient
if vplayer is not None: vplayer.stop()
self.auto_save_delays()
time.sleep(1)
(self.vlcclient if self.use_vlc else self.omxclient).kill()
if vplayer is not None: vplayer.kill()
28 changes: 28 additions & 0 deletions key.pem
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDIbkCFUznTbnoy
VcnlBBVo59KRxX88fmwzz5ZKs77UMXsgXIyr2hM12qISpSRq94HoQNCTC2apkb03
iizdZQ6uF/lnGxstykCnhmDEh7nAGbAWCCeGRKi2WtKVmlamfF9pfm4Pxn2NWi9H
BWyqfYw9ipbg4BfGyStEW8JDqBSW0MoNdmoBSjQiCRy1yQvVk4JeidVyNoufA5WN
u5gj3UlZDBvLxh682kDNj93BKFFIY3Xf5oisAXfMZx97TvdznBim3y+z1pqbno0c
yrYCc9auCx3FYP3NQVJDt6I4gYTZBxq0cVza28rEeOb0vEJn06aerMbTelNLxARj
LXwELj/pAgMBAAECggEAAqOpB9hrt4QJ6eXFTdW67nG3DSJbpZFInXoLUZqCVcr9
AxUU6SJrBFeHsNUp4Jq3xDYuSPFqfaskobmZE6VEBzjbmOb7eaPjLBGR7qSW5pew
AOpEkvkOe7BAe6XXpEOZAgufKWgEuTrJypagsrIKibjsebOZvI1jm3fV3Aw3kTDS
r3+gdhf9IaxrAnRJb/ofZO2H6Nl0mTf2MYW9u9SCGro3qQPeTlimKqbGyD7SBY0t
UVo263/gtyhkEQriVgH/OT7DP6v2mpEDUJex0idnEFbUTMQPcHB8jO2QdisJOMSF
qXRItvYwQ8OnHjheFO63pdlpUNBjeRvqz5jPKou3LQKBgQDtGYR5qpDRknbG8RMZ
K5TRoWZVICc+KiufObFRpn0G2xS2+1V1bVrevlYWhVUDEZJP+w02UZwJmUJLZ3mi
7rcmBeoE0asSje4jGwRvF2LzU8PsALBcgnNEPxCgaTZVa8RXxt7qfR686B/hyJVl
dFbj+ymdBZ/N7xoqXA1IKDDZLwKBgQDYaG6KFLyUywh92kcJbVBz6aglu44hpoNM
Nc1jZBcCWRZtDRgq4N1EAnywrr4qNd49K+JvziVK45zmox/4l8fO9cz5gy62d//y
3/RuHp1uQbBP2VkPfnE1pRmw6BBVwGVXQT2OxUtfv00whP/p6g3xCwWixCb4A45J
tV2tYFOCZwKBgEknz20uyIIxO77EUU052jAYKZfoVNNkdZMqXODBiuAbpreSstqJ
hDkn5y4Js6I/wLI21uvEoG2BwSe85JX2K8Jqnrsf6jXOXwSr6GFSiPBlDxV5XPEe
Oux6vOmRrPcMSkd/D/av5lUJFhU3K4ljLRAoxb0yKA2FUcByKJLz+6Z3AoGBAKez
zi29QiLAcFUvKSuaBeW9pauP++YB5u/RJdgnAVm1dhaONjNMTMvebYhx8jY9xnp7
Hp/sDaRKXRWyRh1cad/tRan6SeHnfnZVrVME8JU33I0Ubtr97ndW+WDJhZceYKpM
iYqxQ+bwFb5K4xL/aUxpcTWgcl5ySvq9zNmFs1FzAoGAJ9tqRpjbhnYb/AKDDJsg
OYVLq35xP0XBKr5qy+TOb9+b43DkOwkZsVM2g15tA14EsR6TmAq4TkZNC0OJo3hR
Bjc0KnvQMWtnZ30GdLZcZnTSuenVavynDU81wTQI7nGwwna7UY+9VmSfbUck+3fY
x3YUiPfkWTaXQJ/g6yOm2ko=
-----END PRIVATE KEY-----
20 changes: 19 additions & 1 deletion lang/en_US
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ Edit song
Move up in queue
Move down in queue
Are you sure you want to delete from the queue
Are you sure you want to clear the ENTIRE queue? Type 'OK' to continue
Are you sure you want to clear the ENTIRE queue?
Add 3 random songs
Clear all
The queue is empty
Expand Down Expand Up @@ -209,3 +209,21 @@ Download subtitles (only embedded) in all languages if available
Downloading high-quality videos might take very long time
Save Play Settings
Save play settings for each song, this includes: audio delay, subtitle delay, and whether to show subtitles.
Add song by speaking the song title
Please speak the song title and click OK!
Only HTTPS websites can have access to microphone, do you want to redirect to HTTPS website?
Please grant the permission to access microphone!
Edit Song Name:
Save
Delete this song
Are you sure you want to delete this song from the library?
Request parameter error!
Trim the song:
Adjust song volume:
Begin time:
End time:
Original Volume (dB):
Cannot find any song matching "%s".
Added "%s" into queue.
Please choose the song(s) to add:
UNDO
22 changes: 20 additions & 2 deletions lang/zh_CN
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ Wifi/网络未连接,10秒后关机...
首歌曲
显示 <b>{start} - {end}</b>{record_name},共计 <b>{total}</b>{record_name}
找到 <b>{found}</b>{record_name},显示 <b>{start} - {end}</b>{record_name}
修改歌曲文件
修改歌曲
在队列中向上移
在队列中向下移
您确定要从点歌队列中删除
您确定要清空整个队列吗? 输入“OK”继续
您确定要清空整个队列吗?
随机添加3首歌曲
全部清除
队列为空
Expand Down Expand Up @@ -209,3 +209,21 @@ Pi卡拉OK版本
下载高清版本可能需要很长时间
保存播放设置
保存每一首歌曲的播放设置,包括:音频延迟,字幕延迟,以及是否显示字幕。
用语音识别来添加歌曲
请说出歌曲名称然后点击确定!
只有HTTPS的网页才能获取麦克风权限,是否切换到HTTPS网页?
请开启麦克风权限!
编辑歌曲名:
保存
删除此歌曲
确定从歌曲库中删除此歌曲?
请求参数错误!
剪辑该歌曲:
调整歌曲音量:
起始时间:
截止时间:
歌曲原始音量(分贝):
找不到匹配歌曲:"%s"。
“%s”已被加入点歌列表。
请选择想要添加的歌曲:
撤销
Loading

0 comments on commit 21d9378

Please sign in to comment.