Skip to content

Instantly share code, notes, and snippets.

@JoJoseph25
Last active June 25, 2021 13:17
Show Gist options
  • Save JoJoseph25/dbfdc5d1b0c631e24a8d045033e56459 to your computer and use it in GitHub Desktop.
Save JoJoseph25/dbfdc5d1b0c631e24a8d045033e56459 to your computer and use it in GitHub Desktop.
Multi-threaded program to get simultaneous video list from channels mentioned in a text file
import time
import threading #standard python muti-threading library
#YouTube bot to make a YouTube videos list (no API token required)
from yt_videos_list import ListCreator #https://pypi.org/project/yt-videos-list/
my_driver = 'firefox' #Selenium driver to use
#increase scroll time if program ends prematurely or slow internet
lc = ListCreator(driver=my_driver, scroll_pause_time=2)
number_of_threads = 3 #number of channels to parse simultaneously
path_to_channel_urls_file = 'channels.txt' #mention channel url in sperate lines
with open(path_to_channel_urls_file, 'r', encoding='utf-8') as file:
for url in file:
#add 1 since main thread counts as a thread
while threading.active_count() == number_of_threads + 1:
#wait 5 seconds before checking to see if a previously running thread completed
time.sleep(5)
thread = threading.Thread(target=lc.create_list_for, args=(url, True))
thread.start()
thread.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment