From 07054947d701f20a60e7e3fc0024ff57037fc580 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Tue, 15 Feb 2022 17:14:47 -0600 Subject: [PATCH] shell cleanup/reordering --- src/Python/Scripts/GTK/edit-path | 213 ++++++++++ src/Python/Scripts/GTK/edit-path/__main__.py | 151 ------- src/Python/Scripts/GTK/edit-path/main.glade | 162 -------- .../{a-z-folder-maker.sh => a-z-folder-maker} | 0 src/Shell/Utils/ani-cli | 373 ++++++++++++++++++ .../{clean-start-menu.sh => clean-start-menu} | 0 ...ear-pycache-dirs.sh => clear-pycache-dirs} | 0 src/Shell/Utils/{compress.sh => compress} | 0 .../download-full-website} | 29 +- .../get-list-of-emoji-icons-for-linux-shell} | 0 ...ssing-gpg-keys.sh => get-missing-gpg-keys} | 0 src/Shell/Utils/install-base-flask-libs | 11 + .../profile-backup} | 0 ...hash-extractor.sh => quick-hash-extractor} | 2 +- .../{system-admin.sh => Utils/system-admin} | 2 +- .../{system-info.sh => Utils/system-info} | 0 .../xbox-controller} | 0 src/Shell/Utils/yt-cli | 200 ++++++++++ src/Shell/{Utils => }/get-mynoise-src.sh | 0 .../{Utils => }/marathon-game-launcher.sh | 0 src/Shell/{Utils => }/sound-fix-ubuntu.sh | 0 21 files changed, 826 insertions(+), 317 deletions(-) create mode 100755 src/Python/Scripts/GTK/edit-path delete mode 100755 src/Python/Scripts/GTK/edit-path/__main__.py delete mode 100644 src/Python/Scripts/GTK/edit-path/main.glade rename src/Shell/Utils/{a-z-folder-maker.sh => a-z-folder-maker} (100%) create mode 100755 src/Shell/Utils/ani-cli rename src/Shell/Utils/{clean-start-menu.sh => clean-start-menu} (100%) rename src/Shell/Utils/{clear-pycache-dirs.sh => clear-pycache-dirs} (100%) rename src/Shell/Utils/{compress.sh => compress} (100%) rename src/Shell/{download-full-website.sh => Utils/download-full-website} (51%) mode change 100644 => 100755 rename src/Shell/{get-list-of-emoji-icons-for-linux-shell.sh => Utils/get-list-of-emoji-icons-for-linux-shell} (100%) mode change 100644 => 100755 rename src/Shell/Utils/{get-missing-gpg-keys.sh => get-missing-gpg-keys} (100%) create mode 100755 src/Shell/Utils/install-base-flask-libs rename src/Shell/{profile-backup.sh => Utils/profile-backup} (100%) rename src/Shell/Utils/{quick-hash-extractor.sh => quick-hash-extractor} (100%) rename src/Shell/{system-admin.sh => Utils/system-admin} (100%) rename src/Shell/{system-info.sh => Utils/system-info} (100%) rename src/Shell/{xbox-controller.sh => Utils/xbox-controller} (100%) mode change 100644 => 100755 create mode 100755 src/Shell/Utils/yt-cli rename src/Shell/{Utils => }/get-mynoise-src.sh (100%) rename src/Shell/{Utils => }/marathon-game-launcher.sh (100%) rename src/Shell/{Utils => }/sound-fix-ubuntu.sh (100%) diff --git a/src/Python/Scripts/GTK/edit-path b/src/Python/Scripts/GTK/edit-path new file mode 100755 index 0000000..f58b7d8 --- /dev/null +++ b/src/Python/Scripts/GTK/edit-path @@ -0,0 +1,213 @@ +#!/usr/sbin/python + +# GTK Imports +import gi, faulthandler, signal +gi.require_version('Gtk', '3.0') + +from gi.repository import Gtk +from gi.repository import GLib + + +# Python Imports +import os, threading, time + +from setproctitle import setproctitle + + + +app_name = "PATH Edit Tool" + + + +def threaded(fn): + def wrapper(*args, **kwargs): + threading.Thread(target=fn, args=args, kwargs=kwargs).start() + return wrapper + + +class Main(Gtk.Window): + def __init__(self): + super(Main, self).__init__() + self._USER_HOME = os.path.expanduser('~') + PREFERED_BASH_PATH = f"{self._USER_HOME}/.bash_paths" + + icon_size = 16 + box = Gtk.Box() + box2 = Gtk.Box() + separator = Gtk.Separator() + self._insert_entry = Gtk.Entry() + self.message_widget = Gtk.Popover.new(separator) + self.message_label = Gtk.Label() + add_button = Gtk.Button.new_from_icon_name("gtk-add", icon_size) + delete_button = Gtk.Button.new_from_icon_name("gtk-delete", icon_size) + save_button = Gtk.Button.new_from_icon_name("gtk-save", icon_size) + + scroll_vw, grid, self.store = self._create_treeview_widget(title="PATHs") + tree_selection = grid.get_selection() + + box2.add(self._insert_entry) + box2.add(add_button) + box2.add(delete_button) + + box.add(separator) + box.add(scroll_vw) + box.add(box2) + box.add(save_button) + + self.message_widget.add(self.message_label) + self.add(box) + self.add(self.message_widget) + + self.message_widget.set_default_widget(self.message_label) + self._insert_entry.set_hexpand(True) + self._insert_entry.set_placeholder_text("Path...") + save_button.set_label("Save") + scroll_vw.set_vexpand(True) + box.set_orientation(1) + box.set_vexpand(True) + self.set_default_size(480, 560) + self.set_title(f"{app_name}") + self.set_icon_name("applications-accessories") + + add_button.connect("clicked", self.add_entry) + delete_button.connect("clicked", self.delete_entry) + save_button.connect("clicked", self.save_enteries) + tree_selection.connect("changed", self._set_selected) + + self.connect("delete-event", Gtk.main_quit) + GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, Gtk.main_quit) + + self.success = "#88cc27" + self.warning = "#ffa800" + self.error = "#ff0000" + self.selected = None + + if os.path.isfile(PREFERED_BASH_PATH): + self.bashrc_path = PREFERED_BASH_PATH + else: + self.bashrc_path = f"{self._USER_HOME}/.bashrc" + + self._load_paths_data() + + self.message_widget.show_all() + self.message_widget.popdown() + box.show_all() + box2.show_all() + self.show_all() + + + + + def add_entry(self, widget): + path = self._insert_entry.get_text().strip() + + if os.path.isdir(path): + self.store.append([path]) + else: + self.display_message(self.warning, "Not a directory!") + + def delete_entry(self, widget): + self.store.remove(self.selected) + + def save_enteries(self, widget): + try: + paths = list() + iter = self.store.get_iter_first() + while iter != None: + pth = self.store.get_value(iter, 0) + pth = pth.replace(self._USER_HOME, "$HOME") + paths.append(pth) + iter = self.store.iter_next(iter) + + + toExport = "export PATH=\"" + ':'.join(paths) + "\"\n\n" + file = open(self.bashrc_path, mode='r') + for line in file: + if "export PATH=" in line: + continue + else: + toExport += line + + file.close() + file = open(self.bashrc_path, mode='w') + file.write(toExport) + file.close() + self.display_message(self.success, "Successfully saved file!") + except Exception as e: + self.display_message(self.error, "Opening/Writing to file failed!") + print("Opening/Writing to file failed with the following:\n\n") + print(e) + + + def _set_selected(self, user_data): + selected = user_data.get_selected()[1] + if selected: + self.selected = selected + + def _load_paths_data(self): + PATH_str = os.getenv("PATH") + + # If path exists in bashrc replace default selection... + file = open(self.bashrc_path, mode='r') + for line in file: + if "export PATH=" in line: + part = line.replace("export PATH=", "") + cleaned = part.replace("\"", "") + PATH_str = cleaned.strip() + + # Split string into list/tuple and add parts to store + paths = PATH_str.split(":") + for path in paths: + self.store.append([path]) + + + + + def display_message(self, type, text): + markup = f"{text}" + self.message_label.set_markup(markup) + self.message_widget.popup() + self.hide_message_timed() + + @threaded + def hide_message_timed(self): + time.sleep(3) + GLib.idle_add(self.message_widget.popdown) + + + + + def _create_treeview_widget(self, title = "Not Set"): + scroll = Gtk.ScrolledWindow() + grid = Gtk.TreeView() + store = Gtk.ListStore(str) + column = Gtk.TreeViewColumn(title) + name = Gtk.CellRendererText() + selec = grid.get_selection() + + grid.set_model(store) + selec.set_mode(2) + + column.pack_start(name, True) + column.add_attribute(name, "text", 0) + column.set_expand(False) + + grid.append_column(column) + grid.set_search_column(0) + grid.set_headers_visible(True) + grid.set_enable_tree_lines(False) + + grid.show_all() + scroll.add(grid) + grid.columns_autosize() + return scroll, grid, store + + + + +if __name__ == '__main__': + faulthandler.enable() # For better debug info + setproctitle(f"{app_name}") + + main = Main() + Gtk.main() diff --git a/src/Python/Scripts/GTK/edit-path/__main__.py b/src/Python/Scripts/GTK/edit-path/__main__.py deleted file mode 100755 index 7085258..0000000 --- a/src/Python/Scripts/GTK/edit-path/__main__.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/python3 - -# GTK Imports -import gi, faulthandler, signal -gi.require_version('Gtk', '3.0') - -from gi.repository import Gtk as gtk -from gi.repository import GLib - - -# Python Imports -import os, threading, time - -from setproctitle import setproctitle - - -def threaded(fn): - def wrapper(*args, **kwargs): - threading.Thread(target=fn, args=args, kwargs=kwargs).start() - - return wrapper - - - -class Main: - def __init__(self): - setproctitle('PATH Edit Tool') - GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, gtk.main_quit) - faulthandler.enable() # For better debug info - - self.HOME = os.path.expanduser('~') - PREFERED_BASH_PATH = self.HOME + "/" + ".bash_paths" - SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__)) + "/" - GLADE_FILE = "main.glade" - - self.builder = gtk.Builder() - self.builder.add_from_file(SCRIPT_PTH + GLADE_FILE) - self.builder.connect_signals(self) - - self.pathTreeView = self.builder.get_object("pathTreeView") - self.messageWidget = self.builder.get_object("messageWidget") - self.messageLabel = self.builder.get_object("messageLabel") - - self.pathListStore = gtk.ListStore(str) - self.success = "#88cc27" - self.warning = "#ffa800" - self.error = "#ff0000" - self.selected = None - self.bashrcPath = "" - - if os.path.isfile(PREFERED_BASH_PATH): - self.bashrcPath = PREFERED_BASH_PATH - else: - self.bashrcPath = self.HOME + "/" + ".bashrc" - - self.setupTreeview() - self.loadPaths() - - window = self.builder.get_object("Main_Window") - window.connect("delete-event", gtk.main_quit) - window.show() - - - - def addEntry(self, widget): - toAddPathTxt = self.builder.get_object("toAddPathEntry").get_text().strip() - - if os.path.isdir(toAddPathTxt): - self.pathListStore.append([toAddPathTxt]) - else: - self.displayMessage(self.warning, "Not a directory!") - - def deleteEntry(self, widget): - self.pathListStore.remove(self.selected) - - def saveToBashrc(self, widget): - try: - paths = list() - iter = self.pathListStore.get_iter_first() - while iter != None: - pth = self.pathListStore.get_value(iter, 0) - pth = pth.replace(self.HOME, "$HOME") - paths.append(pth) - # paths.append(self.pathListStore.get_value(iter, 0)) - iter = self.pathListStore.iter_next(iter) - - - toExport = "export PATH=\"" + ':'.join(paths) + "\"\n\n" - file = open(self.bashrcPath, mode='r') - for line in file: - if "export PATH=" in line: - continue - else: - toExport += line - - file.close() - file = open(self.bashrcPath, mode='w') - file.write(toExport) - file.close() - self.displayMessage(self.success, "Successfully saved file!") - except Exception as e: - self.displayMessage(self.error, "Opening/Writing to file failed!") - print("Opening/Writing to file failed with the following:\n\n") - print(e) - - - def setSelected(self, user_data): - selected = user_data.get_selected()[1] - if selected: - self.selected = selected - - def loadPaths(self): - pathsStr = os.getenv("PATH") - - # If path exists in bashrc replace default selection... - file = open(self.bashrcPath, mode='r') - for line in file: - if "export PATH=" in line: - part = line.replace("export PATH=", "") - cleaned = part.replace("\"", "") - pathsStr = cleaned.strip() - - # Split string into list/tuple and add parts to store - paths = pathsStr.split(":") - for path in paths: - self.pathListStore.append([path]) - - - def setupTreeview(self): - renderer = gtk.CellRendererText() - pathColumn = gtk.TreeViewColumn(title="Paths", cell_renderer=renderer, text=0) - self.pathTreeView.append_column(pathColumn) - self.pathTreeView.set_model(self.pathListStore) - - - def displayMessage(self, type, text): - markup = "" + text + "" - self.messageLabel.set_markup(markup) - self.messageWidget.popup() - self.hideMessageTimed() - - @threaded - def hideMessageTimed(self): - time.sleep(3) - GLib.idle_add(self.messageWidget.popdown) - - - -if __name__ == '__main__': - main = Main() - gtk.main() diff --git a/src/Python/Scripts/GTK/edit-path/main.glade b/src/Python/Scripts/GTK/edit-path/main.glade deleted file mode 100644 index 9853404..0000000 --- a/src/Python/Scripts/GTK/edit-path/main.glade +++ /dev/null @@ -1,162 +0,0 @@ - - - - - - True - False - gtk-delete - - - True - False - gtk-add - - - False - Edit PATH App - center - 480 - 560 - applications-accessories - center - - - - - - True - False - vertical - - - True - False - - - False - True - 0 - - - - - True - True - in - - - True - False - - - True - True - - - - - - - - - - - - True - True - 1 - - - - - True - False - - - True - True - Path... - - - True - True - 0 - - - - - True - True - True - Add path... - plusImage - True - - - - False - True - 1 - - - - - True - True - True - Delete... - delImage - True - - - - False - True - 2 - - - - - False - True - 2 - - - - - gtk-save - True - True - True - Save... - True - True - - - - False - True - 3 - - - - - - - 320 - False - separator1 - bottom - - - True - False - center - - - - - - - diff --git a/src/Shell/Utils/a-z-folder-maker.sh b/src/Shell/Utils/a-z-folder-maker similarity index 100% rename from src/Shell/Utils/a-z-folder-maker.sh rename to src/Shell/Utils/a-z-folder-maker diff --git a/src/Shell/Utils/ani-cli b/src/Shell/Utils/ani-cli new file mode 100755 index 0000000..c68f9ac --- /dev/null +++ b/src/Shell/Utils/ani-cli @@ -0,0 +1,373 @@ +#!/bin/sh + +# dependencies: grep sed curl video_player +# video_player ( needs to be able to play urls ) +player_fn="mpv" + +prog="ani-cli" +logfile="${XDG_CACHE_HOME:-$HOME/.cache}/ani-hsts" + +c_red="\033[1;31m" +c_green="\033[1;32m" +c_yellow="\033[1;33m" +c_blue="\033[1;34m" +c_magenta="\033[1;35m" +c_cyan="\033[1;36m" +c_reset="\033[0m" + + +help_text () { + while IFS= read line; do + printf "%s\n" "$line" + done <<-EOF + USAGE: $prog + -h show this help text + -d download episode + -H continue where you left off + -q set video quality (best/worst/360/480/720/..) + EOF +} + + +die () { + printf "$c_red%s$c_reset\n" "$*" >&2 + exit 1 +} + +err () { + printf "$c_red%s$c_reset\n" "$*" >&2 +} + +search_anime () { + # get anime name along with its id + search=$(printf '%s' "$1" | tr ' ' '-' ) + titlepattern='&2 + quality=best + video_quality=$(printf '%s' "$available_qualities" | tail -n 1) + fi + printf '%s' "$video_quality" + ;; + esac + +} + +get_links () { + embedded_video_url="$1" + video_url=$(curl -s "$embedded_video_url" | + sed -n -E ' + /^[[:space:]]*sources:/{ + s/.*(https[^'\'']*).*/\1/p + q + } + ') + + video_quality=$(get_video_quality "$embedded_video_url" "$video_url") + + # Replace the video with highest quality video + printf '%s' "$video_url" | sed -n -E "s/(.*)\.m3u8/\1.$video_quality.m3u8/p" +} + +dep_ch () { + for dep; do + if ! command -v "$dep" >/dev/null ; then + die "Program \"$dep\" not found. Please install it." + fi + done +} + +# get query +get_search_query () { + if [ -z "$*" ]; then + printf "Search Anime: " + read -r query + else + query=$* + fi +} + +# create history file +[ -f "$logfile" ] || : > "$logfile" + +##################### +## Anime selection ## +##################### + +anime_selection () { + search_results=$* + menu_format_string='[%d] %s\n' + menu_format_string_c1="$c_blue[$c_cyan%d$c_blue] $c_reset%s\n" + menu_format_string_c2="$c_blue[$c_cyan%d$c_blue] $c_yellow%s$c_reset\n" + + count=1 + while read anime_id; do + # alternating colors for menu + [ $((count % 2)) -eq 0 ] && + menu_format_string=$menu_format_string_c1 || + menu_format_string=$menu_format_string_c2 + + printf "$menu_format_string" "$count" "$anime_id" + count=$((count+1)) + done <<-EOF + $search_results + EOF + + # User input + printf "$c_blue%s$c_green" "Enter number: " + read choice + printf "$c_reset" + + # Check if input is a number + [ "$choice" -eq "$choice" ] 2>/dev/null || die "Invalid number entered" + + # Select respective anime_id + count=1 + while read anime_id; do + if [ $count -eq $choice ]; then + selection_id=$anime_id + break + fi + count=$((count+1)) + done <<-EOF + $search_results + EOF + + [ -z "$selection_id" ] && die "Invalid number entered" + + read last_ep_number <<-EOF + $(search_eps "$selection_id") + EOF +} + +################## +## Ep selection ## +################## + +episode_selection () { + [ $is_download -eq 1 ] && + printf "Range of episodes can be specified: start_number end_number\n" + + printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number + read ep_choice_start ep_choice_end + printf "$c_reset" + +} + +open_episode () { + anime_id=$1 + episode=$2 + + # Cool way of clearing screen + tput reset + if [ $episode -lt 1 ] || [ $episode -gt $last_ep_number ]; then + err "Episode out of range" + printf "${c_blue}Choose episode $c_cyan[1-%d]$c_reset:$c_green " $last_ep_number + read episode + printf "$c_reset" + fi + + printf "Getting data for episode %d\n" $episode + + embedded_video_url=$(get_embedded_video_link "$anime_id" "$episode") + video_url=$(get_links "$embedded_video_url") + + case $video_url in + *streamtape*) + # If direct download not available then scrape streamtape.com + BROWSER=${BROWSER:-firefox} + printf "scraping streamtape.com\n" + video_url=$(curl -s "$video_url" | sed -n -E ' + /^