From 26c5ed41883c07fe4bcb729c0c500af3d21a608a Mon Sep 17 00:00:00 2001 From: Daniel Vijge Date: Tue, 16 Apr 2024 11:40:36 +0200 Subject: [PATCH] Option to select custom helper application --- HTML/EN/plugins/MixCloud/settings/basic.html | 7 ++-- Plugin.pm | 2 +- ProtocolHandler.pm | 40 +++++++++++--------- Settings.pm | 2 +- strings.txt | 12 +++--- 5 files changed, 34 insertions(+), 29 deletions(-) diff --git a/HTML/EN/plugins/MixCloud/settings/basic.html b/HTML/EN/plugins/MixCloud/settings/basic.html index 657274b..d06b27a 100644 --- a/HTML/EN/plugins/MixCloud/settings/basic.html +++ b/HTML/EN/plugins/MixCloud/settings/basic.html @@ -23,10 +23,9 @@ [% END %] [% WRAPPER setting title="PLUGIN_MIXCLOUD_HELPER_APPLICATION" desc="PLUGIN_MIXCLOUD_HELPER_APPLICATION_DESC" %] -
-
-
- +
+
+ [% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_CUSTOM_PATH' | getstring %]: [% END %] [% PROCESS settings/footer.html %] diff --git a/Plugin.pm b/Plugin.pm index de445b7..7d9c65b 100644 --- a/Plugin.pm +++ b/Plugin.pm @@ -42,7 +42,7 @@ my $log = Slim::Utils::Log->addLogCategory({ 'description' => string('PLUGIN_MIXCLOUD'), }); -$prefs->init({ apiKey => "", playformat => "mp4", useBuffered => 1 }); +$prefs->init({ apiKey => "", playformat => "mp4", useBuffered => 1, helper_application => 'bundled', helper_application_custom_path => "" }); sub getToken { my ($callback) = shift; diff --git a/ProtocolHandler.pm b/ProtocolHandler.pm index 8f6939f..07bc28b 100644 --- a/ProtocolHandler.pm +++ b/ProtocolHandler.pm @@ -41,8 +41,6 @@ my $log = logger('plugin.mixcloud'); my $prefs = preferences('plugin.mixcloud'); my $cache = Slim::Utils::Cache->new; -my $bin_path; - Slim::Player::ProtocolHandlers->registerURLHandler(PAGE_URL_REGEXP, __PACKAGE__); sub isPlaylistURL { 0 } @@ -173,19 +171,33 @@ sub getNextTrack { } sub findExec { - my %paths = Slim::Utils::Misc::getBinPaths(); + my $exec = EXEC; + if ($^O eq 'MSWin32') { + $exec = "$exec.exe"; + } + if ($prefs->get('helper_application') eq 'custom') { + if ($prefs->get('helper_application_custom_path') eq '') { + return $exec; + } + else { + return $prefs->get('helper_application_custom_path'); + } + return + } + else { + my %paths = Slim::Utils::Misc::getBinPaths(); - for my $path (%paths) { - if (index($path, 'MixCloud') != -1) { - $log->debug("Use bin path " . $path); - $bin_path = $path; - return; + for my $path (%paths) { + if (index($path, 'MixCloud') != -1) { + $log->debug("Use bin path $path/$exec"); + return "$path/$exec"; + } } + $log->error("Error: Cannot find bin path for yt-dlp"); } - $log->error("Error: Cannot find bin path for yt-dlp"); } -# complement track details (url, format, bitrate) using dmixcloud +# complement track details (url, format, bitrate) sub _fetchTrackExtra { my ($url, $cb) = @_; my $id = getId($url); @@ -203,14 +215,8 @@ sub _fetchTrackExtra { my $mixcloud_url = "https://www.mixcloud.com/$id"; - if ($bin_path eq "") { - findExec(); - } # use yt-dlp to extract stream URL - my $exec = $bin_path . '/' . EXEC; - if ($^O eq 'MSWin32') { - $exec = "$exec.exe"; - } + my $exec = findExec(); my $exec_options = EXEC_OPTIONS; my $yt_dlp_cmd = "$exec $exec_options $mixcloud_url 2>&1"; # pipe STDERR to STDOUT $log->info("Executing helper binary: $yt_dlp_cmd"); diff --git a/Settings.pm b/Settings.pm index 9d6eecf..092c0bb 100644 --- a/Settings.pm +++ b/Settings.pm @@ -22,7 +22,7 @@ sub page { sub prefs { my $class = shift; # playformat not used for now - my @prefs = ( preferences('plugin.mixcloud'), qw(apiKey) ); + my @prefs = ( preferences('plugin.mixcloud'), qw(apiKey), qw(helper_application), qw(helper_application_custom_path) ); push @prefs, qw(useBuffered) unless Slim::Player::Protocols::HTTP->can('canEnhanceHTTP'); return @prefs; } diff --git a/strings.txt b/strings.txt index 10627c3..ff5d57c 100644 --- a/strings.txt +++ b/strings.txt @@ -155,13 +155,13 @@ PLUGIN_MIXCLOUD_HELPER_APPLICATION EN Helper application PLUGIN_MIXCLOUD_HELPER_APPLICATION_DESC - EN This plugin uses a helper application to get a playable stream from Mixcloud. By default a bundled version of yt-dlp is used. Select between the bundled version of yt-dlp, a system installed version (must be available in $PATH), or a custom one. + EN This plugin uses a helper application to get a playable stream from Mixcloud. By default a bundled version of yt-dlp is used. Select between the bundled version of yt-dlp, or a custom one. If yt-dlp is available in $PATH the path field can be left empty, else enter the full path to the help application. PLUGIN_MIXCLOUD_HELPER_APPLICATION_BUNDLED - EN Use bundled version - -PLUGIN_MIXCLOUD_HELPER_APPLICATION_SYSTEM - EN Use system version (not yet implemented) + EN Use bundled helper application PLUGIN_MIXCLOUD_HELPER_APPLICATION_CUSTOM - EN Use custom version (not yet implemented) + EN Use custom helper application + +PLUGIN_MIXCLOUD_HELPER_APPLICATION_CUSTOM_PATH + EN Full path \ No newline at end of file