Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to standard units #5

Merged
merged 3 commits into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,23 @@

# Units to be used for all speed values
# Options (smallest to largest):
# - bit = bit/s, Bits per second
# - b = B/s, Bytes per second
# - kbit = Kbit/s, Kilobits per second
# - kb = KB/s, Kilobytes per second
# - mbit = Mbit/s, Megabits per second (default)
# - mb = MB/s, Megabytes per second
units: mbit
# - bit = bit/s, bits per second
# - B = B/s, bytes per second
# - Kbit = Kbit/s, kilobits per second
# - Kibit = Kibit/s, kibibits per second
# - KB = KB/s, kilobytes per second
# - KiB = KiB/s, kibibytes per second
# - Mbit = Mbit/s, megabits per second
# - Mibit = Mibit/s, mebibits per second
# - MB = MB/s, megabytes per second
# - MiB = MiB/s, mebibytes per second (default)
# - Gbit = Gbit/s, gigabits per second
# - Gibit = Gibit/s, gibibits per second
# - GB = GB/s, gigabytes per second
# - GiB = GiB/s, gibibytes per second
# Full unit names (e.g. kilobyte) can be used as well
itschasa marked this conversation as resolved.
Show resolved Hide resolved
# Note: Capitalization matters for the acronyms above.
units: MiB

# The minimum upload speed allowed on your torrent client.
# Note: Most torrent clients won't allow you to set the upload speed to 0,
Expand Down
31 changes: 26 additions & 5 deletions helpers/bit_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,32 @@

bit_convertion_dict = {
"bit": 1,
"b": 8,
"kbit": 1000,
"kb": 8000,
"mbit": 1000000,
"mb": 8000000,
"B": 8,
"byte": 8,
"Kbit": 1000,
"kilobit": 1000,
"Kibit": 1024,
"kibibit": 1024,
"KB": 8000,
"kilobyte": 8000,
"KiB": 8 * 1024,
"kibibyte": 8 * 1024,
"Mbit": 1000**2,
"megabit": 1000**2,
"Mibit": 1024**2,
"mebibit": 1024**2,
"MB": 8 * 1000**2,
"megabyte": 8 * 1000**2,
"MiB": 8 * 1024**2,
"mebibyte": 8 * 1024**2,
"Gbit": 1000**3,
"gigabit": 1000**3,
"Gibit": 1024**3,
"gibibit": 1024**3,
"GB": 8 * 1000**3,
"gigabyte": 8 * 1000**3,
"GiB": 8 * 1024**3,
"gibibyte": 8 * 1024**3,
}


Expand Down
30 changes: 29 additions & 1 deletion helpers/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,35 @@ class ModulesConfig(YAMLWizard):

@dataclass(frozen=True)
class SpeedrrConfig(YAMLWizard):
units: Literal['bit', 'b', 'kbit', 'kb', 'mbit', 'mb']
units: Literal[
'bit',
'B',
'byte',
'Kbit',
'kilobit',
'Kibit',
'kibibit',
'KB',
'kilobyte',
'KiB',
'kibibyte',
'Mbit',
'megabit',
'Mibit',
'mebibit',
'MB',
'megabyte',
'MiB',
'mebibyte',
'Gbit',
'gigabit',
'Gibit',
'gibibit',
'GB',
'gigabyte',
'GiB',
'gibibyte',
]
min_upload: int
max_upload: int
clients: List[ClientConfig]
Expand Down
14 changes: 7 additions & 7 deletions modules/media_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,13 @@ def __init__(self, config: SpeedrrConfig, server_config: MediaServerConfig, modu


def get_bandwidth(self) -> int:
"Get the current bandwidth usage from the server, in kbit/s."
"Get the current bandwidth usage from the server, in Kbit/s."
raise NotImplementedError("get_bandwidth must be implemented in a subclass")


def set_reduction(self, reduction) -> None:
"Set the upload speed reduction for the server, in config units. Accepts kbit/s as input."
reduction = bit_conv(reduction, "kbit", self._config.units)
"Set the upload speed reduction for the server, in config units. Accepts Kbit/s as input."
reduction = bit_conv(reduction, "Kbit", self._config.units)

old_reduction = self._module.reduction_value_dict.get(self._server_config)

Expand Down Expand Up @@ -154,7 +154,7 @@ def run(self) -> None:

class PlexServer(BaseServer):
def get_bandwidth(self) -> int:
"Get the current bandwidth usage from Plex, in kbit/s."
"Get the current bandwidth usage from Plex, in Kbit/s."

logger.debug(f"{self._logger_prefix} Getting bandwidth")

Expand Down Expand Up @@ -194,7 +194,7 @@ def get_bandwidth(self) -> int:

class TautulliServer(BaseServer):
def get_bandwidth(self) -> int:
"Get the current bandwidth usage from Tautulli, in kbit/s."
"Get the current bandwidth usage from Tautulli, in Kbit/s."

logger.debug(f"{self._logger_prefix} Getting bandwidth")

Expand Down Expand Up @@ -230,7 +230,7 @@ def get_bandwidth(self) -> int:

class JellyfinServer(BaseServer):
def get_bandwidth(self) -> int:
"Get the current bandwidth usage from Jellyfin, in kbit/s."
"Get the current bandwidth usage from Jellyfin, in Kbit/s."

logger.debug(f"{self._logger_prefix} Getting bandwidth")

Expand Down Expand Up @@ -269,5 +269,5 @@ def get_bandwidth(self) -> int:

self.remove_old_paused(session_ids)

return int(round(bit_conv(count, 'bit', 'kbit'), 0))
return int(round(bit_conv(count, 'bit', 'Kbit'), 0))