Skip to content

Commit

Permalink
Version Checker Update
Browse files Browse the repository at this point in the history
* Allow to check for updates or not via argument
  • Loading branch information
cyberofficial committed Aug 2, 2023
1 parent 3609bc4 commit eeeb30e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 18 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ This script uses argparse to accept command line arguments. The following option
| `--use_finetune` | Use fine-tuned model. This will increase accuracy, but will also increase latency. Additional VRAM/RAM usage is required. |
| `--no_log` | Makes it so only the last thing translated/transcribed is shown rather log style list. |
| `--retry` | Retries translations and transcription if they fail. |
| `--updatebranch` | Check which branch from the repo to check for updates. Default is **master**, choices are **master** and **dev-testing**. To turn off update checks use **disable**. |
| `--about` | Shows about the app. |

# Things to note!
Expand Down
Binary file modified modules/__pycache__/parser_args.cpython-310.pyc
Binary file not shown.
Binary file modified modules/__pycache__/version_checker.cpython-310.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions modules/parser_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def parse_arguments():
parser.add_argument("--auto_language_lock", action='store_true', help="Automatically locks the language based on the detected language after set ammount of transcriptions.")
parser.add_argument("--retry", action='store_true', help="Retries the transcription if it fails. May increase output time.")
parser.add_argument("--use_finetune", action='store_true', help="Use finetuned model.")
parser.add_argument("--updatebranch", default="master", help="Check which branch from the repo to check for updates. Default is master, choices are master and dev-testing. To turn off update checks use disable.", choices=["master", "dev-testing", "disable"])
parser.add_argument("--about", action='store_true', help="About the project.")
args = parser.parse_args()
return args
Expand Down
57 changes: 44 additions & 13 deletions modules/version_checker.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import requests
import re
from colorama import Fore, Back, Style, init

version = "1.0.9971"
ScriptCreator = "cyberofficial"
GitHubRepo = "https://github.com/cyberofficial/Synthalingua"
repo_owner = "cyberofficial"
repo_name = "Synthalingua"

def get_remote_version(repo_owner, repo_name, file_path):
url = f"https://raw.githubusercontent.com/{repo_owner}/{repo_name}/master/{file_path}"
def get_remote_version(repo_owner, repo_name, updatebranch, file_path):
url = f"https://raw.githubusercontent.com/{repo_owner}/{repo_name}/{updatebranch}/{file_path}"
response = requests.get(url)

if response.status_code == 200:
Expand All @@ -18,25 +19,55 @@ def get_remote_version(repo_owner, repo_name, file_path):
remote_version = version_search.group(1)
return remote_version
else:
print("Error: Version not found in the remote file.")
print(f"{Fore.RED}Error: Version not found in the remote file.{Style.RESET_ALL}")
return None
else:
print(f"An error occurred. Status code: {response.status_code}")
print(f"{Fore.RED}An error occurred when checking for updates. Status code: {response.status_code}{Style.RESET_ALL}")
print(f"Could not fetch remote version from: {Fore.YELLOW}{url}{Style.RESET_ALL}")
print(f"Please check your internet connection and try again.")
print("\n\n")
return None

def check_for_updates():
def check_for_updates(updatebranch):
local_version = version
remote_version = get_remote_version(repo_owner, repo_name, "transcribe_audio.py")
remote_version = get_remote_version(repo_owner, repo_name, updatebranch, "modules/version_checker.py")

if remote_version is not None:
if remote_version != local_version:
print(f"Version mismatch. Local version: {local_version}, remote version: {remote_version}")
# Split the version numbers into parts (major, minor, patch)
local_version_parts = [int(part) for part in local_version.split(".")]
remote_version_parts = [int(part) for part in remote_version.split(".")]

# Compare major versions
if remote_version_parts[0] > local_version_parts[0]:
print(f"Major version mismatch. Local version: {Fore.YELLOW}{local_version}{Style.RESET_ALL}, remote version: {Fore.YELLOW}{remote_version}{Style.RESET_ALL}")
print("Consider updating to the latest version.")
print(f"Update available at: " + GitHubRepo)
print("\n\n\n\n\n\n")
print(f"Update available at: {GitHubRepo}")
print("\n\n")
elif remote_version_parts[0] == local_version_parts[0]:
# Compare minor versions
if remote_version_parts[1] > local_version_parts[1]:
print(f"Minor version mismatch. Local version: {Fore.YELLOW}{local_version}{Style.RESET_ALL}, remote version: {Fore.YELLOW}{remote_version}{Style.RESET_ALL}")
print("Consider updating to the latest version.")
print(f"Update available at: {GitHubRepo}")
print("\n\n")
elif remote_version_parts[1] == local_version_parts[1]:
# Compare patch versions
if remote_version_parts[2] > local_version_parts[2]:
print(f"Patch version mismatch. Local version: {Fore.YELLOW}{local_version}{Style.RESET_ALL}, remote version: {Fore.YELLOW}{remote_version}{Style.RESET_ALL}")
print("Consider updating to the latest version.")
print(f"Update available at: {GitHubRepo}")
print("\n\n")
else:
print("You are already using the latest version.")
print(f"Current version: {local_version}")
print("\n\n")
else:
print("You are already using a newer version.")
print(f"Current version: {local_version}")
print("\n\n")
else:
print("You are already using the latest version.")
print("You are already using a newer version.")
print(f"Current version: {local_version}")
print("\n\n\n\n\n\n")
print("\n\n")

print("Version Checker Module Loaded")
print("Version Checker Module Loaded")
10 changes: 5 additions & 5 deletions transcribe_audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@
from modules.warnings import print_warning
from modules import parser_args
from modules.languages import get_valid_languages
print("Modules Loaded\n\n\n\n\n")
print("Modules Loaded\n\n")

# Code is semi documented, but if you have any questions, feel free to ask in the Discussions tab.

def main():
args = parser_args.parse_arguments()

check_for_updates()
# if args.updatebranch is set as disable then skip
if args.updatebranch != "disable":
check_for_updates(args.updatebranch)

def record_callback(_, audio:sr.AudioData) -> None:
data = audio.get_raw_data()
Expand Down Expand Up @@ -96,9 +99,6 @@ def is_input_device(device_index):
return sr.Microphone(sample_rate=16000, device_index=index), "system default"

raise ValueError("No valid input devices found.")


args = parser_args.parse_arguments()

if len(sys.argv) == 1:
parser.print_help()
Expand Down

0 comments on commit eeeb30e

Please sign in to comment.