From 0a862c499dd582d39a6c897e0f5941f7623b537c Mon Sep 17 00:00:00 2001 From: Von Random Date: Sun, 7 Dec 2014 00:58:53 +0300 Subject: [PATCH] initial commit --- LICENSE | 22 ++++++++++++++++++++ README.md | 4 ++++ flac-to-mp3.zsh | 29 ++++++++++++++++++++++++++ lowercase.lua | 55 +++++++++++++++++++++++++++++++++++++++++++++++++ lowercase.pl | 31 ++++++++++++++++++++++++++++ simpler.pl | 10 +++++++++ 6 files changed, 151 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 flac-to-mp3.zsh create mode 100755 lowercase.lua create mode 100755 lowercase.pl create mode 100755 simpler.pl diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..fb393a8 --- /dev/null +++ b/LICENSE @@ -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. + diff --git a/README.md b/README.md new file mode 100644 index 0000000..340b3af --- /dev/null +++ b/README.md @@ -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. diff --git a/flac-to-mp3.zsh b/flac-to-mp3.zsh new file mode 100755 index 0000000..fbd8103 --- /dev/null +++ b/flac-to-mp3.zsh @@ -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 diff --git a/lowercase.lua b/lowercase.lua new file mode 100755 index 0000000..35c3350 --- /dev/null +++ b/lowercase.lua @@ -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 diff --git a/lowercase.pl b/lowercase.pl new file mode 100755 index 0000000..ac0794b --- /dev/null +++ b/lowercase.pl @@ -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; + diff --git a/simpler.pl b/simpler.pl new file mode 100755 index 0000000..54a83aa --- /dev/null +++ b/simpler.pl @@ -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" +}