Skip to content

Commit 69d7c7a

Browse files
committed
added background music
1 parent ce9f6d1 commit 69d7c7a

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

1_🕔_Clock.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ def get_image_data_url(img_bytes):
2222
encoded = base64.b64encode(img_bytes).decode()
2323
return f"data:image/png;base64,{encoded}"
2424

25+
def music_player(id):
26+
return f"""<iframe style="display:none;" width="560" height="315" src="https://www.youtube.com/embed/{id}?autoplay=1&loop=1&playlist={id}" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen></iframe>"""
27+
2528
if "image" not in st.session_state:
2629
st.session_state.image = "https://f8n-production.s3.us-east-2.amazonaws.com/collections/awzn1l17u-beach%20relax-export.gif"
2730

@@ -34,6 +37,9 @@ def get_image_data_url(img_bytes):
3437
if "screen_dim" not in st.session_state:
3538
st.session_state.screen_dim = [1920, 1080]
3639

40+
if "selected_video" not in st.session_state:
41+
st.session_state.selected_video = ("None","")
42+
3743
zoneinfo = ZoneInfo(st.session_state.timezone)
3844
dt = datetime.now(zoneinfo)
3945

@@ -100,5 +106,8 @@ def get_image_data_url(img_bytes):
100106

101107

102108

109+
st.markdown(music_player(st.session_state.selected_video[1]), unsafe_allow_html=True)
110+
111+
103112
time.sleep(1)
104113
st.rerun()

pages/2_⚙️_settings.py

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,25 @@
4242
if "image" not in st.session_state:
4343
st.session_state.image = "https://f8n-production.s3.us-east-2.amazonaws.com/collections/awzn1l17u-beach%20relax-export.gif"
4444

45+
if "selected_video" not in st.session_state:
46+
st.session_state.selected_video = ("None","")
47+
48+
49+
if "videos" not in st.session_state:
50+
st.session_state.videos = {
51+
"None":"",
52+
"Pokemon": "YMEblRM4pGc",
53+
"Minecraft": "0KvlwMd3C4Y",
54+
"Lofi Girl": "BTYAsjAVa3I",
55+
"Upbeat Classical": "mv5SZ7i6QLI",
56+
"Classical Music":"jgpJVI3tDbY",
57+
"Upbeat Study":"xcwA5h85AvA",
58+
"Soft Techno":"7j0yL8A-k4E",
59+
"8D Binaural":"n0SpKMnkPec",
60+
"Input youtube link":""
61+
}
62+
63+
4564
#function to change format from printable to executable
4665
def format_funct(val):
4766
i = st.session_state.timezones.index(val)
@@ -53,6 +72,14 @@ def get_index(val):
5372
def get_image_data_url(img_bytes):
5473
encoded = base64.b64encode(img_bytes).decode()
5574
return f"data:image/png;base64,{encoded}"
75+
76+
def extract_youtube_id(url):
77+
start = url.find("?v=") + 3
78+
end = url.find("&", start)
79+
if end == -1:
80+
end = len(url)
81+
return url[start:end]
82+
5683
#save timezone value:
5784
st.session_state.timezone = st.selectbox("Select Timezone:", st.session_state.timezones, index=get_index(st.session_state.timezone), format_func=format_funct, placeholder="Europe: Italy")
5885

@@ -63,4 +90,28 @@ def get_image_data_url(img_bytes):
6390

6491
uploaded_file = st.file_uploader("Choose an image...", type=["png", "jpg", "jpeg", "gif"])
6592
if uploaded_file is not None:
66-
st.session_state.image = get_image_data_url(uploaded_file.read())
93+
st.session_state.image = get_image_data_url(uploaded_file.read())
94+
95+
96+
97+
98+
list_keys = list(st.session_state.videos.keys())#easy way to get all names of choices
99+
sel_obj = st.session_state.selected_video[0]#extract the current name
100+
col1, col2 = st.columns(2)
101+
with col1:
102+
st.markdown("""<div style="display:flex; font-size: 30px; justify-content:center; align-items:center; font-weight: bold; color: "white";">
103+
Beats🎶
104+
</div>""",unsafe_allow_html=True)
105+
key = st.selectbox("select ambient music", list_keys, index = list_keys.index(sel_obj), label_visibility="collapsed")
106+
107+
if key == "Input youtube link":
108+
text = st.text_input("input link:", placeholder="https://www.youtube.com/watch?v=jNQXAC9IVRw")
109+
text = extract_youtube_id(text)
110+
if len(text) != 11:
111+
st.toast("Please input a valid youtube link")
112+
else:
113+
st.session_state.videos[key]=text
114+
st.toast("Youtube link accepted!")
115+
116+
117+
st.session_state.selected_video = (key,st.session_state.videos[key])

0 commit comments

Comments
 (0)