Fixed YouTube integration

This commit is contained in:
jeffser
2024-09-02 16:31:27 -06:00
parent 9d740a7db9
commit 3ceb25ccc6
2 changed files with 6 additions and 4 deletions

View File

@@ -7,6 +7,7 @@ import logging, requests, threading
from pytube import YouTube
from html2text import html2text
from gi.repository import Adw, Gtk
from .internal import cache_dir
logger = logging.getLogger(__name__)
# CLEAR CHAT | WORKS
@@ -337,9 +338,9 @@ def youtube_caption_response(self, dialog, task, video_url, caption_drop_down):
selected_caption = caption_drop_down.get_selected_item().get_string()
for event in yt.captions[selected_caption.split('(')[-1][:-1]].json_captions['events']:
text += "{}\n".format(event['segs'][0]['utf8'].replace('\n', '\\n'))
if not os.path.exists(os.path.join(self.cache_dir, 'tmp/youtube')):
os.makedirs(os.path.join(self.cache_dir, 'tmp/youtube'))
file_path = os.path.join(os.path.join(self.cache_dir, 'tmp/youtube'), f'{yt.title} ({selected_caption.split(" (")[0]})')
if not os.path.exists(os.path.join(cache_dir, 'tmp/youtube')):
os.makedirs(os.path.join(cache_dir, 'tmp/youtube'))
file_path = os.path.join(os.path.join(cache_dir, 'tmp/youtube'), f'{yt.title} ({selected_caption.split(" (")[0]})')
with open(file_path, 'w+', encoding="utf-8") as f:
f.write(text)
self.attach_file(file_path, 'youtube')