summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2019-04-11 11:08:19 +0200
committerFlorian Pritz <bluewind@xinu.at>2019-04-11 11:08:19 +0200
commit2ba2e84ef06f1d98b99c86b8e77f7daa80d389b6 (patch)
tree0bad9d14fead66204e44591d0cb81797950c23c4
parentb300634f222eb9414ed6cf5768b5f1b745e5e384 (diff)
downloadbin-2ba2e84ef06f1d98b99c86b8e77f7daa80d389b6.tar.gz
bin-2ba2e84ef06f1d98b99c86b8e77f7daa80d389b6.tar.xz
Add browser_launcher.pl
Signed-off-by: Florian Pritz <bluewind@xinu.at>
-rwxr-xr-xbrowser_launcher.pl53
1 files changed, 53 insertions, 0 deletions
diff --git a/browser_launcher.pl b/browser_launcher.pl
new file mode 100755
index 0000000..3bc2dfe
--- /dev/null
+++ b/browser_launcher.pl
@@ -0,0 +1,53 @@
+#!/usr/bin/env perl
+
+=head1 DESCRIPTION
+
+Open an URL in different browsers depending on the URL. Play spotify URLs with
+the spotify client.
+
+=cut
+
+use strict;
+use warnings;
+use autodie qw(:all);
+
+use Text::Template 'fill_in_string';
+
+my $sites = {
+ 'youtube' => {
+ 'patterns' => [
+ qr|^https://www.youtube.com|,
+ qr|^https://youtube.com|,
+ qr|^https://youtu.be|,
+ ],
+ 'command' => ['firefox', '{$url}'],
+ },
+ 'spotify' => {
+ 'patterns' => [
+ qr|^https://open\.spotify\.com/(?<group>\w+)/(?<track>\w+)?|
+ ],
+ 'command' => [
+ 'dbus-send', '--print-reply',
+ '--dest=org.mpris.MediaPlayer2.spotify',
+ '/org/mpris/MediaPlayer2',
+ 'org.mpris.MediaPlayer2.Player.OpenUri',
+ 'string:spotify:{$group}:{$track}',
+ ],
+ },
+};
+
+my $url_argument = $ARGV[0];
+
+for my $key (keys $sites->%*) {
+ my $site = $sites->{$key};
+ for my $pattern ($site->{patterns}->@*) {
+ if ($url_argument =~ m/$pattern/) {
+ my @cmd = $site->{command}->@*;
+ # template @cmd
+ @cmd = map {fill_in_string($_, HASH => {%+, url => $url_argument}) } @cmd;
+ exec(@cmd);
+ }
+ }
+}
+
+exec $ENV{'REAL_BROWSER'} // 'firefox', $url_argument;