Skip to content

Commit

Permalink
Option to select custom helper application
Browse files Browse the repository at this point in the history
  • Loading branch information
danielvijge committed Apr 16, 2024
1 parent b8d6337 commit 26c5ed4
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 29 deletions.
7 changes: 3 additions & 4 deletions HTML/EN/plugins/MixCloud/settings/basic.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@
[% END %]

[% WRAPPER setting title="PLUGIN_MIXCLOUD_HELPER_APPLICATION" desc="PLUGIN_MIXCLOUD_HELPER_APPLICATION_DESC" %]
<input type="radio" id="bundled" checked /><label for="bundled">[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_BUNDLED' | getstring %]</label><br/>
<input type="radio" id="system" disabled /><label for="system">[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_SYSTEM' | getstring %]</label><br/>
<input type="radio" id="custom" disabled /><label for="custom">[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_CUSTOM' | getstring %]</label><br/>
<input type="text" id="custom_path" disabled />
<input type="radio" class="stdedit" name="pref_helper_application" id="helper_application_bundled" value="bundled"[% IF prefs.helper_application == 'bundled' %] checked="checked"[% END %] /><label for="helper_application_bundled">[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_BUNDLED' | getstring %]</label><br/>
<input type="radio" class="stdedit" name="pref_helper_application" id="helper_application_custom" value="custom"[% IF prefs.helper_application == 'custom' %] checked="checked"[% END %] /><label for="helper_application_custom">[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_CUSTOM' | getstring %]</label><br/>
[% 'PLUGIN_MIXCLOUD_HELPER_APPLICATION_CUSTOM_PATH' | getstring %]: <input type="text" class="stdedit" name="pref_helper_application_custom_path" id="helper_application_custom_path" value="[% prefs.helper_application_custom_path %]" size="40" />
[% END %]

[% PROCESS settings/footer.html %]
2 changes: 1 addition & 1 deletion Plugin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
40 changes: 23 additions & 17 deletions ProtocolHandler.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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);
Expand All @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion Settings.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions strings.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>yt-dlp</code> is used. Select between the bundled version of yt-dlp, a system installed version (must be available in <code>$PATH</code>), or a custom one.
EN This plugin uses a helper application to get a playable stream from Mixcloud. By default a bundled version of <code>yt-dlp</code> is used. Select between the bundled version of <code>yt-dlp</code>, or a custom one. If <code>yt-dlp</code> is available in <code>$PATH</code> 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

0 comments on commit 26c5ed4

Please sign in to comment.