This commit is contained in:
|| Prof. - Xadk3! 2023-04-30 15:20:40 +00:00
commit a73b4f044d
5 changed files with 52 additions and 0 deletions

3
.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.log
*.pyc
__pycache__/

3
README.md Normal file
View file

@ -0,0 +1,3 @@
# TransLait [🉑️/❤️‍🔥]
---
> Powered by <a href="https://translate.google.com">Google Translate!</a>

24
install_driver.sh Executable file
View file

@ -0,0 +1,24 @@
#!/bin/bash
DRIVER_NAME="geckodriver"
LATEST_RELEASE_TAG="$(curl -s 'https://api.github.com/repos/mozilla/geckodriver/releases/latest' -o - | grep tag_name | head -n 2 | cut -d '"' -f 4)"
function download_driver () {
axel -an 9 "https://github.com/mozilla/$DRIVER_NAME/releases/download/$LATEST_RELEASE_TAG/$DRIVER_NAME-$LATEST_RELEASE_TAG-linux64.tar.gz"
tar xvf "$DRIVER_NAME-$LATEST_RELEASE_TAG-linux64.tar.gz"
rm "$DRIVER_NAME-$LATEST_RELEASE_TAG-linux64.tar.gz"
}
if [ ! -f "$DRIVER_NAME" ]; then
download_driver
else
LOCAL_RELEASE_TAG="v$(./geckodriver -V | head -n 1 | cut -d ' ' -f 2)"
if [[ "$LOCAL_RELEAsE_TAG" != "$LATEST_RELEASE_TAG" ]]; then
echo "[+] Downloading Latest $DRIVER_NAME"
rm -rf "./$DRIVER_NAME"
download_driver
fi
fi
export PATH="$PWD:$PATH"
sudo cp "./$DRIVER_NAME" /usr/bin

1
requirements.txt Normal file
View file

@ -0,0 +1 @@
selenium

21
translate.py Executable file
View file

@ -0,0 +1,21 @@
#!/usr/bin/env python3
from selenium import webdriver
browser = webdriver.Firefox()
TRP_CONSTRUCT = "https://DOMAIN.translate.goog/PATH/?_x_tr_sl=auto&_x_tr_tl=en&_x_tr_hl=en-US&_x_tr_pto=wapp"
url = input("Enter URL you wish to translate: ")
remote_domain = url.split('://')[1].split('/')[0]
remote_path = '/'.join(url.split('/')[3:])
rDUri = remote_domain.replace('.', '-')
if '?' in remote_path:
remote_path = remote_path.split('?')[0]
remote_URL_query = ''.join(url.split('?')[1:])
rUrl = TRP_CONSTRUCT.replace('DOMAIN', rDUri).replace('PATH', remote_path) + '&' + remote_URL_query
else:
rUrl = TRP_CONSTRUCT.replace('DOMAIN', rDUri).replace('PATH', remote_path)
print("Executing :" + rUrl + " \nwithin DOM.")
browser.get(rUrl)
browser.execute_script('''document.querySelector('iframe').style.display = "none";document.querySelector('iframe').remove()''')