initial commit

This commit is contained in:
Von Random 2014-12-07 00:58:53 +03:00
commit 0a862c499d
6 changed files with 151 additions and 0 deletions

22
LICENSE Normal file
View file

@ -0,0 +1,22 @@
The MIT License (MIT)
Copyright (c) 2014 Von Random
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

4
README.md Normal file
View file

@ -0,0 +1,4 @@
vscripts
========
Some of my scripts. Different languages, different purposes, different quality of code. If you happen to use any of them and have a suggestion for improvements, I'll gladly accept them via e-mail.

29
flac-to-mp3.zsh Executable file
View file

@ -0,0 +1,29 @@
#!/usr/bin/env zsh
read_tags() {
metaflac $1 --show-tag=ALBUM --show-tag=ARTIST --show-tag=GENRE --show-tag=DATE --show-tag=TITLE --show-tag=TRACKNUMBER --show-tag=TRACKTOTAL |\
sed s/=/~..~/ |\
awk -F'~..~' '{print $1"='\''"$2"'\''"}'
}
mime_is() {
mimetype=$(file -b --mime-type $1)
if [[ $mimetype == $2 ]]; then
return 0
else
return 1
fi
}
for i in $argv[@]; do
if mime_is $i 'audio/x-flac'; then
local original=$i
eval $(read_tags $original)
local out_dir=/home/von/Music/\[UNSORTED\]/$ARTIST/$ALBUM
[[ -d $out_dir ]] || mkdir -p $out_dir
local converted=$out_dir/${i%.*}.mp3
flac -c -d $original | lame -V0 --add-id3v2 --pad-id3v2 --ignore-tag-errors \
--ta $ARTIST --tt $TITLE --tl $ALBUM --tg ${GENRE:-12} --tn ${TRACKNUMBER:-0} --ty $DATE \
- $converted
else
return 1
fi
done
exit 0

55
lowercase.lua Executable file
View file

@ -0,0 +1,55 @@
#!/usr/bin/env lua
require('os')
require('lfs')
function lowercase(basename, basedir)
if basedir == nil then
basedir = ''
end
local lowercased = string.lower(basename)
local path_orig = basedir .. basename
local path_new = basedir .. lowercased
if path_orig == path_new then
print(path_orig .. ' is already lowercase!')
return 1
else
print('Renaming: ' .. path_orig .. ' -> ' .. path_new)
os.rename(path_orig,path_new)
end
end
function is_dir(name)
local ftype = lfs.symlinkattributes(name, "mode")
if ftype == "directory" then
return true
else
return false
end
end
function find_and_rename(path)
for basename in lfs.dir(path) do
if basename ~= "." and basename ~= ".." then
local basedir = path .. '/'
local filename = basedir .. basename
if is_dir(filename) then
find_and_rename(filename)
end
lowercase(basename, basedir)
end
end
end
function test_and_execute(dir)
if is_dir(dir) then
find_and_rename(dir)
lowercase(dir)
else
print(dir .. ' is not a directory or does not exist!')
end
end
local i = 1
while arg[i] do
test_and_execute(arg[i])
i = i + 1
end

31
lowercase.pl Executable file
View file

@ -0,0 +1,31 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Copy;
use File::Find;
use Cwd 'cwd';
use feature 'say';
sub pathname {
return my $pathname = $File::Find::dir . '/' . $_[0];
}
sub lowercase {
if ($_ eq '.') {
return 0;
}
my $original = $_;
$_ =~ s/(^.*)/\L$1/g;
my $lowercased = $_;
if ($original eq $lowercased) {
say 'No need to rename ' . $original . ', it is already in lower case.';
return 0;
}
say 'Renaming ' . pathname($original) . ' to ' . pathname($lowercased) . '...';
move("$original", "$lowercased");
}
finddepth(\&lowercase, @ARGV);
say 'Everything done.';
exit 0;

10
simpler.pl Executable file
View file

@ -0,0 +1,10 @@
#!/usr/bin/env perl
use open ':std', ':encoding(UTF-8)';
my $block = shift || (chr(0x2588) x 3);
for (["", 0], ["1;", 0], ["", 8], ["1;", 8]) {
my ($bold, $offset) = @$_;
my @range = map $offset + $_, 0..7;
printf "%s %-6s ", $bold ? "bold" : "norm", "$range[0]-$range[-1]";
print map("\e[${bold}38;5;${_}m$block", @range), "\e[0m";
print "\n"
}