-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #283 from kozaka-tv/49-tag-manager
49-tag-manager
- Loading branch information
Showing
15 changed files
with
393 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from dataclasses import dataclass | ||
|
||
|
||
@dataclass | ||
class RSPLTag: | ||
name: str | ||
rspl_id: str | ||
icon: str | ||
color: str | ||
user: bool | ||
|
||
|
||
@dataclass | ||
class RSPLTags: | ||
tag_to_download: RSPLTag | ||
tag_downloaded: RSPLTag | ||
tag_loaded: RSPLTag | ||
tag_new_viewer_request: RSPLTag | ||
tag_raider_request: RSPLTag | ||
tag_vip_viewer_request: RSPLTag | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import logging | ||
|
||
from dacite import from_dict | ||
|
||
from config.config_data import ConfigData | ||
from modules.servant.song_loader.rs_playlist_data import RsPlaylist | ||
from modules.servant.song_loader.song_loader import SongLoader | ||
from utils.rs_playlist_util import get_playlist | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
class TagManager: | ||
def __init__(self, config_data: ConfigData, song_loader: SongLoader): | ||
# TODO | ||
# TODO | ||
# TODO | ||
rsplaylist = self.get_rsplaylist(config_data) | ||
self.all_tags = self.__fetch_all_tags(rsplaylist) | ||
self.user_tags = self.__fetch_user_tags(rsplaylist) | ||
self.server_tags = self.__fetch_server_tags(rsplaylist) | ||
|
||
pass | ||
|
||
@staticmethod | ||
def get_rsplaylist(config_data): | ||
loader = config_data.song_loader | ||
new_playlist = get_playlist(loader.twitch_channel, loader.phpsessid) | ||
rsplaylist = from_dict(data_class=RsPlaylist, data=new_playlist) | ||
return rsplaylist | ||
|
||
@staticmethod | ||
def __fetch_all_tags(rsplaylist): | ||
return {value.name: key for key, value in rsplaylist.channel_tags.items()} | ||
|
||
@staticmethod | ||
def __fetch_server_tags(rsplaylist): | ||
return {value.name: key for key, value in rsplaylist.channel_tags.items() if not value.user} | ||
|
||
@staticmethod | ||
def __fetch_user_tags(rsplaylist): | ||
return {value.name: key for key, value in rsplaylist.channel_tags.items() if value.user} | ||
|
||
# def update_tags(self, new_playlist): | ||
# self.rsplaylist_json = new_playlist | ||
# self.rsplaylist = from_dict(data_class=RsPlaylist, data=new_playlist) | ||
# | ||
# def __log_available_rspl_tags(self): | ||
# tags = self.rsplaylist.channel_tags | ||
# user_tags = {value.name: key for key, value in tags.items() if value.user} | ||
# log.warning("Tags set in RSPlaylist:\n%s", pprint.pformat(user_tags)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import logging | ||
import pprint | ||
from typing import Dict | ||
|
||
from modules.servant.song_loader.rs_playlist_data import ChannelTag | ||
|
||
log = logging.getLogger() | ||
|
||
|
||
def log_available_rspl_tags(rsplaylist_channel_tags: Dict[str, ChannelTag]) -> None: | ||
user_tags = __filter_tags(rsplaylist_channel_tags, is_user=True) | ||
system_tags = __filter_tags(rsplaylist_channel_tags, is_user=False) | ||
|
||
__log_tags(user_tags, log.warning, "Tags set by the user in RSPlaylist") | ||
__log_tags(system_tags, log.info, "System tags set in RSPlaylist") | ||
|
||
|
||
def __filter_tags(tags_to_filter, is_user): | ||
return {value.name: key for key, value in tags_to_filter.items() if value.user == is_user} | ||
|
||
|
||
def __log_tags(tags_to_log, log_function, prefix_message): | ||
formatted_tags = pprint.pformat(tags_to_log) | ||
log_function(f"{prefix_message}:\n{formatted_tags}") |
Oops, something went wrong.