|
|
@@ -15,7 +15,7 @@ DAYS_TO_KEEP = 10 # Delete videos older than 10 days
|
|
|
TOKEN_FILE = "youtube_token.pickle" # Token file from the OAuth script
|
|
|
EXIT_TIME = datetime.time(6, 0) # Exit the script at 06:00
|
|
|
POPULAR_VIDEOS_MAX_RESULTS = 10 # Number of popular videos to fetch (you can change this)
|
|
|
-REGION_CODES = ["US", "GB", "LU"] # Regions to fetch popular videos from
|
|
|
+REGION_CODES = ["US", "GB", "LU", "LK"] # Regions to fetch popular videos from
|
|
|
|
|
|
def update_yt_dlp():
|
|
|
"""Update yt-dlp to the latest version."""
|
|
|
@@ -106,19 +106,22 @@ def get_popular_videos(youtube, region_code):
|
|
|
return popular_videos
|
|
|
|
|
|
def download_video(video_id, output_path):
|
|
|
- """Download a YouTube video in the best quality, handling errors gracefully."""
|
|
|
+ """Download a YouTube video prioritizing 4K non-AV1 formats, with fallback options."""
|
|
|
try:
|
|
|
command = [
|
|
|
"yt-dlp",
|
|
|
- "-f", "bestvideo+bestaudio/best", # Best available format
|
|
|
+ "-f", "bv[height=2160][vcodec!*=av1]+ba / bv[height<=1080]+ba / best",
|
|
|
+ "--merge-output-format", "mp4",
|
|
|
+ "--no-mtime",
|
|
|
f"https://www.youtube.com/watch?v={video_id}",
|
|
|
"-o", os.path.join(output_path, "%(title)s.%(ext)s")
|
|
|
]
|
|
|
subprocess.run(command, check=True)
|
|
|
+ print(f"Successfully downloaded video {video_id}")
|
|
|
except subprocess.CalledProcessError as e:
|
|
|
print(f"Error downloading video {video_id}: {e}")
|
|
|
- return False # Return False to indicate failure
|
|
|
- return True # Return True if download is successful
|
|
|
+ return False
|
|
|
+ return True
|
|
|
|
|
|
# Temporarily commented out video conversion functionality
|
|
|
# def convert_to_mp4(input_file):
|