This repository has been archived by the owner on Apr 23, 2024. It is now read-only.
/
turbo-autoplay.py
273 lines (254 loc) · 14.8 KB
/
turbo-autoplay.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
import datetime
import os
import re
import time
import urllib.parse
import urllib.request
from ftplib import FTP # import file from ftp
from subprocess import Popen
import pafy # video api
port = 21
password = 'ftp_login_password'
os.chdir("C:/Files") # dirSave (where the file is stored
ftp = FTP("111.111.1.1") # ip for python ot connect
ftp.login('username_ftp', password)
print("File List:")
files = ftp.dir()
directory = "/files/" # dir (specifies the directory of the ftp)
filematch = '*filename.txt*' # file name
ftp.cwd(directory)
for filename in ftp.nlst(filematch): # Loop - looking for matching files
with open(filename, 'wb') as fhandle:
print('Getting ' + filename) # for confort sake, shows the file that's being retrieved
ftp.retrbinary('RETR ' + filename, fhandle.write)
ftp.delete("/files/filename.txt")
store = [] # empty list
music_lenght = [] # empty list for lenght of videos
def linkConvert(music_name):
query_string = urllib.parse.urlencode({"search_query": music_name})
html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
result = ("http://www.youtube.com/watch?v=" + search_results[0])
if result in store:
print("Music already exists")
print(music_name) # Prints music name that already exists
elif result not in store:
store.append(result)
return print(store)
def Remove_Empty_Lines(filename):
with open(filename, 'r+') as file:
lines = file.readlines()
file.seek(0)
file.writelines(line for line in lines if line.strip()) # for each line if
file.truncate()
Remove_Empty_Lines("C:/Files/filename.txt")
with open("C:/Files/filename.txt", "r", encoding="UTF-8") as file:
for line in file: # for each line on the file pass the line into the function
linkConvert(line)
# Subloop
run_once = 0
run_once1 = 0
run_once2 = 0
run_once3 = 0
run_once4 = 0
run_once5 = 0
run_once6 = 0
run_once7 = 0
run_once8 = 0
# 9:20-9:30
future = datetime.datetime.now() + datetime.timedelta(
seconds=600) # this is the future I stored the first delta in here (put the first interval time in here)
print("The Program is starting")
time.sleep(3)
while True: # make a eternal loop
if datetime.datetime.now() < future:
for music in store: # loop for each music in the list
if datetime.datetime.now() < future: # if the time at the start of the loop is less than the future the music is gona start
video = pafy.new(music)
delay = video.length + 5 # delay of each music passing through the loop
Popen(['start', 'chrome', music], shell=True) # opens in the browser
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True) # closes the browser
# 10:20-10:35
future2 = datetime.datetime.now() + datetime.timedelta(
seconds=3905) # defines the second future (delta time of the delay[this is the lenght of the break - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is the datetime of future2: ",
datetime.datetime.now()) # just to check if everything is going according to plan (to be deleted)
print("This is future2: ", future2) # same as the last (to be deleted)
elif datetime.datetime.now() < future2: # if the time atm is less than the future true green light to start the next condition
time.sleep(5)
print("This is future2: ", future2) # checkpoint (to be deleted - tbd)
pause = datetime.datetime.now() + datetime.timedelta(
seconds=3000) # this is important, this is the pause of the loop. Insert on the seconds the time you want the loop to stop (50min in seconds to be more precise)
# this is the the snippet to pause the script
if run_once == 0:
while pause > datetime.datetime.now():
print("Time is over, first break")
print("Restarting 3000s/50min")
time.sleep(3000) # insert the time of wanted pause here aswell in seconds
run_once = 1
print("This is future2: ", future2) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 11: 25 - 11:35
future3 = datetime.datetime.now() + datetime.timedelta(
seconds=3605) # defines the second future (delta time of the delay[this is the lenght of the interval - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is the datetime of the future3: ",
datetime.datetime.now()) # checkpoint (tbd)
print("This is future3: ", future3) # checkpoint (tbd)
elif datetime.datetime.now() < future3:
time.sleep(5)
print("This is future3: ", future3) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000) # break
if run_once1 == 0:
while pause > datetime.datetime.now():
print("Time is over, second break")
print("Restarting 3000s/50min")
time.sleep(3000) # break
run_once1 = 1
print("This is future3: ", future3) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 12: 25 - 12:30
future4 = datetime.datetime.now() + datetime.timedelta(
seconds=3305) # defines the second future (delta time of the delay[this is the lenght of the interval - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay) ex. 3605
print("This is datetime of future4: ", future4) # checkpoint (tbd)
print("This is future4: ", future4) # checkpoint (tbd)
elif datetime.time.now() < future4:
time.sleep(5)
print("This is future4: ", future4) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000) # break
if run_once2 == 0:
while pause > datetime.datetime.now():
print("Time is over, third break")
print("Restarting 3000s/50min")
time.sleep(3000) # break
run_once2 = 1
print("This is future4: ", future4) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 13:20-13:30
future5 = datetime.datetime.now() + datetime.timedelta(
seconds=3605) # defines the second future (delta time of the delay[this is the lenght of the interval - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is datetime of future5: ", future5) # checkpoint (tbd)
print("This is future5: ", future5) # checkpoint (tbd)
elif datetime.datetime.now() < future5:
time.sleep(5)
print("This is future5: ", future5) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000) # break
if run_once3 == 0:
while pause > datetime.datetime.now():
print("Time is over, fourth break")
print("Restarting 3000s/50min")
time.sleep(3000) # break
run_once3 = 1
print("This is future5: ", future5) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 14:20-14:30
future6 = datetime.datetime.now() + datetime.timedelta(
seconds=3605) # defines the second future (delta time of the delay[this is the lenght of the interval - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is datetime of future6: ", future6) # checkpoint (tbd)
print("This is future6: ", future6) # checkpoint (tbd)
elif datetime.datetime.now() < future6: # if the time atm is less than the future true green light to start the next condition (this gets a somewhat useless check of the last futures. Using as a precaution [to be deleted in the final version])
time.sleep(5)
print("This is future6: ", future6) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000) # break
if run_once4 == 0:
while pause > datetime.datetime.now():
print("Time is over, fifth break ")
print("Restarting 3000s/50min")
time.sleep(3000) # break
run_once4 = 1
print("This is future6: ", future6) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 15: 20 - 15:30
future7 = datetime.datetime.now() + datetime.timedelta(
seconds=3605) # defines the second future (delta time of the delay[this is the lenght of the break - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is datetime of future7: ", future7) # checkpoint (tbd)
print("This is future7: ", future7) # checkpoint (tbd)
elif datetime.datetime.now() < future7:
time.sleep(5)
print("This is future7: ", future7) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000) # break
if run_once5 == 0:
while pause > datetime.datetime.now():
print("Time is over, sixth break")
print("Restarting 3000s/50min")
time.sleep(3000) # break
run_once5 = 1
print("This is future7: ", future7) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 16:20-16:35
future8 = datetime.datetime.now() + datetime.timedelta(
seconds=3605) # defines the second future (delta time of the delay[this is the lenght of the break - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is datetime of future8: ", future8) # checkpoint (tbd)
print("This is future8: ", future8) # checkpoint (tbd)
elif datetime.datetime.now() < future8:
time.sleep(5)
print("This is future8: ", future8) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000) # break
if run_once6 == 0:
while pause > datetime.datetime.now():
print("Time is over, seventh braek")
print("Restarting 3000s/50min")
time.sleep(3000) # break
run_once6 = 1
print("This is future8: ", future8) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
# 17:25-17:30
future9 = datetime.datetime.now() + datetime.timedelta(
seconds=3305) # defines the second future (delta time of the delay[this is the lenght of the break - 10min but needs to be added the class duration. 10min in seconds + 50min in seconds + 5s of delay)
print("This is datetime of future9: ", future9) # checkpoint (tbd)
print("This is future9: ", future9) # checkpoint (tbd)
elif datetime.datetime.now() < future9:
print("This is future9: ", future9) # checkpoint (tbd)
pause = datetime.datetime.now() + datetime.timedelta(seconds=3000)
if run_once7 == 0:
while pause > datetime.datetime.now():
print("Time is over")
print("Restarting 3000s/50min")
time.sleep(3000)
run_once7 = 1
print("This is future9: ", future9) # checkpoint (tbd)
video = pafy.new(music)
delay = video.length + 5
Popen(['start', 'chrome', music], shell=True)
print("Waiting ", delay, " seconds for the music to stop")
time.sleep(delay)
Popen('taskkill /F /IM chrome.exe', shell=True)
elif datetime.datetime.now() > future9:
print("The Time is over for today... turning off the program...")
break