Skip to content

Commit

Permalink
Ability to hide/exclude certain elements from a per-stream summary (#90)
Browse files Browse the repository at this point in the history
- Move text formatting into new TextManager, account for embed customization (anonymizing)
- New anonymize settings to hide/exclude certain elements from per-stream and overview summary
- Update README with new env vars
- Update Unraid template
  • Loading branch information
nwithan8 authored Jun 3, 2023
1 parent 165813a commit 9aaadfb
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 97 deletions.
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ You will need to set the following environment variables:
| TC_TERMINATE_MESSAGE | No | Message sent to users when a stream is killed | "Your stream has ended." |
| TC_SERVER_NAME | No | Name of the Plex server.<br/>Will use provided; if not provided, will use "Plex"; if provided string is empty, will attempt to extract Plex Media Server name via Tautulli. | "Plex" |
| TC_USE_24_HOUR_TIME | No | Whether to display times in 24-hour time | "False" |
| TC_ANON_USERS | No | Whether to hide usernames in the streams view | "False" |
| TC_HIDE_USERNAMES | No | Whether to hide usernames in the streams view | "False" |
| TC_HIDE_PLATFORMS | No | Whether to hide platforms in the streams view | "False" |
| TC_HIDE_PLAYER_NAMES | No | Whether to hide player names in the streams view | "False" |
| TC_HIDE_QUALITY | No | Whether to hide quality profiles in the streams view | "False" |
| TC_HIDE_BANDWIDTH | No | Whether to hide bandwidth in the streams view | "False" |
| TC_HIDE_TRANSCODE | No | Whether to hide transcoding statuses in the streams view | "False" |
| TC_HIDE_PROGRESS | No | Whether to hide stream progress in the streams view | "False" |
| TC_HIDE_ETA | No | Whether to hide stream ETAs in the streams view | "False" | | | | |
| TC_VC_STATS_CATEGORY_NAME | No | Name of the stats voice channel category | "Tautulli Stats" |
| TC_VC_STREAM_COUNT | No | Whether to display current stream count in a voice channel | "False" |
| TC_VC_TRANSCODE_COUNT | No | Whether to display current transcode count in a voice channel | "False" |
Expand Down
9 changes: 9 additions & 0 deletions config.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ Tautulli:
TVEpisodeCount: true
MusicArtistCount: true
MusicTrackCount: true
Anonymize:
HideUsernames: false
HidePlayerNames: false
HidePlatforms: false
HideQuality: false
HideBandwidth: false
HideTranscode: false
HideProgress: false
HideETA: false

Discord:
Connection:
Expand Down
79 changes: 73 additions & 6 deletions modules/config_parser.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import json
import os
from typing import List
from typing import List, Dict, Any

import confuse
import yaml

from modules import statics
import modules.logs as logging
from modules import statics
from modules.text_manager import TextManager


def _extract_bool(value):
Expand Down Expand Up @@ -90,7 +91,7 @@ def refresh_interval(self) -> int:
def server_name(self) -> str:
return self._customization._get_value(key='ServerName', default="Plex",
env_name_override="TC_SERVER_NAME")

@property
def anonymous_users(self) -> bool:
value = self._customization._get_value(key='AnonymousUsers', default=False,
Expand Down Expand Up @@ -213,7 +214,7 @@ def show_music_track_count(self) -> bool:
return _extract_bool(value)

@property
def voice_channel_settings(self):
def voice_channel_settings(self) -> Dict[str, Any]:
return {
statics.KEY_STATS_CATEGORY_NAME: self.stats_voice_channel_category_name,
statics.KEY_COUNT: self.display_stream_count,
Expand All @@ -235,14 +236,79 @@ def voice_channel_settings(self):
@property
def any_live_stats_channels_enabled(self) -> bool:
keys = [statics.KEY_COUNT, statics.KEY_TRANSCODE_COUNT, statics.KEY_BANDWIDTH,
statics.KEY_LAN_BANDWIDTH, statics.KEY_REMOTE_BANDWIDTH, statics.KEY_PLEX_STATUS]
statics.KEY_LAN_BANDWIDTH, statics.KEY_REMOTE_BANDWIDTH, statics.KEY_PLEX_STATUS]
return any([self.voice_channel_settings.get(key, False) for key in keys])

@property
def any_library_stats_channels_enabled(self) -> bool:
keys = [statics.KEY_STATS]
return any([self.voice_channel_settings.get(key, False) for key in keys])

@property
def _anonymize_rules(self) -> ConfigSection:
return self._customization._get_subsection(key="Anonymize")

@property
def _anonymize_hide_usernames(self) -> bool:
value = self._anonymize_rules._get_value(key="HideUsernames", default=False,
env_name_override="TC_HIDE_USERNAMES")
return _extract_bool(value)

@property
def _anonymize_hide_platforms(self) -> bool:
value = self._anonymize_rules._get_value(key="HidePlatforms", default=False,
env_name_override="TC_HIDE_PLATFORMS")
return _extract_bool(value)

@property
def _anonymize_hide_player_names(self) -> str:
return self._anonymize_rules._get_value(key="HidePlayerNames", default=False,
env_name_override="TC_HIDE_PLAYER_NAMES")

@property
def _anonymize_hide_quality(self) -> bool:
value = self._anonymize_rules._get_value(key="HideQuality", default=False,
env_name_override="TC_HIDE_QUALITY")
return _extract_bool(value)

@property
def _anonymize_hide_bandwidth(self) -> bool:
value = self._anonymize_rules._get_value(key="HideBandwidth", default=False,
env_name_override="TC_HIDE_BANDWIDTH")
return _extract_bool(value)

@property
def _anonymize_hide_transcode_decision(self) -> bool:
value = self._anonymize_rules._get_value(key="HideTranscode", default=False,
env_name_override="TC_HIDE_TRANSCODE")
return _extract_bool(value)

@property
def _anonymize_hide_progress(self) -> bool:
value = self._anonymize_rules._get_value(key="HideProgress", default=False,
env_name_override="TC_HIDE_PROGRESS")
return _extract_bool(value)

@property
def _anonymize_hide_eta(self) -> bool:
value = self._anonymize_rules._get_value(key="HideETA", default=False,
env_name_override="TC_HIDE_ETA")
return _extract_bool(value)

@property
def text_manager(self) -> TextManager:
anonymous_rules = {
statics.KEY_HIDE_USERNAMES: self._anonymize_hide_usernames,
statics.KEY_HIDE_PLAYER_NAMES: self._anonymize_hide_player_names,
statics.KEY_HIDE_PLATFORMS: self._anonymize_hide_platforms,
statics.KEY_HIDE_QUALITY: self._anonymize_hide_quality,
statics.KEY_HIDE_BANDWIDTH: self._anonymize_hide_bandwidth,
statics.KEY_HIDE_TRANSCODING: self._anonymize_hide_transcode_decision,
statics.KEY_HIDE_PROGRESS: self._anonymize_hide_progress,
statics.KEY_HIDE_ETA: self._anonymize_hide_eta,
}
return TextManager(anon_rules=anonymous_rules)


class DiscordConfig(ConfigSection):
def __init__(self, data, pull_from_env: bool = True):
Expand Down Expand Up @@ -270,7 +336,8 @@ def admin_ids(self) -> List[str]:

@property
def channel_name(self) -> str:
return self._connection._get_value(key="ChannelName", default="tauticord", env_name_override="TC_DISCORD_CHANNEL_NAME")
return self._connection._get_value(key="ChannelName", default="tauticord",
env_name_override="TC_DISCORD_CHANNEL_NAME")

@property
def _customization(self) -> ConfigSection:
Expand Down
23 changes: 12 additions & 11 deletions modules/statics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@
STANDARD_EMOJIS_FOLDER = "resources/emojis/standard"
NITRO_EMOJIS_FOLDER = "resources/emojis/nitro"

sessions_message = """{stream_count} {word}"""
transcodes_message = """{transcode_count} {word}"""
bandwidth_message = """{emoji} {bandwidth}"""
lan_bandwidth_message = """({emoji} {bandwidth})"""

session_title_message = """{emoji} | {icon} {media_type_icon} *{title}*"""
session_user_message = """{emoji} **{username}**"""
session_player_message = """{emoji} **{product}** ({player})"""
session_details_message = """{emoji} **{quality_profile}** ({bandwidth}){transcoding}"""
session_progress_message = """{emoji} **{progress}** (ETA: {eta})"""

voice_channel_order = {
'count': 1,
'transcodes': 2,
Expand All @@ -40,4 +29,16 @@
KEY_SHOW_MUSIC_ARTISTS = "show_music_artists"
KEY_SHOW_MUSIC_TRACKS = "show_music_tracks"

KEY_ANONYMOUS_SETTINGS = "anonymous_settings"
KEY_HIDE_USERNAMES = "hide_usernames"
KEY_HIDE_PLATFORMS = "hide_platforms"
KEY_HIDE_PLAYER_NAMES = "anonymize_players"
KEY_HIDE_QUALITY = "hide_quality"
KEY_HIDE_BANDWIDTH = "hide_bandwidth"
KEY_HIDE_TRANSCODING = "hide_transcoding"
KEY_HIDE_PROGRESS = "hide_progress"
KEY_HIDE_ETA = "hide_eta"
KEY_DISABLE_TERMINATION = "hide_termination"


MAX_STREAM_COUNT = 36
Loading

0 comments on commit 9aaadfb

Please sign in to comment.