-
Notifications
You must be signed in to change notification settings - Fork 0
/
add_video.py
54 lines (40 loc) · 1.37 KB
/
add_video.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
import keyboard
import tkinter
import time
import random
prev_urls = []
video_ids = []
root = tkinter.Tk()
playlist_name = input("name of playlist to add to ")
time.sleep(0.6)
prev_clipboard = "fillerclipboard"
curr_clipboard = prev_clipboard
#limit loops to prevent infinite loop
for i in range(50):
counter = 0
#copy url using keyboard shortcuts and wait until it is actually copied
while (prev_clipboard == curr_clipboard and counter < 20):
keyboard.press_and_release('ctrl + l')
keyboard.press_and_release('ctrl + c')
time.sleep(0.1)
curr_clipboard = root.clipboard_get()
counter += 1
prev_clipboard = curr_clipboard
print("clip board received")
#stop after cycling through all the tabs
if curr_clipboard in prev_urls:
break
prev_urls.append(curr_clipboard)
#search url for youtube and get video id
url_parts = curr_clipboard.split("/")
if (len(url_parts) > 3):
if url_parts[2] == "www.youtube.com" and url_parts[3][0:8] == "watch?v=":
video_ids.append(url_parts[3][8:19])
print("added video id")
#switch tabs
keyboard.press_and_release('ctrl + tab')
#add ids to file
f = open('playlist' + playlist_name + '.txt', 'a')
for i in range(len(video_ids)):
f.write(',' + video_ids[i])
f.close()