Skip to content

Instantly share code, notes, and snippets.

@BishopKO
Last active February 1, 2021 23:20
Show Gist options
  • Save BishopKO/822c94b18b435510a7dd91b6d26ec1ed to your computer and use it in GitHub Desktop.
Save BishopKO/822c94b18b435510a7dd91b6d26ec1ed to your computer and use it in GitHub Desktop.
import pytube
import clipboard
import time
import sys
class DownTube:
def __init__ (self, mode="listen"):
mode = sys.argv[1][1:]
if mode=="listen":
self.clear_list_file()
print("Waiting for links in clipboard...")
self.add_links()
elif mode == "download":
self.download()
def clear_list_file(self):
file = open("tunes_list.txt", "w")
file.close()
def count_list(self):
return len(open("tunes_list.txt", "r").readlines())
def check_duplicates(self, address):
with open("tunes_list.txt", "r") as file:
for line in file.readlines():
if line.strip() == address:
print("Link already on the list...")
return False
return True
def add_links(self):
current = clipboard.paste()
while True:
if current != clipboard.paste():
current = clipboard.paste()
if current.find("https://youtu.be/") != -1 and self.check_duplicates(current):
with open("tunes_list.txt", "a") as file:
file.write(current+"\n")
print("Added new link to links list")
time.sleep(1)
def download(self):
counter = self.count_list()
with open("tunes_list.txt", 'r') as line:
for nr, link in enumerate(line.readlines(), 1):
link = link.strip()
try:
yt = pytube.YouTube(link)
print(f"Download... {nr}/{counter} - '{yt.title}'")
yt.streams.get_by_itag(140).download("e:\\muza\\")
except Exception as e:
print("Download failed: ", nr)
print(e)
return False
self.clear_list_file()
input("Finished, list cleared... press Enter.")
if __name__ == "__main__":
downtube = DownTube()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment