From 72812a1683223ecfab670ba9b550c39c37cfae6f Mon Sep 17 00:00:00 2001 From: David Trattnig <david.trattnig@o94.at> Date: Fri, 17 Jul 2020 15:56:58 +0200 Subject: [PATCH] Resolve entry by URI. --- modules/core/state.py | 61 ++++++++++++---------------- modules/liquidsoap/in_filesystem.liq | 1 + 2 files changed, 27 insertions(+), 35 deletions(-) diff --git a/modules/core/state.py b/modules/core/state.py index 71169f56..d366850b 100644 --- a/modules/core/state.py +++ b/modules/core/state.py @@ -21,8 +21,8 @@ import logging from collections import deque from modules.base.exceptions import NoActiveEntryException -from modules.base.utils import SimpleUtil, EngineUtil - +from modules.base.utils import SimpleUtil as SU, EngineUtil +from modules.core.channels import ChannelType @@ -73,45 +73,36 @@ class PlayerStateService: return self.entry_history[0] - def entry_for_source(self, source): + def resolve_entry(self, source): """ Retrieves the `PlaylistEntry` matching the provied source URI. - """ - # TODO Implement - - - def store_trackservice_entry(self, filepath): - """ - Stores the entry identified by the given source in the Track Service. Args: - filepath (String): The path of the currently playing file - + source (String): The URI of the source playing Raises: - (NoActiveEntryException): In case currently nothing is playing + (NoActiveEntryException) """ - found = False - # entries = self.get_recent_entries() - - # if not entries: - # raise NoActiveEntryException - - # for active_entry in entries: - # base_dir = self.config.get("audiofolder") - # if EngineUtil.uri_to_filepath(base_dir, active_entry.source) == filepath: - # trackservice = TrackService(active_entry) - # trackservice.store(add=True, commit=True) - - # active_entry.trackservice_id = trackservice.id - # active_entry.store(add=False, commit=True) - - # self.logger.info("Stored active entry '%s' to TrackService as '%s'" % (active_entry, trackservice)) - # found = True - - # if not found: - # msg = "Found no entry in the recent history which matches the given source '%s'" % (filepath) - # self.logger.critical(SimpleUtil.red(msg)) - + result = None + entries = self.get_recent_entries() + if not entries: + raise NoActiveEntryException + + for entry in entries: + entry_source = entry.source + + if entry.channel in ChannelType.FILESYSTEM.channels: + base_dir = self.config.get("audiofolder") + entry_source = EngineUtil.uri_to_filepath(base_dir, entry.source) + if entry_source == source: + self.logger.info("Resolved '%s' entry '%s' for URI '%s'" % (entry.get_type(), entry, source)) + result = entry + break + + if not result: + msg = "Found no entry in the recent history which matches the given source '%s'" % (source) + self.logger.critical(SU.red(msg)) + + return result def print_entry_history(self): diff --git a/modules/liquidsoap/in_filesystem.liq b/modules/liquidsoap/in_filesystem.liq index b51018b0..119af23b 100644 --- a/modules/liquidsoap/in_filesystem.liq +++ b/modules/liquidsoap/in_filesystem.liq @@ -32,6 +32,7 @@ def do_meta_filesystem(meta) = filename = meta["filename"] # artist = meta["artist"] # title = meta["title"] + # print('CALLING GURU #{list.assoc(default="", "install_dir", ini)}/guru.py') system('#{list.assoc(default="", "install_dir", ini)}/guru.py --on_play "#{filename}" &') end -- GitLab