33import csv
44import pyautogui
55import tkinter as tk
6+ import webbrowser
67from threading import Thread
78
89global cast
1415global text2
1516global text3
1617global checkbox_var
17-
18+ #Open CSV file and put it in a list (Medias)
1819with open ("List-Media.csv" , encoding = 'utf-8' , newline = '' ) as csvfile :
1920 Medias = list (csv .reader (csvfile ,delimiter = ";" ))
2021 print ("Medias link" ,Medias )
21-
22+ #Start the connection with the Chromecast
2223def start_cast (stop_connection = False ):
24+ """
25+ Start the connection with the Chromecast \n
26+ if stop_connection = True, close the connection \n
27+ Example: \n
28+ - start_cast(stop_connection = False) #Start the connection \n
29+ - start_cast(stop_connection = True) #Close the connection \n
30+ or
31+ - start_cast() #Start the connection \n
32+ """
2333 if stop_connection == False :
2434 global cast
2535 chromecasts , browser = pychromecast .get_listed_chromecasts (friendly_names = [NameOfCast ])
2636 print ("Found {} chromecasts" .format (len (chromecasts )))
2737 cast = chromecasts [0 ]
2838 cast .wait ()
29- print (cast .status )
39+ print ("Cast.status" , cast .status )
3040 elif stop_connection == True :
3141 try :
3242 cast .quit_app ()
@@ -37,6 +47,15 @@ def start_cast(stop_connection = False):
3747
3848# Share an image (from a URL) to the Chromecast
3949def show_media (url , x = 0 , duration = 10 ): #duration is in seconds, by default set at 10 (for mp4)
50+ """
51+ Share the media (image or video (URL)) to the Chromecast \n
52+ Example: \n
53+ - show_media("https://[...].png") #Share an image \n
54+ Info: \n
55+ "x" and "duration" are optional and only used for videos (.mp4) \n
56+ - x = Knows the line of the URL in the CSV file, used to check if duration is writen next to a video url\n
57+ - duration = If no duration mention in CSV file, the default duration is set to 10 seconds\n
58+ """
4059 global cast
4160 global mc
4261 mc = cast .media_controller
@@ -53,6 +72,7 @@ def show_media(url, x=0, duration=10): #duration is in seconds, by default set a
5372 print ("Found duration in csv file (" , duration ,"s)" )
5473 else :
5574 print ("No duration found in csv file, set to default (" , duration ,"s)" )
75+ print ("X=" , x , "Medias[x][1]=" , Medias [x ][1 ])
5676 time .sleep (int (duration ))
5777
5878 else :
@@ -62,17 +82,24 @@ def show_media(url, x=0, duration=10): #duration is in seconds, by default set a
6282
6383# Loop through the images in the list (url(s) inside of csv file)
6484def loop (number , Repetition = 1 , EndAfterLoop = False ):
85+ """
86+ number = number of URL in the list (CSV) \n
87+ Repetition = number of time the loop will be repeated \n
88+ EndAfterLoop = if True, the connection will be closed after the end of the loop \n
89+ """
6590 for i in range (Repetition ):
6691 for x in range (number ):
6792 show_media (Medias [x ][0 ], x )
68-
6993 time .sleep (TempsDePause )
7094 if EndAfterLoop == True :
7195 start_cast (stop_connection = True )
7296
7397def clear_log (): # Clear the log file
74- with open ("log.txt" , "w" ) as file :
75- file .write ("" )
98+ """
99+ Clear the log file \n
100+ """
101+ with open ("log.txt" , "w" ) as file :
102+ file .write ("" )
76103##### UI ####
77104def UI ():
78105 def Send ():
@@ -110,7 +137,7 @@ def quit():
110137 # create UI
111138 root = tk .Tk ()
112139 root .title ("Chromecast-URL" )
113- root .geometry ("400x300 " )
140+ root .geometry ("450x350 " )
114141 root .resizable (False , False )
115142 root .configure (background = '#2B2B2B' )
116143
@@ -130,7 +157,7 @@ def quit():
130157 text1 = tk .Entry (root )
131158 text1 .insert (0 , name_of_chromecast )
132159 text1 .pack ()
133- text2_label = tk .Label (root , text = "Time between photos (s):" )
160+ text2_label = tk .Label (root , text = "Time between URLs (s):" )
134161 text2_label .pack ()
135162 text2 = tk .Entry (root )
136163 text2 .insert (0 , time_between_photos )
@@ -146,7 +173,7 @@ def quit():
146173 text1_label .pack ()
147174 text1 = tk .Entry (root )
148175 text1 .pack ()
149- text2_label = tk .Label (root , text = "Time between photos (s):" )
176+ text2_label = tk .Label (root , text = "Time between URLs (s):" )
150177 text2_label .pack ()
151178 text2 = tk .Entry (root )
152179 text2 .pack ()
@@ -162,16 +189,25 @@ def quit():
162189
163190 # Create the submit button
164191 submit_button = tk .Button (root , text = "Submit" , command = Send )
165- submit_button .pack ()
192+ submit_button .pack (ipadx = 20 , ipady = 10 )
193+ submit_button .configure (background = '#6D4AFF' , foreground = '#FFFFFF' , font = ('Arial' , 12 , 'bold' ))
166194
167195 # Create the quit button
168196 quit_button = tk .Button (root , text = "Quit and end connection" , command = quit )
169- quit_button .pack ()
197+ quit_button .pack (side = tk .BOTTOM )
198+ quit_button .configure (background = '#FF4A4A' , foreground = '#FFFFFF' , font = ('Arial' , 12 , 'bold' ))
170199
171200 # Create the clear log button
172201 clear_log_button = tk .Button (root , text = "Clear log" , command = clear_log )
173- clear_log_button .pack ()
174-
202+ clear_log_button .place (relx = 1.0 , rely = 1.0 , anchor = 'se' )
203+
204+ # Add menu bar
205+ menubar = tk .Menu (root )
206+ filemenu = tk .Menu (menubar , tearoff = 0 )
207+ filemenu .add_command (label = "Github" , command = lambda : webbrowser .open_new ("https://github.com/HowlingByte/Cast-URLs-on-ChromeCast" ))
208+ menubar .add_cascade (label = "About" , menu = filemenu )
209+ root .config (menu = menubar )
210+
175211 # When the window is closed, quit the application
176212 root .protocol ("WM_DELETE_WINDOW" , quit )
177213
0 commit comments