SF Vip plejer

Učlanjen(a)
18.04.2023
Poruka
78
@salezli Is it possible to add something like global default proxy? I mean by that 2 things.
1. If I add some new playlist the default proxy will be auto added and I don't need to type it there each time again and again for every single added playlist.

HereEvo jednostavne Python skripte za to.

Add a global user proxy for all users / Dodajte globalni korisnički proksi za sve korisnike:
Kod:
python -m sfvip_user_proxy http://127.0.0.1:8888

Remove it / Uklonite ga:
Kod:
python -m sfvip_user_proxy

Kod:
# Use Python 3.11 with no dependencies

# set a global user proxy:
# python -m sfvip_user_proxy http://127.0.0.1:8888

# remove the global user proxy:
# python -m sfvip_puser_proxy

import argparse
import json
import logging
import re
import winreg
from contextlib import suppress
from pathlib import Path
from types import SimpleNamespace

logging.basicConfig(level=logging.INFO, format="%(message)s")


def reg_value_by_name(hkey: int, path: str, name: str) -> str:
    with suppress(WindowsError, FileNotFoundError), winreg.OpenKey(hkey, path) as k:
        value = winreg.QueryValueEx(k, name)[0]
        return value
    return ""


class _JsonTrailingCommas:
    _object = re.compile(r'(,)\s*}(?=([^"\\]*(\\.|"([^"\\]*\\.)*[^"\\]*"))*[^"]*$)')
    _array = re.compile(r'(,)\s*\](?=([^"\\]*(\\.|"([^"\\]*\\.)*[^"\\]*"))*[^"]*$)')

    @staticmethod
    def remove(json_str: str) -> str:
        json_str = _JsonTrailingCommas._object.sub("}", json_str)
        return _JsonTrailingCommas._array.sub("]", json_str)


class User(SimpleNamespace):
    _playlist_ext = ".m3u", ".m3u8"

    def __init__(self, **kwargs: str) -> None:
        # pylint: disable=invalid-name
        self.Name: str
        self.Address: str
        self.HttpProxy: str
        super().__init__(**kwargs)

    def is_playlist(self) -> bool:
        path = Path(self.Address)
        return path.suffix in User._playlist_ext or path.is_file()


class Users:
    _from_registry = winreg.HKEY_CURRENT_USER, r"SOFTWARE\SFVIP", "ConfigDir"
    _filename = "Database.json"
    _encoding = "utf-8"

    class _Encoder(json.JSONEncoder):
        def default(self, o: User) -> dict[str, str]:
            return o.__dict__

    def __init__(self) -> None:
        self._users: list[User] = []
        self._database = Path(reg_value_by_name(*Users._from_registry)) / Users._filename
        logging.info("Users database %s", self._database if self._database.is_file() else "NOT found")

    def _load(self) -> None:
        with self._database.open("r", encoding=Users._encoding) as f:
            json_str = _JsonTrailingCommas.remove(f.read())
            self._users = json.loads(json_str, object_hook=lambda dct: User(**dct))

    def _save(self) -> None:
        with self._database.open("w", encoding=Users._encoding) as f:
            json.dump(self._users, f, cls=Users._Encoder, indent=2, separators=(",", ":"))

    def set_user_proxy(self, user_proxy: str) -> None:
        if self._database.is_file():
            self._load()
            user_proxy = user_proxy.strip()
            users = [user for user in self._users if not user.is_playlist()]
            logging.info("%s global user proxy %s", "Set" if user_proxy else "Remove", user_proxy)
            logging.info("For %s", ", ".join(user.Name for user in users) if users else "No users")
            for user in users:
                user.HttpProxy = user_proxy
            self._save()


if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("url", nargs="?", default="", help="global user proxy url")
    Users().set_user_proxy(parser.parse_args().url)
 
Poslednja izmena:
Učlanjen(a)
24.08.2022
Poruka
53
HereEvo jednostavne Python skripte za to.
Probao sam skriptu, ali dobio sam ovu grešku:

"
Traceback (most recent call last):
File "Python_Portable\SFVIPproxy.py", line 53, in <module>
class Users:
File "Python_Portable\SFVIPproxy.py", line 58, in Users
class _Encoder(json.JSONEncoder):
File "Python_Portable\SFVIPproxy.py", line 59, in _Encoder
def default(self, o: User) -> dict[str, str]:
TypeError: 'type' object is not subscriptable "
 
Učlanjen(a)
18.04.2023
Poruka
78
Probao sam skriptu, ali dobio sam ovu grešku:

def default(self, o: User) -> dict[str, str]:
TypeError: 'type' object is not subscriptable "
Potreban vam je Python >= 3.11 (možda je >= 3.9 dovoljno) jer koristim savete za kucanje koji su dostupni samo u novijim verzijama Pythona.
 
Poslednja izmena:
Učlanjen(a)
24.08.2022
Poruka
53
Probao v3.11.4 i dobio ovu grešku:

"
C:\Users\Marino\Desktop\Softwares\SFVIP Player\sfvip Proxifier>python-3.11.4-embed-amd64\python.exe python-3.11.4-embed-amd64\SFVIPproxy.py
File "C:\Users\Marino\Desktop\Softwares\SFVIP Player\sfvip Proxifier\python-3.11.4-embed-amd64\SFVIPproxy.py", line 5
python -m sfvip_user_proxy http://47.88.62.42:80
^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax "
 
Učlanjen(a)
18.04.2023
Poruka
78
Tried v3.11.4 and got this error:

"
C:\Users\Marino\Desktop\Softwares\SFVIP Player\sfvip Proxifier>python-3.11.4-embed-amd64\python.exe python-3.11.4-embed-amd64\SFVIPproxy.py
File "C:\Users\Marino\Desktop\Softwares\SFVIP Player\sfvip Proxifier\python-3.11.4-embed-amd64\SFVIPproxy.py", line 5
python -m sfvip_user_proxy http://47.88.62.42:80
^^^^^^^^^^^^^^^^
SyntaxError: invalid syntax "
Izgleda da ste dekomentirali nešto u kodu. Trebalo bi da promenite globalni korisnički proksi tako što ćete dati kao argument Python skripti.
 
Učlanjen(a)
18.04.2023
Poruka
78
Sastavio sam ga sa Nuitka tako da je lakši za korišćenje:

sfvip_user_proxy 0.1
Dodajte globalni korisnički proksi za sve korisnike / Add a global user proxy for all users

x64 - x86 - Github

Dodajte ⭐ ako vam odgovara / Add a ⭐ if you like it
 
Učlanjen(a)
18.04.2023
Poruka
78
SfvipUserProxy 0.2
Dodajte globalni korisnički proksi za sve korisnike / Add a global user proxy for all users

x64 - x86 - Github

Dodajte ⭐ ako vam odgovara / Add a ⭐ if you like it
 
Učlanjen(a)
18.04.2023
Poruka
78
Add a global user proxy for all users / Dodajte globalni korisnički proksi za sve korisnike:
Kod:
SfvipUserProxy http://127.0.0.1:8888

Remove it / Uklonite ga:
Kod:
SfvipUserProxy --remove
 
Učlanjen(a)
18.04.2023
Poruka
78
SfvipUserProxy 0.3

Dodajte ili uklonite globalni korisnički proksi za sve korisnike / Add or remove a global user proxy for all users
SfvipUserProxy http://127.0.0.1:8888 or SfvipUserProxy --remove

x64 - x86 - Github

Dodajte ⭐ ako vam odgovara / Add a ⭐ if you like it
 
Poslednja izmena:
Natrag
Top