mangadex-sync 2.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ """
2
+ MangaDex Sync
3
+ Export and import your MangaDex library to/from MyAnimeList and AniList.
4
+ """
5
+
6
+ __version__ = "2.0.1"
7
+ __author__ = "Spider2742"
8
+
9
+ from .app import app # noqa: F401
10
+
11
+
12
+ def _webview_fix_hint():
13
+ """Return a distro/OS-aware fix message for missing pywebview GUI backends."""
14
+ import platform
15
+
16
+ system = platform.system()
17
+
18
+ if system == "Windows":
19
+ return (
20
+ " On Windows, install Qt support:\n"
21
+ " pip install PyQt6 qtpy\n"
22
+ " Or reinstall pywebview:\n"
23
+ " pip install --upgrade pywebview"
24
+ )
25
+
26
+ if system == "Darwin":
27
+ return (
28
+ " On macOS, pywebview uses WebKit which should work out of the box.\n"
29
+ " Try upgrading pywebview:\n"
30
+ " pip install --upgrade pywebview\n"
31
+ " If that doesn't help, install Qt as a fallback:\n"
32
+ " brew install pyqt (requires Homebrew: brew.sh)\n"
33
+ " pip install PyQt6 qtpy"
34
+ )
35
+
36
+ if system == "Linux":
37
+ distro_id = ""
38
+ distro_like = ""
39
+ try:
40
+ info = platform.freedesktop_os_release() # Python 3.10+
41
+ distro_id = info.get("ID", "").lower()
42
+ distro_like = info.get("ID_LIKE", "").lower()
43
+ except Exception:
44
+ pass
45
+
46
+ combined = f"{distro_id} {distro_like}"
47
+ is_debian = any(x in combined for x in ("debian", "ubuntu", "mint", "pop", "elementary", "kali", "zorin", "raspbian"))
48
+ is_fedora = any(x in combined for x in ("fedora", "rhel", "centos", "rocky", "alma", "nobara"))
49
+ is_arch = any(x in combined for x in ("arch", "manjaro", "endeavour", "garuda", "artix"))
50
+ is_suse = any(x in combined for x in ("suse", "opensuse"))
51
+ is_void = "void" in combined
52
+
53
+ if is_debian:
54
+ gtk_hint = " sudo apt install python3-gi python3-gi-cairo gir1.2-gtk-3.0 gir1.2-webkit2-4.0"
55
+ elif is_fedora:
56
+ gtk_hint = " sudo dnf install python3-gobject python3-gobject-base webkit2gtk4.1"
57
+ elif is_arch:
58
+ gtk_hint = " sudo pacman -S python-gobject webkit2gtk-4.1"
59
+ elif is_suse:
60
+ gtk_hint = " sudo zypper install python3-gobject python3-gobject-Gdk typelib-1_0-WebKit2-4_1"
61
+ elif is_void:
62
+ gtk_hint = " sudo xbps-install python3-gobject webkit2gtk"
63
+ else:
64
+ gtk_hint = " Install python3-gobject and webkit2gtk via your package manager"
65
+
66
+ return (
67
+ f" Fix with GTK (recommended):\n"
68
+ f"{gtk_hint}\n\n"
69
+ f" Or use Qt instead:\n"
70
+ f" pip install PyQt6 qtpy"
71
+ )
72
+
73
+ return (
74
+ " Try installing Qt support:\n"
75
+ " pip install PyQt6 qtpy\n"
76
+ " Or GTK via your system package manager (python3-gobject + webkit2gtk)"
77
+ )
78
+
79
+
80
+ def main():
81
+ """CLI entry point: runs the Flask app with optional pywebview."""
82
+ import sys
83
+ import time
84
+ import webbrowser
85
+ import threading
86
+ import requests as req_lib
87
+
88
+ missing = []
89
+ for pkg in ["requests", "pandas", "openpyxl", "flask"]:
90
+ try:
91
+ __import__(pkg)
92
+ except ImportError:
93
+ missing.append(pkg)
94
+ if missing:
95
+ print(f"Missing packages. Run: pip install {' '.join(missing)}")
96
+ sys.exit(1)
97
+
98
+ PORT = 7337
99
+
100
+ flask_thread = threading.Thread(
101
+ target=lambda: app.run(host="127.0.0.1", port=PORT, debug=False, threaded=True),
102
+ daemon=True,
103
+ )
104
+ flask_thread.start()
105
+
106
+ for _ in range(20):
107
+ try:
108
+ req_lib.get(f"http://127.0.0.1:{PORT}/", timeout=1)
109
+ break
110
+ except Exception:
111
+ time.sleep(0.3)
112
+
113
+ try:
114
+ import webview
115
+
116
+ print(f"\n MangaDex Sync v{__version__}")
117
+ print(f" Opening native window...")
118
+ print(f" (Also accessible at http://localhost:{PORT})\n")
119
+ webview.create_window(
120
+ title=f"MangaDex Sync v{__version__}",
121
+ url=f"http://127.0.0.1:{PORT}",
122
+ width=1200,
123
+ height=800,
124
+ min_size=(900, 600),
125
+ background_color="#0c0e14",
126
+ )
127
+ import os, sys
128
+ with open(os.devnull, 'w') as devnull:
129
+ old_stderr = sys.stderr
130
+ sys.stderr = devnull
131
+ try:
132
+ webview.start()
133
+ finally:
134
+ sys.stderr = old_stderr
135
+
136
+ except ImportError:
137
+ print(f"\n pywebview not installed - opening in browser instead.")
138
+ print(f" To get the native window: pip install 'mangadex-sync[desktop]'\n")
139
+ print(f" MangaDex Sync v{__version__}")
140
+ print(f" Open in browser: http://localhost:{PORT}\n")
141
+ webbrowser.open(f"http://localhost:{PORT}")
142
+ try:
143
+ while True:
144
+ time.sleep(1)
145
+ except KeyboardInterrupt:
146
+ print("\nShutting down.")
147
+
148
+ except Exception:
149
+ print(f"\n pywebview is installed but couldn't find a GUI backend.")
150
+ print(f"\n{_webview_fix_hint()}")
151
+ print(f"\n Falling back to browser...")
152
+ print(f" Open in browser: http://localhost:{PORT}\n")
153
+ webbrowser.open(f"http://localhost:{PORT}")
154
+ try:
155
+ while True:
156
+ time.sleep(1)
157
+ except KeyboardInterrupt:
158
+ print("\nShutting down.")