Skip to content

Commit 8644db2

Browse files
Merge pull request #2 from HowlingByte/dev
New update v1.0
2 parents e9fc9a0 + 706a7e4 commit 8644db2

File tree

3 files changed

+107
-25
lines changed

3 files changed

+107
-25
lines changed

.gitignore

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

22
*.csv
33
Twitter-API-Get.py
4-
List-Media.csv
5-
*.csv
4+
List-Media.csv

Chromecast-main.py

Lines changed: 103 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,40 @@
22
import pychromecast
33
import csv
44
import pyautogui
5+
import tkinter as tk
6+
from threading import Thread
7+
8+
global cast
9+
global NameOfCast
10+
global TempsDePause
11+
global Medias
12+
global text1
13+
global text2
14+
global text3
15+
global checkbox_var
516

617
with open("List-Media.csv", encoding='utf-8', newline='') as csvfile:
718
Medias=list(csv.reader(csvfile,delimiter=";"))
819
print("Medias link",Medias)
920

10-
def start_cast():
11-
global cast
12-
chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[NameOfCast])
13-
print("Found {} chromecasts".format(len(chromecasts)))
14-
15-
cast = chromecasts[0]
16-
cast.wait()
17-
print(cast.status)
21+
def start_cast(stop_connection = False):
22+
if stop_connection == False:
23+
global cast
24+
chromecasts, browser = pychromecast.get_listed_chromecasts(friendly_names=[NameOfCast])
25+
print("Found {} chromecasts".format(len(chromecasts)))
26+
cast = chromecasts[0]
27+
cast.wait()
28+
print(cast.status)
29+
elif stop_connection == True:
30+
try:
31+
cast.quit_app()
32+
cast.disconnect()
33+
print("Connection closed", cast.status)
34+
except:
35+
pass
1836

1937

20-
# show an image
38+
# Share an image (from a URL) to the Chromecast
2139
def show_media(url):
2240
global cast
2341
mc = cast.media_controller
@@ -29,26 +47,88 @@ def show_media(url):
2947
#
3048
mc.block_until_active()
3149
return mc.status
32-
50+
# Stop the media playing on the Chromecast and disconnect
51+
"""
3352
def stop_cast():
3453
global cast
3554
cast.quit_app()
3655
cast.disconnect()
56+
"""
57+
# Loop through the images in the list (url(s) inside of csv file)
58+
def loop(number, Repetition=1, EndAfterLoop = False):
59+
for i in range(Repetition):
60+
for x in range(number):
61+
show_media(Medias[x][0])
62+
time.sleep(TempsDePause)
63+
if EndAfterLoop == True:
64+
start_cast(stop_connection = True)
65+
66+
####
67+
#UI
68+
####
69+
def UI():
70+
def Send():
71+
global NameOfCast
72+
global TempsDePause
73+
NameOfCast = text1.get()
74+
TempsDePause = int(text2.get())
75+
Repetition = int(text3.get())
76+
print("NameOfCast:",NameOfCast)
77+
print("TempsDePause:",TempsDePause)
78+
thread = Thread(target=start_and_loop, args=(Repetition,))
79+
thread.start()
80+
81+
def start_and_loop(Repetition):
82+
start_cast()
83+
if checkbox_var.get() == 1:
84+
loop(len(Medias), Repetition, EndAfterLoop=True)
85+
else:
86+
loop(len(Medias), Repetition)
87+
88+
# create UI
89+
root = tk.Tk()
90+
root.title("Chromecast-URL")
91+
root.geometry("400x300")
92+
root.resizable(False, False)
93+
root.configure(background='#2B2B2B')
94+
95+
#text
96+
text1_label = tk.Label(root, text="Name of Chromecast:")
97+
text1_label.pack()
98+
text1 = tk.Entry(root)
99+
text1.pack()
100+
text2_label = tk.Label(root, text="Time between photos (s):")
101+
text2_label.pack()
102+
text2 = tk.Entry(root)
103+
text2.pack()
104+
text3_label = tk.Label(root, text="Repetition:")
105+
text3_label.pack()
106+
text3 = tk.Entry(root)
107+
text3.pack()
108+
109+
#create another checkbox
110+
checkbox_var = tk.IntVar(value=1)
111+
checkbox1 = tk.Checkbutton(root, text="End connection after loop", variable=checkbox_var)
112+
checkbox1.pack()
37113

38-
def boucle(nombre):
39-
for x in range(nombre):
40-
show_media(Medias[x][0])
41-
time.sleep(TempsDePause)
114+
# Create the submit button
115+
submit_button = tk.Button(root, text="Submit", command=Send)
116+
submit_button.pack()
42117

43-
### Main ###
44-
NameOfCast = "Mat" #Name of your Chromecast
45-
MediasNumber = len(Medias) #Number of medias in your list
46-
TempsDePause = 5 #Time between each media
47-
print("MediasNumber",MediasNumber) #Debug
118+
def quit():
119+
print("Quit")
120+
start_cast(stop_connection = True)
121+
time.sleep(1)
122+
root.destroy()
48123

49-
start_cast()
124+
# Create the quit button
125+
quit_button = tk.Button(root, text="Quit and end connection", command=quit)
126+
quit_button.pack()
50127

51-
boucle(MediasNumber)
128+
# When the window is closed, quit the application
129+
root.protocol("WM_DELETE_WINDOW", quit)
52130

53-
pyautogui.alert(text='Close?', title='Main', button='OK')
54-
stop_cast()
131+
# Start the main event loop
132+
root.mainloop()
133+
134+
UI()

requierements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pychromecast
2+
pyautogui
3+
tkinter

0 commit comments

Comments
 (0)