Skip to content

Commit 133480a

Browse files
committed
Removed PyTube dependency and fixed youtube integration
1 parent 19b32a9 commit 133480a

File tree

3 files changed

+10
-30
lines changed

3 files changed

+10
-30
lines changed

com.jeffser.Alpaca.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,6 @@
9999
}
100100
]
101101
},
102-
{
103-
"name": "python3-pytube",
104-
"buildsystem": "simple",
105-
"build-commands": [
106-
"pip3 install --verbose --exists-action=i --no-index --find-links=\"file://${PWD}\" --prefix=${FLATPAK_DEST} \"pytube\" --no-build-isolation"
107-
],
108-
"sources": [
109-
{
110-
"type": "file",
111-
"url": "https://files.pythonhosted.org/packages/51/64/bcf8632ed2b7a36bbf84a0544885ffa1d0b4bcf25cc0903dba66ec5fdad9/pytube-15.0.0-py3-none-any.whl",
112-
"sha256": "07b9904749e213485780d7eb606e5e5b8e4341aa4dccf699160876da00e12d78"
113-
}
114-
]
115-
},
116102
{
117103
"name": "python3-youtube-transcript-api",
118104
"buildsystem": "simple",

src/generic_actions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import os, requests
77
from youtube_transcript_api import YouTubeTranscriptApi
8+
from youtube_transcript_api.formatters import TextFormatter
89
from html2text import html2text
910
from .internal import cache_dir
1011

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

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

4547
if not os.path.exists(os.path.join(cache_dir, 'tmp/youtube')):
4648
os.makedirs(os.path.join(cache_dir, 'tmp/youtube'))

src/window.py

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@
1919
"""
2020
Handles the main window
2121
"""
22-
import json, threading, os, re, base64, gettext, uuid, shutil, logging, time
22+
import json, threading, os, re, base64, gettext, uuid, shutil, logging, time, requests
2323
import odf.opendocument as odfopen
2424
import odf.table as odftable
2525
from io import BytesIO
2626
from PIL import Image
2727
from pypdf import PdfReader
2828
from datetime import datetime
29-
from pytube import YouTube
3029

3130
import gi
3231
gi.require_version('GtkSource', '5')
@@ -875,17 +874,10 @@ def current_chat_actions(self, action, user_data):
875874

876875
def youtube_detected(self, video_url):
877876
try:
878-
tries=0
879-
while True:
880-
try:
881-
yt = YouTube(video_url)
882-
video_title = yt.title
883-
break
884-
except Exception as e:
885-
tries+=1
886-
if tries == 4:
887-
raise Exception(e)
888-
transcriptions = generic_actions.get_youtube_transcripts(yt.video_id)
877+
response = requests.get('https://noembed.com/embed?url={}'.format(video_url))
878+
data = json.loads(response.text)
879+
880+
transcriptions = generic_actions.get_youtube_transcripts(data['url'].split('=')[1])
889881
if len(transcriptions) == 0:
890882
self.show_toast(_("This video does not have any transcriptions"), self.main_overlay)
891883
return
@@ -895,8 +887,8 @@ def youtube_detected(self, video_url):
895887

896888
dialog_widget.simple_dropdown(
897889
_('Attach YouTube Video?'),
898-
_('{}\n\nPlease select a transcript to include').format(video_title),
899-
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),
890+
_('{}\n\nPlease select a transcript to include').format(data['title']),
891+
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),
900892
transcriptions
901893
)
902894
except Exception as e:

0 commit comments

Comments
 (0)