Created
November 16, 2024 15:53
-
-
Save regenrek/146a21822028d4ce7d9a7da85ce6be78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title gimmevid | |
# @raycast.mode compact | |
# Optional parameters: | |
# @raycast.icon ▶️ | |
# @raycast.argument1 { "type": "text", "placeholder": "Insert Video Url..." } | |
# Documentation: | |
# @raycast.author kevin_regenrek | |
# @raycast.authorURL https://raycast.com/kevin_regenrek | |
# Define the download path and max filename length | |
DOWNLOAD_PATH="<ENTER YOUR PATH>" | |
MAX_FILENAME_LENGTH=50 # Adjust this length if necessary | |
# Set output template with a shorter title length | |
yt-dlp -f "bv*+ba/b" --merge-output-format mp4 -o "$DOWNLOAD_PATH/%(title).50s.%(ext)s" "$1" | |
# Check if any downloaded file exceeds the max filename length and rename if necessary | |
for file in "$DOWNLOAD_PATH"/*; do | |
if [ -f "$file" ]; then | |
filename=$(basename "$file") | |
extension="${filename##*.}" | |
title="${filename%.*}" | |
# If filename length exceeds max, truncate it and rename the file | |
if [ ${#title} -gt $MAX_FILENAME_LENGTH ]; then | |
truncated_title="${title:0:MAX_FILENAME_LENGTH}" | |
new_filename="${truncated_title}.${extension}" | |
mv "$file" "$DOWNLOAD_PATH/$new_filename" | |
fi | |
fi | |
done | |
# Open the download directory | |
open "$DOWNLOAD_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment