Skip to content

Commit

Permalink
added yt and ts to poetry and to config in setup.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
xssdoctor committed Mar 3, 2024
1 parent aa33795 commit 914f6b4
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
2 changes: 0 additions & 2 deletions helpers/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ These are helper tools to work with Fabric. Examples include things like getting

```bash

pip install -r requirements.txt

mac:
brew install ffmpeg

Expand Down
4 changes: 0 additions & 4 deletions helpers/requirements.txt

This file was deleted.

File renamed without changes.
24 changes: 16 additions & 8 deletions helpers/yt → helpers/yt.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
#!/usr/bin/env python3

import sys
import re
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
Expand All @@ -11,12 +8,14 @@
import isodate
import argparse


def get_video_id(url):
# Extract video ID from URL
pattern = r'(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?:[^\/\n\s]+\/\S+\/|(?:v|e(?:mbed)?)\/|\S*?[?&]v=)|youtu\.be\/)([a-zA-Z0-9_-]{11})'
match = re.search(pattern, url)
return match.group(1) if match else None


def main(url, options):
# Load environment variables from .env file
load_dotenv(os.path.expanduser('~/.config/fabric/.env'))
Expand Down Expand Up @@ -51,7 +50,8 @@ def main(url, options):
# Get video transcript
try:
transcript_list = YouTubeTranscriptApi.get_transcript(video_id)
transcript_text = ' '.join([item['text'] for item in transcript_list])
transcript_text = ' '.join([item['text']
for item in transcript_list])
transcript_text = transcript_text.replace('\n', ' ')
except Exception as e:
transcript_text = "Transcript not available."
Expand All @@ -72,14 +72,22 @@ def main(url, options):
except HttpError as e:
print("Error: Failed to access YouTube API. Please check your YOUTUBE_API_KEY and ensure it is valid.")

if __name__ == '__main__':
parser = argparse.ArgumentParser(description='vm (video meta) extracts metadata about a video, such as the transcript and the video\'s duration. By Daniel Miessler.')

def main():
parser = argparse.ArgumentParser(
description='vm (video meta) extracts metadata about a video, such as the transcript and the video\'s duration. By Daniel Miessler.')
parser.add_argument('url', nargs='?', help='YouTube video URL')
parser.add_argument('--duration', action='store_true', help='Output only the duration')
parser.add_argument('--transcript', action='store_true', help='Output only the transcript')
parser.add_argument('--duration', action='store_true',
help='Output only the duration')
parser.add_argument('--transcript', action='store_true',
help='Output only the transcript')
args = parser.parse_args()

if args.url:
main(args.url, args)
else:
parser.print_help()


if __name__ == "__main__":
main()
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,5 @@ build-backend = "poetry.core.masonry.api"
fabric = 'installer:cli'
fabric-api = 'installer:run_api_server'
fabric-webui = 'installer:run_webui_server'
ts = 'helpers.ts:main'
yt = 'helpers.yt:main'
5 changes: 2 additions & 3 deletions setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ echo "Installing python dependencies"
poetry install

# List of commands to check and add or update alias for
commands=("fabric" "fabric-api" "fabric-webui")

# Add 'yt' and 'ts' to the list of commands
commands=("fabric" "fabric-api" "fabric-webui" "ts", "yt")

# List of shell configuration files to update
config_files=("$HOME/.bashrc" "$HOME/.zshrc" "$HOME/.bash_profile")
Expand Down Expand Up @@ -69,4 +69,3 @@ if [ ${#source_commands[@]} -ne 0 ]; then
else
echo "No configuration files were updated. No need to source."
fi

0 comments on commit 914f6b4

Please sign in to comment.