Skip to content

Commit

Permalink
Removed PyTube dependency and fixed youtube integration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffser committed Dec 26, 2024
1 parent 19b32a9 commit 133480a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 30 deletions.
14 changes: 0 additions & 14 deletions com.jeffser.Alpaca.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,20 +99,6 @@
}
]
},
{
"name": "python3-pytube",
"buildsystem": "simple",
"build-commands": [
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"pytube\" --no-build-isolation"
],
"sources": [
{
"type": "file",
"url": "https://files.pythonhosted.org/packages/51/64/bcf8632ed2b7a36bbf84a0544885ffa1d0b4bcf25cc0903dba66ec5fdad9/pytube-15.0.0-py3-none-any.whl",
"sha256": "07b9904749e213485780d7eb606e5e5b8e4341aa4dccf699160876da00e12d78"
}
]
},
{
"name": "python3-youtube-transcript-api",
"buildsystem": "simple",
Expand Down
4 changes: 3 additions & 1 deletion src/generic_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import os, requests
from youtube_transcript_api import YouTubeTranscriptApi
from youtube_transcript_api.formatters import TextFormatter
from html2text import html2text
from .internal import cache_dir

Expand Down Expand Up @@ -40,7 +41,8 @@ def attach_youtube(video_title:str, video_author:str, watch_url:str, video_url:s
else:
transcript = YouTubeTranscriptApi.get_transcript(video_id, languages=[caption_name])

result_text += '\n'.join([t['text'] for t in transcript])
result_text += TextFormatter().format_transcript(transcript)
#result_text += '\n'.join([t['text'] for t in transcript])

if not os.path.exists(os.path.join(cache_dir, 'tmp/youtube')):
os.makedirs(os.path.join(cache_dir, 'tmp/youtube'))
Expand Down
22 changes: 7 additions & 15 deletions src/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,13 @@
"""
Handles the main window
"""
import json, threading, os, re, base64, gettext, uuid, shutil, logging, time
import json, threading, os, re, base64, gettext, uuid, shutil, logging, time, requests
import odf.opendocument as odfopen
import odf.table as odftable
from io import BytesIO
from PIL import Image
from pypdf import PdfReader
from datetime import datetime
from pytube import YouTube

import gi
gi.require_version('GtkSource', '5')
Expand Down Expand Up @@ -875,17 +874,10 @@ def current_chat_actions(self, action, user_data):

def youtube_detected(self, video_url):
try:
tries=0
while True:
try:
yt = YouTube(video_url)
video_title = yt.title
break
except Exception as e:
tries+=1
if tries == 4:
raise Exception(e)
transcriptions = generic_actions.get_youtube_transcripts(yt.video_id)
response = requests.get('https://noembed.com/embed?url={}'.format(video_url))
data = json.loads(response.text)

transcriptions = generic_actions.get_youtube_transcripts(data['url'].split('=')[1])
if len(transcriptions) == 0:
self.show_toast(_("This video does not have any transcriptions"), self.main_overlay)
return
Expand All @@ -895,8 +887,8 @@ def youtube_detected(self, video_url):

dialog_widget.simple_dropdown(
_('Attach YouTube Video?'),
_('{}\n\nPlease select a transcript to include').format(video_title),
lambda caption_name, yt=yt, video_url=video_url: generic_actions.attach_youtube(yt.title, yt.author, yt.watch_url, video_url, yt.video_id, caption_name),
_('{}\n\nPlease select a transcript to include').format(data['title']),
lambda caption_name, data=data, video_url=video_url: generic_actions.attach_youtube(data['title'], data['author_name'], data['url'], video_url, data['url'].split('=')[1], caption_name),
transcriptions
)
except Exception as e:
Expand Down

0 comments on commit 133480a

Please sign in to comment.