Stash Explorer

Open galleries/images in Windows Explorer. Requires included stashExplorer.py to be running locally.

יוצר
stashtastic
התקנות יומיות
0
סה"כ התקנות
1
דירוגים
0 0 0
גרסה
2024-09-13
נוצר
05-10-2024
עודכן
05-10-2024
רישיון
MIT
חל על

Open images/galleries in Windows Explorer from Stash https://github.com/stashapp/stash/

  • Adds a folder icon to the top-left of gallery/image pages.
  • Clicking the icon will open Windows Explorer, automatically selecting the file.

NOTE: Required Python Script

UserScripts do not have the ability to open Windows Explorer.

This script requires a separate Python script is running on your local host, in order to open Windows Explorer.

The Python script will open a port on your computer (port 9998). The Python script code is included in the UserScript comments, and below:

from http.server import BaseHTTPRequestHandler, HTTPServer
from urllib.parse import urlparse
from urllib.parse import parse_qs
import subprocess

class StashExplorerHandler(BaseHTTPRequestHandler):
    def o(self, text):
        text = str(text)
        print(f"[StashExplorer.py] {text}")
        output = text + "\n\n"
        self.wfile.write(output.encode("utf-8"))

    def do_GET(self):
        """handle GET requests."""
        self.send_response(200)
        self.send_header("Content-type", "text/html")
        self.end_headers()

        # Parse path
        parsed_url = urlparse(self.path)
        params = parse_qs(parsed_url.query)

        if "path" not in params:
            self.o(f"Could not find 'path' in params: {params}")
            return

        path = params["path"][0]
        path = path.replace('/', '\\')

        # Sanitize
        if '"' in path:
            path = path.replace('"', '\\"')

        command = f'explorer /select,"{path}"'
        self.o(f"Opening: {command}")
        subprocess.Popen(command)


def run(server_class=HTTPServer, handler_class=StashExplorerHandler):
    server_address = ('', 9998)
    httpd = server_class(server_address, handler_class)
    httpd.serve_forever()

run()