diff --git a/modules/core/state.py b/modules/core/state.py index 71169f5632b240dc01747e529e0a68846f8eae23..d366850b218a0e5f4c3252282838b98d98d26c5d 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 b51018b061c01ec39b8b937ef26bf6d0f4c990f3..119af23b64370b6b6cb905d2a37362e31f7e3be4 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