Skip to content

Commit

Permalink
v1.4.3
Browse files Browse the repository at this point in the history
- fixed channel name
  • Loading branch information
countervolts committed Sep 23, 2024
1 parent 0792bdb commit 0501425
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 20 deletions.
15 changes: 7 additions & 8 deletions archiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@
from compression.compressor import main as compressor_main
from convert.local import convert_videos
from config import API_KEY, YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION, DOWNLOAD_QUALITY, SKIP_SHORTS
from utils.misc.misc import check_config, info_getter, print_status
from utils.ytutils.ythelper import parse_duration, is_short
from utils.dlutils.dl import download_video
from utils.misc.misc import check_config, info_getter
from utils.ytutils.ythelper import get_channel_id, get_video_ids, get_video_details, parse_duration, is_short
from utils.dlutils.dl import download_video, print_status
from utils.dlutils.path import save_download_path
from utils.ytutils.get import get_channel_id, get_video_ids, get_video_details

check_config()

Expand All @@ -28,7 +27,7 @@ def main():
os.system('cls' if os.name == 'nt' else 'clear')
info_getter()
channel_name = input("\nEnter YouTube channel name: ")
channel_id, display_name = get_channel_id(channel_name)
channel_id = get_channel_id(channel_name)

base_path = os.path.join('yt_data', channel_id)
os.makedirs(base_path, exist_ok=True)
Expand Down Expand Up @@ -74,7 +73,7 @@ def main():
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")

with open(channel_info_path, 'w', encoding='utf-8') as channel_info_file:
channel_info_file.write(f"Channel Name: {display_name}\n")
channel_info_file.write(f"Channel Name: {channel_name}\n")
channel_info_file.write(f"Channel ID: {channel_id}\n")
channel_info_file.write(f"Number of cached videos: {num_videos}\n")
channel_info_file.write(f"Data saved on: {timestamp}\n")
Expand Down Expand Up @@ -123,7 +122,7 @@ def main():
newest_video = video['snippet']['title']

os.system('cls' if os.name == 'nt' else 'clear')
print(f"{Fore.CYAN}channel: {Fore.YELLOW}{display_name}{Style.RESET_ALL}")
print(f"{Fore.CYAN}channel: {Fore.YELLOW}{channel_name}{Style.RESET_ALL}")
print(f"{Fore.CYAN}videos: {Fore.YELLOW}{len(video_details)}{Style.RESET_ALL}")
print(f"{Fore.CYAN}total length: {Fore.YELLOW}{total_duration}{Style.RESET_ALL}")
print(f"{Fore.CYAN}est size: {Fore.YELLOW}{total_size_estimate_str}{Style.RESET_ALL}")
Expand Down Expand Up @@ -159,7 +158,7 @@ def main():
total_size_str = f"{total_size / (1024 * 1024):.2f} MB"

with open(os.path.join(base_path, f'{channel_id}_post_download_info.txt'), 'w', encoding='utf-8') as info_file:
info_file.write(f"channel: {display_name}\n")
info_file.write(f"channel: {channel_name}\n")
info_file.write(f"videos downloaded: {len(video_details)}\n")
info_file.write(f"time it took: {elapsed_time}\n")
info_file.write(f"est size: {total_size_estimate_str}\n")
Expand Down
4 changes: 1 addition & 3 deletions utils/ytutils/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ def get_channel_id(channel_name):
maxResults=1
)
response = request.execute()
channel_id = response['items'][0]['snippet']['channelId']
display_name = response['items'][0]['snippet']['title']
return channel_id, display_name
return response['items'][0]['snippet']['channelId']

def get_video_ids(channel_id):
video_ids = []
Expand Down
11 changes: 2 additions & 9 deletions utils/ytutils/ythelper.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import re
from datetime import timedelta, datetime
from datetime import timedelta

def parse_duration(duration):
match = re.match(r'PT(\d+H)?(\d+M)?(\d+S)?', duration)
Expand All @@ -13,11 +13,4 @@ def is_short(video):
print(f"Skipping video {video.get('snippet', {}).get('title', 'Unknown')} due to missing duration info.")
return False
duration = parse_duration(video['contentDetails']['duration'])
return duration < timedelta(minutes=1)

def save_channel_info(channel_id, display_name, video_count, save_path):
with open(save_path, 'w') as file:
file.write(f"Channel Name: {display_name}\n")
file.write(f"Channel ID: {channel_id}\n")
file.write(f"Number of cached videos: {video_count}\n")
file.write(f"Data saved on: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}\n")
return duration < timedelta(minutes=1)

0 comments on commit 0501425

Please sign in to comment.