danielmiessler / fabric

fabric is an open-source framework for augmenting humans using AI. It provides a modular framework for solving specific problems using a crowdsourced set of AI prompts that can be used anywhere.
https://danielmiessler.com/p/fabric-origin-story
MIT License
25.59k stars 2.72k forks source link

raycast bash script #1075

Open lexilexikon opened 1 month ago

lexilexikon commented 1 month ago

Discussed in https://github.com/danielmiessler/fabric/discussions/1032

Originally posted by **lexilexikon** October 7, 2024 I've installed fabric and tried to use the Raycast script command to get the transcript of a YouTube video. The bash script is breaking and it keeps saying 'invalid YouTube URL, can't get video ID'. That was the URL I retrieved: https://youtu.be/7Inkwc23U1M. I've also installed a YouTube API. I don't have this issue using the terminal instead of Raycast. Can anyone help me figure out what's going wrong?"
polyglotdev commented 2 weeks ago

Hey @lexilexikon! I was able to to get the following script to work in Raycast:

⚠️ To use this implementation you will need to download yt-dlp. On macOS you can run brew install yt-dlp

#!/bin/zsh

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Fabric YouTube Summary Generation
# @raycast.mode compact

# Optional parameters:
# @raycast.icon 🤖
# @raycast.argument1 { "type": "text", "placeholder": "YouTube URL" }
# @raycast.packageName fabric-aliased-commands

# Documentation:
# @raycast.description Using fabric to generate YouTube Video summary
# @raycast.author dom_hallan
# @raycast.authorURL https://raycast.com/dom_hallan

# Source zsh configuration to get access to your PATH and aliases
source ~/.zshrc

# Validate input
if [ -z "$1" ]; then
    echo "Error: Please provide a YouTube URL"
    exit 1
fi

# Set Obsidian vault path
obsidian_base="/Users/domhallan/domhallan-obsidian-notes/notes/"

# Generate timestamp
date_stamp=$(date +'%Y-%m-%d')

# Get video title using yt-dlp
video_title=$(yt-dlp --get-title "$1" | tr -d '\n' | sed 's/:/-/g' | sed 's/[^a-zA-Z0-9-]/-/g' | tr -s '-')
output_file="${obsidian_base}${date_stamp}-${video_title}.md"

# Execute the command and save output
echo "# YouTube Summary: $1" > "$output_file"
echo "Date: $date_stamp" >> "$output_file"
echo "URL: $1" >> "$output_file"
echo "\n---\n" >> "$output_file"

# Debug: First get the transcript and save it
echo "Fetching transcript..."
transcript=$(fabric -y "$1" --transcript)
echo "Transcript length: ${#transcript}"

if [ -n "$transcript" ]; then
    echo "Processing transcript with fabric..."
    echo "$transcript" | fabric -sp extract_wisdom | tee -a "$output_file"
else
    echo "Error: No transcript was fetched" | tee -a "$output_file"
fi

echo "\nSummary saved to: $output_file"

2024-11-08-youtube-summary-nTQIYWgn-lQ - notes - Obsidian v1 7 5 2024-11-08 at 1 19 35 PM

One last thing

Make sure that when you select a YouTube video that you right click on the video itself and choose copy video URL because the share sheet link does not work

Here is the recording of things working:

https://github.com/user-attachments/assets/5358c6e3-4280-4a95-a6de-7f4a1d165aea

I hope this is helpful!

polyglotdev commented 2 weeks ago

@lexilexikon did this answer your question?

lexilexikon commented 2 weeks ago

Hi @polyglotdev Thank you for your help! Unfortunately I'm still not able to get it running. Im using the script which is in the github repository. But I'm always getting the error message 'invalid YouTube URL, can't get video ID'. When I'm working with the terminal on my mac it works like a charm.

#!/bin/bash`

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Get YouTube Transcript
# @raycast.mode fullOutput

# Optional parameters:
# @raycast.icon 🧠
# @raycast.argument1 { "type": "text", "placeholder": "Input text", "optional": false, "percentEncoded": true}

# Documentation:
# @raycast.description Run fabric -y on the input text of a YouTube video to get the transcript from.
# @raycast.author Daniel Miessler
# @raycast.authorURL https://github.com/danielmiessler

# Set PATH to include common locations and $HOME/go/bin
PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:$HOME/go/bin:$PATH"

# Use the PATH to find and execute fabric
if command -v fabric >/dev/null 2>&1; then
    fabric -y "${1}"
else
    echo "Error: fabric command not found in PATH"
    echo "Current PATH: $PATH"
    exit 1
`fi

I'm new to coding, so I hardly understand what the bash script is doing.

polyglotdev commented 1 week ago

@lexilexikon Where are you getting the URL for the YouTube video from?

lexilexikon commented 1 week ago

I tried different ways. Right-click on the youtube video and clicking on the "copy video-url". I also tried to fetch it from the browser window (search bar). I know that the "www.yout.be..." URL seams to be problematic.