Last active
August 29, 2015 14:02
-
-
Save CrimsonRoselia/24d3842883ba6b953696 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Works on linux only (with mpd) | |
Requires the YAML::Syck module from cpan. | |
Requires youtube-dl | |
Requires mpc | |
musircrc file must be placed in /etc folder |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use feature 'switch'; | |
use POSIX qw(getuid setuid setgid getpwnam); | |
use YAML::Syck; | |
no warnings; # Shut the fuck up, i dont care if given/when is experimental. | |
sub download_file { | |
my ($file, $format) = @_; | |
system "youtube-dl -x --audio-format $format $file"; | |
print "\n"; | |
} | |
sub change_permission { | |
my ($name, undef, $uid, $gid, undef, undef, undef, undef, undef, undef) = getpwnam(shift); | |
setgid($gid); | |
setuid($uid); | |
} | |
die "Could not find /etc/musicrc" unless (-e '/etc/musicrc'); | |
my $config = LoadFile('/etc/musicrc'); | |
given($ARGV[0]) { | |
when ('download') { | |
die "Please run this script as root\n" if $> != 0; | |
change_permission $config->{music}->{user}; | |
my $pl = $ARGV[1]; | |
if($pl =~ /^http/i) { | |
chdir $config->{'music'}->{'path'}."/".$config->{'music'}->{'default-playlist'}; | |
download_file($_, $config->{'download'}->{'format'}) foreach @ARGV[1 .. $#ARGV]; | |
} else { | |
chdir $config->{'music'}->{'path'}."/".$pl; | |
download_file($_, $config->{'download'}->{'format'}) foreach @ARGV[2 .. $#ARGV]; | |
} | |
} | |
when ('reload') { | |
my $pl = join ' ', map { qq/"$_"/ } @{$config->{music}->{playlists}}; | |
exec "mpc update && mpc clear && mpc ls $pl | sort | mpc add"; | |
} | |
default { print "I do not know the command '$_'" } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
music: | |
user: mpd | |
path: /var/lib/mpd/music/ | |
playlists: | |
- random | |
- The Audience's Listening | |
default-playlist: random | |
download: | |
format: vorbis |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment