Skip to content

Commit 92924f1

Browse files
authored
Add files via upload
1 parent 94c4120 commit 92924f1

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

pyautosrt/__init__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
# ADDTIONAL IMPORTS
2222
import io
2323
import time
24-
import signal
2524
import threading
2625
from threading import Timer, Thread
2726
import PySimpleGUI as sg
@@ -565,22 +564,24 @@ def find_speech_regions(filename, frame_width=4096, min_region_size=0.3, max_reg
565564
return regions
566565

567566

568-
async def GoogleTranslate(text, src, dst):
567+
def GoogleTranslate(text, src, dst):
569568
url = 'https://translate.googleapis.com/translate_a/'
570569
params = 'single?client=gtx&sl='+src+'&tl='+dst+'&dt=t&q='+text;
571-
async with httpx.AsyncClient() as client:
572-
response = await client.get(url+params)
573-
#print('response = {}'.format(response))
574-
response_json = response.json()[0]
575-
#print('response_json = {}'.format(response_json))
576-
length = len(response_json)
577-
#print('length = {}'.format(length))
578-
translation = ""
579-
for i in range(length):
580-
#print("{} {}".format(i, response_json[i][0]))
581-
translation = translation + response_json[i][0]
582-
return translation
583-
570+
with httpx.Client(http2=True) as client:
571+
client.headers.update({'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', 'Referer': 'https://translate.google.com',})
572+
response = client.get(url+params)
573+
#print('response.status_code = {}'.format(response.status_code))
574+
if response.status_code == 200:
575+
response_json = response.json()[0]
576+
#print('response_json = {}'.format(response_json))
577+
length = len(response_json)
578+
#print('length = {}'.format(length))
579+
translation = ""
580+
for i in range(length):
581+
#print("{} {}".format(i, response_json[i][0]))
582+
translation = translation + response_json[i][0]
583+
return translation
584+
return
584585

585586
class SentenceTranslator(object):
586587
def __init__(self, src, dest, patience=-1):
@@ -593,7 +594,9 @@ def __call__(self, sentence):
593594
# handle the special case: empty string.
594595
if not sentence:
595596
return None
596-
translated_sentence = asyncio.get_event_loop().run_until_complete(GoogleTranslate(sentence, src=self.src, dst=self.dest)) # using self made GoogleTranslate2()
597+
598+
translated_sentence = GoogleTranslate(sentence, src=self.src, dst=self.dest)
599+
597600
fail_to_translate = translated_sentence[-1] == '\n'
598601
while fail_to_translate and patience:
599602
translated_sentence = translator.translate(translated_sentence, src=self.src, dest=self.dest).text
@@ -607,7 +610,6 @@ def __call__(self, sentence):
607610

608611

609612
def transcribe(src, dest, filename, subtitle_format, main_window):
610-
#global thread_transcribe, not_transcribing, pool, wav_filename, subtitle_file, translated_subtitle_file, subtitle_folder_name, converter, recognizer, extracted_regions, transcriptions
611613
global thread_transcribe, not_transcribing, pool
612614

613615
if not_transcribing: return

setup.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
setup(
2020
name="pyautosrt",
21-
version="0.0.5",
21+
version="0.0.6",
2222
description="pyautosrt is a python based desktop app to generate subtitle and translated subtitle file",
2323
long_description = long_description,
2424
author="Bot Bahlul",
@@ -36,7 +36,6 @@
3636
"six>=1.11.0",
3737
"tk>=0.1.0",
3838
"pysimplegui>=4.60.1",
39-
"asyncio",
4039
"httpx>=0.13.3",
4140
],
4241
license=open("LICENSE").read()

0 commit comments

Comments
 (0)