-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtorrentstat-sync
executable file
·86 lines (66 loc) · 2.67 KB
/
torrentstat-sync
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
#! /usr/bin/env python
# SPDX-FileCopyrightText: 2024 sudorook <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
""" docstring """
import os
import json
from xdg.BaseDirectory import xdg_config_home
from PyQt6.QtCore import QSettings
def get_transmission_stats(path):
"""docstring"""
with open(path, "r", encoding="utf-8") as f:
stats = json.load(f)
return stats
def write_transmission_stats(path, stats):
"""docstring"""
with open(path, "w", encoding="utf-8") as f:
json.dump(stats, f, ensure_ascii=False, indent=4)
def get_qbittorrent_stats(path):
"""docstring"""
settings = QSettings(path)
stats = settings.value("Stats/AllStats")
return stats
def write_qbittorrent_stats(path, stats):
settings = QSettings(path)
settings.setValue("Stats/AllStats", stats)
def update_max_stats(qstats, tstats):
"""docstring"""
if qstats["AlltimeDL"] != tstats["downloaded-bytes"]:
if qstats["AlltimeDL"] < tstats["downloaded-bytes"]:
qstats["AlltimeDL"] = tstats["downloaded-bytes"]
else:
tstats["downloaded-bytes"] = qstats["AlltimeDL"]
if qstats["AlltimeUL"] != tstats["uploaded-bytes"]:
if qstats["AlltimeUL"] < tstats["uploaded-bytes"]:
qstats["AlltimeUL"] = tstats["uploaded-bytes"]
else:
tstats["uploaded-bytes"] = qstats["AlltimeUL"]
return qstats, tstats
if __name__ == "__main__":
QBITTORRENT_STAT_FILE = os.path.join(
xdg_config_home, "qBittorrent/qBittorrent-data.conf"
)
TRANSMISSION_STAT_FILE = os.path.join(
xdg_config_home, "transmission/stats.json"
)
QBITTORRENT_STATS = get_qbittorrent_stats("qBittorrent/qBittorrent-data")
TRANSMISSION_STATS = get_transmission_stats(TRANSMISSION_STAT_FILE)
QBITTORRENT_STATS, TRANSMISSION_STATS = update_max_stats(
QBITTORRENT_STATS, TRANSMISSION_STATS
)
write_qbittorrent_stats("qBittorrent/qBittorrent-data", QBITTORRENT_STATS)
write_transmission_stats(TRANSMISSION_STAT_FILE, TRANSMISSION_STATS)