Browse Source

added yt and ts to poetry and to config in setup.sh

pull/153/head v1.1.2
jad2121 9 months ago
parent
commit
914f6b46c3
  1. 2
      helpers/README.md
  2. 4
      helpers/requirements.txt
  3. 0
      helpers/ts.py
  4. 24
      helpers/yt.py
  5. 2
      pyproject.toml
  6. 5
      setup.sh

2
helpers/README.md

@ -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

4
helpers/requirements.txt

@ -1,4 +0,0 @@
isodate
python-dotenv
google-api-python-client
youtube_transcript_api

0
helpers/ts → helpers/ts.py

24
helpers/yt → helpers/yt.py

@ -1,6 +1,3 @@
#!/usr/bin/env python3
import sys
import re
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
@ -11,12 +8,14 @@ import json
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'))
@ -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."
@ -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
pyproject.toml

@ -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
setup.sh

@ -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")
@ -69,4 +69,3 @@ if [ ${#source_commands[@]} -ne 0 ]; then
else
echo "No configuration files were updated. No need to source."
fi

Loading…
Cancel
Save