1919"""
2020Handles 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
2323import odf .opendocument as odfopen
2424import odf .table as odftable
2525from io import BytesIO
2626from PIL import Image
2727from pypdf import PdfReader
2828from datetime import datetime
29- from pytube import YouTube
3029
3130import gi
3231gi .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 \n Please 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 \n Please 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