Browse Source

initial commit

master
Von Random 4 years ago
commit
0a862c499d
6 changed files with 151 additions and 0 deletions
  1. 22
    0
      LICENSE
  2. 4
    0
      README.md
  3. 29
    0
      flac-to-mp3.zsh
  4. 55
    0
      lowercase.lua
  5. 31
    0
      lowercase.pl
  6. 10
    0
      simpler.pl

+ 22
- 0
LICENSE View File

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

+ 4
- 0
README.md View File

@@ -0,0 +1,4 @@
1
+vscripts
2
+========
3
+
4
+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
- 0
flac-to-mp3.zsh View File

@@ -0,0 +1,29 @@
1
+#!/usr/bin/env zsh
2
+read_tags() {
3
+	metaflac $1 --show-tag=ALBUM --show-tag=ARTIST --show-tag=GENRE --show-tag=DATE --show-tag=TITLE --show-tag=TRACKNUMBER --show-tag=TRACKTOTAL |\
4
+		sed s/=/~..~/ |\
5
+		awk -F'~..~' '{print $1"='\''"$2"'\''"}'
6
+}
7
+mime_is() {
8
+	mimetype=$(file -b --mime-type $1)
9
+	if [[ $mimetype == $2 ]]; then
10
+		return 0
11
+	else
12
+		return 1
13
+	fi
14
+}
15
+for i in $argv[@]; do
16
+	if mime_is $i 'audio/x-flac'; then
17
+		local original=$i
18
+		eval $(read_tags $original)
19
+		local out_dir=/home/von/Music/\[UNSORTED\]/$ARTIST/$ALBUM
20
+		[[ -d $out_dir ]] || mkdir -p $out_dir
21
+		local converted=$out_dir/${i%.*}.mp3
22
+		flac -c -d $original | lame -V0 --add-id3v2 --pad-id3v2 --ignore-tag-errors \
23
+			--ta $ARTIST --tt $TITLE --tl $ALBUM --tg ${GENRE:-12} --tn ${TRACKNUMBER:-0} --ty $DATE \
24
+			- $converted
25
+	else
26
+		return 1
27
+	fi
28
+done
29
+exit 0

+ 55
- 0
lowercase.lua View File

@@ -0,0 +1,55 @@
1
+#!/usr/bin/env lua
2
+require('os')
3
+require('lfs')
4
+
5
+function lowercase(basename, basedir)
6
+	if basedir == nil then
7
+		basedir = ''
8
+	end
9
+	local lowercased = string.lower(basename)
10
+	local path_orig = basedir .. basename
11
+	local path_new = basedir .. lowercased
12
+	if path_orig == path_new then
13
+		print(path_orig .. ' is already lowercase!')
14
+		return 1
15
+	else
16
+		print('Renaming: ' .. path_orig .. ' -> ' .. path_new)
17
+		os.rename(path_orig,path_new)
18
+	end
19
+end
20
+
21
+function is_dir(name)
22
+	local ftype = lfs.symlinkattributes(name, "mode")
23
+	if ftype == "directory" then
24
+		return true
25
+	else
26
+		return false
27
+	end
28
+end
29
+
30
+function find_and_rename(path)
31
+	for basename in lfs.dir(path) do
32
+		if basename ~= "." and basename ~= ".." then
33
+			local basedir = path .. '/'
34
+			local filename = basedir .. basename
35
+			if is_dir(filename) then
36
+				find_and_rename(filename)
37
+			end
38
+			lowercase(basename, basedir)
39
+		end
40
+	end
41
+end
42
+
43
+function test_and_execute(dir)
44
+	if is_dir(dir) then
45
+		find_and_rename(dir)
46
+		lowercase(dir)
47
+	else
48
+		print(dir .. ' is not a directory or does not exist!')
49
+	end
50
+end
51
+local i = 1
52
+while arg[i] do
53
+	test_and_execute(arg[i])
54
+	i = i + 1
55
+end

+ 31
- 0
lowercase.pl View File

@@ -0,0 +1,31 @@
1
+#!/usr/bin/env perl
2
+use strict;
3
+use warnings;
4
+use File::Copy;
5
+use File::Find;
6
+use Cwd 'cwd';
7
+use feature 'say';
8
+
9
+sub pathname {
10
+	return my $pathname = $File::Find::dir . '/' . $_[0];
11
+}
12
+
13
+sub lowercase {
14
+	if ($_ eq '.') {
15
+		return 0;
16
+	}
17
+	my $original = $_;
18
+	$_ =~ s/(^.*)/\L$1/g;
19
+	my $lowercased = $_;
20
+	if ($original eq $lowercased) {
21
+		say 'No need to rename ' . $original . ', it is already in lower case.';
22
+		return 0;
23
+	}
24
+	say 'Renaming ' . pathname($original) . ' to ' . pathname($lowercased) . '...';
25
+	move("$original", "$lowercased");
26
+}
27
+
28
+finddepth(\&lowercase, @ARGV);
29
+say 'Everything done.';
30
+exit 0;
31
+

+ 10
- 0
simpler.pl View File

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

Loading…
Cancel
Save