From 263df37d0374962e19ccdfbd1f4594db1671f27c Mon Sep 17 00:00:00 2001 From: Bijo Date: Wed, 29 Nov 2023 17:25:12 +0400 Subject: [PATCH] update --- archiver.py | 15 +++++++++++---- archiver_packages/mega.py | 6 +++--- archiver_packages/utilities/youtube_utils.py | 6 +++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/archiver.py b/archiver.py index 58c1ff7..55762e0 100644 --- a/archiver.py +++ b/archiver.py @@ -5,7 +5,7 @@ from archiver_packages.htmls import ending from archiver_packages.utilities.utilities import del_special_chars, convert_date_format, list_files_by_creation_date from archiver_packages.utilities.selenium_utils import chrome_setup -from archiver_packages.utilities.youtube_utils import download_videos_with_info, get_youtube_links_from_playlist, input_youtube_links +from archiver_packages.utilities.youtube_utils import download_videos_with_info, get_youtube_links_from_playlist_and_channel, input_youtube_links from archiver_packages.utilities.archiver_utils import remove_output_folder, chrome_version_exception @@ -113,19 +113,26 @@ def archiver(yt_urls:list,output_directory:str="downloaded"): input("\nMega.io login credentials not found. Please enter them in settings.json") remove_output_folder(output_directory) - + print("\nDownloading videos...") - # Extract yt urls from playlists + # Extract yt urls from playlists and channels for yt_url in yt_urls: if "&list=" in yt_url: - extracted_urls = get_youtube_links_from_playlist(yt_url) + extracted_urls = get_youtube_links_from_playlist_and_channel(yt_url) + yt_urls.remove(yt_url) + yt_urls.extend(extracted_urls) + elif "/@" in yt_url: + extracted_urls = get_youtube_links_from_playlist_and_channel(yt_url) yt_urls.remove(yt_url) yt_urls.extend(extracted_urls) # Download yt videos and extract metadata info_list = download_videos_with_info(yt_urls,output_directory) + print(f"YouTube urls: {len(yt_urls)}") + print(f"Metadata: {len(info_list)}") + # Load chromedriver try: driver = chrome_setup( diff --git a/archiver_packages/mega.py b/archiver_packages/mega.py index fabe327..81e4baf 100644 --- a/archiver_packages/mega.py +++ b/archiver_packages/mega.py @@ -44,10 +44,10 @@ def mega_upload(driver:webdriver.Chrome,login:str,password:str,delay:int,files:l else: WebDriverWait(driver, 60**2*5, poll_frequency=20).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='transfer-progress-txt' and text()='Completed']"))) - # Select file - file = driver.find_element(By.XPATH, f"//span[@class='tranfer-filetype-txt' and text()='{filepath.name}']/parent::*/ancestor::tr") + # Select file on mega + mega_file = driver.find_element(By.XPATH, f'//span[@class="tranfer-filetype-txt" and text()="{filepath.name}"]/parent::*/ancestor::tr') act=ActionChains(driver) - act.move_to_element(file).click().perform() + act.move_to_element(mega_file).click().perform() # Click on get link button sleep(delay+1) diff --git a/archiver_packages/utilities/youtube_utils.py b/archiver_packages/utilities/youtube_utils.py index fe83492..fb498f6 100644 --- a/archiver_packages/utilities/youtube_utils.py +++ b/archiver_packages/utilities/youtube_utils.py @@ -30,7 +30,7 @@ def input_youtube_links() -> list[str]: try: while True: print("\nNOTE:") - print("Add YouTube Videos/Playlists one by one. Finally type 'S/s' to start") + print("Add YouTube Video/Playlist/Channel URLs one by one. Finally type 'S/s' to start") link = input("\n >> Add YouTube link: ") if link.lower()=='s': @@ -38,7 +38,7 @@ def input_youtube_links() -> list[str]: if link not in yt_links: # Avoid duplicates yt_links.append(link) - #print Full list + # Print Full list clear() print("Author\t Title\t Link\t") @@ -55,7 +55,7 @@ def input_youtube_links() -> list[str]: return yt_links -def get_youtube_links_from_playlist(playlist_link:str) -> list[str]: +def get_youtube_links_from_playlist_and_channel(playlist_link:str) -> list[str]: with yt_dlp.YoutubeDL() as ydl: playlist_dict = ydl.extract_info(playlist_link, download=False)