Mercurial > ec-dotfiles
changeset 4:94ee419ad047
Added bin-ec - a collection of scripts.
author | Edho Prima Arief <me@myconan.net> |
---|---|
date | Sat, 10 Jul 2010 12:38:52 +0000 |
parents | 39ef7f7236fc |
children | de6ce93d40fc |
files | bin/cek bin/cek.rb bin/ed2k bin/lren bin/mgren bin/patren bin/putcrc bin/rar2zip bin/ren setup tcsh |
diffstat | 11 files changed, 379 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/cek Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,53 @@ +#!/bin/sh + +bn() { basename "/$*"; } +#cs() { cksfv -- "$@"; } +cs() { cek.rb "$@"; } +if [ "$#" -lt 1 ]; then + cat <<EOF +Usage: $(bn "$0") file1 file2 ... fileN +EOF + exit 1 +fi + +file_ok=0 +file_unre=0 +file_err=0 +file_nocrc=0 +for file in "$@"; do + st="nofile" + if [ -f "${file}" ] && [ -r "${file}" ]; then + crc=$(cs "${file}" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/') + nocrc=$(bn "${file}" | sed -e 's/.*[[(][A-Fa-f0-9]\{8\}[])].*//') + st="nocrc" + if [ ! -n "${nocrc}" ]; then + # the filename has CRC. Yay + filecrc=$(bn "${file}" | sed -e 's/.*[[(]\([A-Fa-f0-9]\{8\}\)[])].*/\1/;y/abcdef/ABCDEF/') + if [ "${filecrc}" = "${crc}" ]; then + st="fileok" + file_ok=$((file_ok+1)) + else + st="filerr" + file_err=$((file_err+1)) + fi + else + st="nocrc" + file_nocrc=$((file_nocrc+1)) + fi + else + st="nofile" + file_unre=$((file_unre+1)) + fi + case "${st}" in + "nofile") ret="not a file or unreadable";; + "nocrc") ret="${crc}";; + "fileok") ret="${crc} - OK!";; + "filerr") ret="${crc} - ERROR - should be ${filecrc}";; + esac + printf "%s\n" "${file}: ${ret}" +done +echo "--------------------------------" +[ "${file_ok}" -gt 0 ] && echo "Files ok: ${file_ok}" +[ "${file_err}" -gt 0 ] && echo "Files broken: ${file_err}" +[ "${file_nocrc}" -gt 0 ] && echo "Files without crc information: ${file_nocrc}" +[ "${file_unre}" -gt 0 ] && echo "Files unreadable or not file: ${file_unre}"
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/cek.rb Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,14 @@ +#!/usr/bin/env ruby +require 'zlib' + +block = 1048576 +ARGV.each do |filename| + crc = 0 + file = File.open(filename, 'rb') + currentbyte = 0 + while (line = file.read(block)) do + crc = Zlib.crc32(line,crc) + end + file.close + printf("%s %08X\n", filename, crc.to_s) +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/ed2k Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,26 @@ +#!/usr/bin/env ruby +require 'openssl' + +def file_ed2k(file_name, output_mode = "hash") + ed2k_block = 9500*1024 #ed2k block size is 9500 KiB + ed2k_hash = "" + file = File.open(file_name, 'rb') + file_size = file.stat.size #while at it, fetch the size of the file + while (block = file.read(ed2k_block)) do + ed2k_hash << OpenSSL::Digest::MD4.digest(block) #hashes are concatenated md4 per block size for ed2k hash + end + ed2k_hash << OpenSSL::Digest::MD4.digest("") if file_size % ed2k_block == 0 #on size of modulo block size, append another md4 hash of a blank string + file.close + ed2k_hash = OpenSSL::Digest::MD4.hexdigest(ed2k_hash) #finally + return case output_mode #there are 2 modes, just the has, or complete with link. + when "hash" + ed2k_hash + when "link" + "ed2k://|file|#{File.basename(file_name)}|#{file_size}|#{ed2k_hash}|" + end +end + +ARGV.each do |file_name| + next unless File.file?(file_name) and File.readable?(file_name) + printf("%s\n", file_ed2k(file_name,"link")) +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/lren Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,28 @@ +#!/usr/bin/env perl + +use warnings; +use strict; +use File::Basename; + +my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1); +my $skip=0; +foreach (@files) { + my $newname = $_; + print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_; + $newname =~ s/_/ /g; + $newname =~ s/.* Ep([[:digit:]]+) .*/[Anime-Takeover] You're Under Arrest! - $1 [v2].mkv/; + $newname =~ s/ +/ /g; + print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; + if ($_ eq $newname) { + print("$_: no need to rename, skipping\n"); + } else { + if($skip==1) { print("Result: $_ --> $newname\n"); } + else { + if(rename($_, $newname)) { print("$_ -> $newname\n"); } + else { print("$_: rename failed\n"); } + } + } + next(); +} + +exit(0);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/mgren Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +TITLE_MAPS={ "otaku no musume-san" => 1 } +TITLE_REAL={ 1 => "Otaku no Musume-san" } + +def get_title + +end + +ARGV.each do |file| + next unless File.file?(file) and File.readable?(file) +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/patren Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,11 @@ +#!/usr/bin/env ruby +TITLE_MAPS={ "otaku no musume-san" => 1 } +TITLE_REAL={ 1 => "Otaku no Musume-san" } + +def get_title + +end + +ARGV.each do |file| + next unless File.file?(file) and File.readable?(file) +end
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/putcrc Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,32 @@ +#!/bin/sh +safe_path() +{ + # It all depends on the first character. + __start=$(printf "%s" "$*" | cut -c 1) + __path= + case "${__start}" in + .|/) __path="$*";; # . and / is safe. No change. + *) __path="./$*";; # Anything else must be prefixed with ./ + esac + printf "%s" "${__path}" # Return. +} + +if [ "$#" -lt 1 ]; then + cat <<EOF +Usage: $(basename "/$0") file1 file2 ... fileN +EOF + exit 1 +fi + +for file in "$@"; do + if [ -f "${file}" ] && [ -r "${file}" ] && [ -n "$(printf "%s\n" "${file}" | sed -e 's/.*[A-F0-9]\{8\}.*//')" ]; then + filename="$(basename "$(safe_path "${file}")")" + dirname="$(dirname "$(safe_path "${file}")")" + myfile="$(printf "%s\n" "${filename%.*}" | sed -e 's/\([^]]\)$/\1 /')" + myext="${filename##*.}"; if [ "${myext}" = "${filename}" ]; then myext=""; else myext=".${myext}"; fi + crc=$(cek.rb "$(safe_path "${file}")" | tail -1 | sed -e 's/.*\([A-F0-9]\{8\}\)$/\1/') + mv -- "${file}" "${dirname}/${myfile}[${crc}]${myext}" && printf "%s => %s\n" "${file}" "${myfile}[${crc}]${myext}" + else + printf "%s\n" "${file} is not a file or unreadable" + fi +done
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/rar2zip Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,30 @@ +#!/bin/sh +to_lower() { + printf "%s" "$1" | tr '[:upper:]' '[:lower:]' +} +full_path() { + # It all depends on the first character. + start=${i%${i#?}} + path= + case "${start}" in + /) path="${1}";; # / is absolute. No change. + *) path="${2}/${1}";; # Anything else must be prefixed with $2 (hopefully $PWD) + esac + printf "%s" "${path}" # Return. +} +for i in "$@"; do + src_ext="${i##*.}" + src_path="$(full_path "${i}" "${PWD}")" + if [ -f "${src_path}" ] && [ -r "${src_path}" ] && [ "${src_ext}" != "${i}" ] && [ "$(to_lower ${src_ext})" = "rar" ]; then + tmpdir=".tmp.${i##*/}" + if mkdir -p "${tmpdir}"; then + if 7z x -o"${tmpdir}" -- "${src_path}"; then + (cd "${tmpdir}" && 7z a -mx=1 -tzip "${src_path%.*}.zip" -- "*";) + fi + rm -r "${tmpdir}" + fi + else + echo "Invalid input: ${i}" + fi +done +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/bin/ren Sat Jul 10 12:38:52 2010 +0000 @@ -0,0 +1,172 @@ +#!/usr/bin/env perl + +use warnings; +use strict; +use File::Basename; + +my @files = @ARGV or print("Usage: ",basename($0)," file1 ... fileN\n") && exit(1); +my $skip=0; +foreach (@files) { + my $newname = $_; + print(qq(Could not find file "$_", skipping\n)) and next() unless -e $_; + $newname =~ s/Sakura\.Wars\.([[:digit:]]{2}).*/[AM] Sakura Wars - $1.mkv/; + #$newname =~ s/Legend Of The Crystals OAV - 0/- Legend of the Crystals OVA - /; + #$newname =~ s/^Kaleido_Star_-_([[:digit:]]{2}).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - $1 [DVD]$2/i; + #$newname =~ s/^Kaleido_Star_-_Clean_ED([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Ending $1 (Clean) [DVD]$2/i; + #$newname =~ s/^Kaleido_Star_-_Clean_OP([[:digit:]]).*(\[[[:xdigit:]]{8}\]\.mkv)$/[joseole99] Kaleido Star - Opening $1 (Clean) [DVD]$2/i; + #$newname =~ s/.*_-_([[:digit:]]{2})\[47\].*(\[[[:xdigit:]]{8}\]\.mkv)$/[AniMecha] - $1 [DVD]$2/i; + #$newname =~ s/.*\.([[:digit:]]{2})\.\[.*([[:xdigit:]]{8}\]\.mkv)$/[Arigatou] Blade of the Immortal - $1 [$2/i; + #$newname =~ s/.* ([[:digit:]]+) .*/[AonE-AnY] Ah My Goddess - $1.avi/; + #$newname =~ s/\[24-\(Final\)\]_/24 [End]/; + #$newname =~ s/\[([[:digit:]]{2})\]/$1/; + #$newname =~ s/^Otaku no Musume-san c([[:digit:]]+) \[v03\](\[.+\])\.zip$/Otaku no Musume-san - $1 (v03) $2.zip/i; + #$newname =~ s/ HQ //; + $newname =~ s/xvid//i; + $newname =~ s/^\[Doremi\]\.HeartCatch\.PreCure!\.([[:digit:]]{2})\.\[1280x720\]\.\[([[:xdigit:]]{8})\]\.mkv$/[Doremi] HeartCatch PreCure! - $1 (1280x720) [$2].mkv/; + $newname =~ s/^\[Doremi\]\.Motto\.Ojamajo\.Doremi\.([[:digit:]]{2})\.\[([[:xdigit:]]{8})\]\.avi$/[Doremi] Motto Ojamajo Doremi - $1 [$2].avi/; + $newname =~ s/^(Detective Conan - [[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/; + $newname =~ s/^(Detective Conan - OVA[[:digit:]]+-?[[:digit:]]*) (\[DCTP[^]]*\])(.+)$/$2 $1 $3/; + $newname =~ s/^(Kamen Rider W - [[:digit:]]+)HD (\[W-Time\])(.+)$/$2 $1 $3/; + $newname =~ s/- TV -/-/; + $newname =~ s/^(\[Keroro\])\.([[:digit:]]+)\..*(\[[[:xdigit:]]{8}\].+)$/$1 Keroro Gunsou - $2 $3/; + $newname =~ s/SubDESU(.*)_-_Directors_Cut/SubDesu$1/; + $newname =~ s/\[480p\]\.mkv$/.mkv/; + $newname =~ s/^(\[EG\])ZZ_Gundam_BD_([[:digit:]]+)\(720p\)(.+)$/$1 Gundam ZZ - $2 (960x720) [BD]$3/; + $newname =~ s/\]_Working_-/] Working!! -/; + $newname =~ s/WORKING!!/Working!!/; + $newname =~ s/\[Retrofit\]_\[Ayako-m\.3\.3\.w\.\]/[Retrofit-Ayako-m.3.3.w]/i; + $newname =~ s/Rosario\+Vampire/Rosario + Vampire/i; + $newname =~ s/Rosario \+ Vampire - Capu2 - /Rosario + Vampire Capu 2 - /i; + $newname =~ s/ Hidamari Sketch Hoshimittsu / Hidamari Sketch - Hoshi Mittsu /i; + $newname =~ s/ HEROMAN / Heroman /i; + #$newname =~ s/^/[ETB]/i; + $newname =~ s/_/ /g; + $newname =~ s/ ARIA The ORIGINATION / Aria the Origination /i; + $newname =~ s/ ARIA The NATURAL / Aria the Natural /i; + $newname =~ s/^Clannad Ep([[:digit:]]+) \[1080p,BluRay,x264\] - THORA\.mkv$/[THORA] Clannad - $1 (1920x1080) [BD].mkv/i; + $newname =~ s/ Mahou Kishi Rayearth / Magic Knight Rayearth /i; + $newname =~ s/rune soldier ep/ Rune Soldier /i; + $newname =~ s/ Harukanaru Toki no Naka de Hachiyoushou / Haruka Naru Toki no Naka de - Hachiyoushou /i; + $newname =~ s/ Harukanaru Toki no Naka de - / Haruka Naru Toki no Naka de - Hachiyoushou /i; + $newname =~ s/ -Hachiyoushou - / - Hachiyoushou - /i; + $newname =~ s/\[Retrofit\] \[Shinsen\] /[Retrofit-SHS] /i; + $newname =~ s/ You're Under Arrest - / You're Under Arrest! - /i; + $newname =~ s/ Rosario to Vampire / Rosario + Vampire /i; + $newname =~ s/\[R2 Video\]//i; + $newname =~ s/ \(BD-720p\) \[/ (1280x720) [BD][/i; + $newname =~ s/ TV Ep/ - /i; + $newname =~ s/\] AIR - /] Air - /i; + $newname =~ s/ - Episode / - /i; + $newname =~ s/\[divx[[:digit:].]+\]//i; + $newname =~ s/\[BD\] \(1280x720\) \[/(1280x720) [BD][/i; + $newname =~ s/ Seiken no Blacksmith / The Sacred Blacksmith /i; + #$newname =~ s/^Rizelmine([[:digit:]]+)\.avi$/[AC] Rizelmine - $1.avi/i; + $newname =~ s/\[v2\]/v2/i; + $newname =~ s/\.AAC\]//; + $newname =~ s/ No / no /g; + #$newname =~ s/ 0([[:digit:]]) / $1 /; + $newname =~ s/\[1280x720\]/(1280x720) /; + #$newname =~ s/^.*( [[:digit:]]{2}v2).*(\[[[:xdigit:]]{8}\]\.mkv)$/[KAA] Ai Yori Aoshi - $1 [DVD]$2/; + $newname =~ s/ True Tears / true tears /i; + $newname =~ s/ Fate stay night TV Reproduction / Fate-stay night - TV Reproduction /i; + $newname =~ s/ The Tatami Galaxy \(Yojouhan Shinwa Taikei\) / The Tatami Galaxy /i; + $newname =~ s/ Saint Seiya The Lost Canvas / Saint Seiya - The Lost Canvas /i; + $newname =~ s/Mayoi Neko Overrun /Mayoi Neko Overrun! /; + $newname =~ s/Angel Beats /Angel Beats! /i; + $newname =~ s/Rainbow /Rainbow /i; + $newname =~ s/ Ookiku Furikabutte - The Summer Tournament Chapter / Ookiku Furikabutte S2 /i; + $newname =~ s/Senko no night raid /Senkou no Night Raid /i; + $newname =~ s/To Heart Mini Ep0/To Heart - Special /; + $newname =~ s/Mai Otome/Mai-Otome/i; + $newname =~ s/WORKING!!/Working!!/i; + $newname =~ s/ Sengoku Basara / Sengoku Basara /i; + $newname =~ s/ K-on!! S2 / K-ON!! /i; + #$newname =~ s/.*\[([[:digit:]]{2})\].*(\[[[:xdigit:]]{8}\]\.mkv)/[FuktLogik] Hidamari Sketch - $1 [DVD]$2/; + $newname =~ s/\(BD\) \[/ [BD][/i; + $newname =~ s/\[\[BD\]/[BD][/; + $newname =~ s/\(DVD \)/[DVD]/; + $newname =~ s/ AC3\]/ /; + $newname =~ s/ *(\.[[:alnum:]]+)[^[:alnum:]]*$/$1/; + $newname =~ s/\[webrip\]/[Webrip]/i; + $newname =~ s/\[[^]]*(640x360|[[:digit:]]{3}x480)[^]]*\]//; + $newname =~ s/([^]])\[/$1 [/; + #$newname =~ s/- .*x264 AAC\)//; + #$newname =~ s/ 0([[:digit:]]) / $1 /; + #$newname =~ s/ - Great Guardians OVA - / Great Guardians - Special - /; + #$newname =~ s/ ([\d]) / 0$1 /; + #$newname =~ s/.* ([\d]{2}) .*/[HL] Gundam ZZ - $1.mkv/; + #$newname =~ s/ \[[[:xdigit:]]{8}\]//; + $newname =~ s/^\(([^)]+)\)/[$1]/; + $newname =~ s/sonic x/Sonic X/i; + $newname =~ s/END/End/; + #$newname =~ s/\[[^]]*h\.?264[^]]*\]//; + $newname =~ s/h\.?264//i; + $newname =~ s/ op([\d]) / Opening $1 /i; + $newname =~ s/ ed([\d]) / Ending $1 /i; + $newname =~ s/ dragonball / Dragon Ball /i; + $newname =~ s/Kissxsis/ Kiss x Sis /i; + $newname =~ s/k-on/K-ON/i; + #$newname =~ s/ dvd (\(.*\) )?\[/ $1 [DVD][/i; + $newname =~ s/ ([\d]+)( |\.)/ - $1$2/; + $newname =~ s/\(([[:xdigit:]]{8})\)/[$1]/; + $newname =~ s/ ep([\d]+) / - $1 /i; + $newname =~ s/- \[/ [/; + $newname =~ s/&/ & /g; + $newname =~ s/ ([\d]{2})\[/ $1 [/; + $newname =~ s/(\[[0-9a-fA-F]{8})/\U$1/; + $newname =~ s/v([[:digit:].]+)([^\[]+)\[/${2}[v${1}][/i; + #$newname =~ s/v2 (?=\(.*\) ) \[/ $1 [v2][/; + $newname =~ s/([^ ])\[DVD\]\[x264\.AAC\]/$1 [DVD]/; + $newname =~ s/\(DVD\) +\[/[DVD][/; + $newname =~ s/^(\[[^]]+\])([^ ])/$1 $2/; + $newname =~ s/(\((1280x720|960x720)[^)]*\))/($2)/; + $newname =~ s/(\((1920x1080)[^)]*\)) /($2) [BD]/; + $newname =~ s/\[[^]]*720p[^]]*\] ?/(1280x720) /; + $newname =~ s/\[[^]]*1080p[^]]*\] ?/(1920x1080) /; + $newname =~ s/\(720p\)/(1280x720)/; + $newname =~ s/\[1280x720[^]]+\]/ (1280x720) /; + $newname =~ s/\([^)]*704x480[^)]*\)//; + $newname =~ s/([^ ])\(/$1 (/; + $newname =~ s/\.avi\.avi/.avi/; + $newname =~ s/^\[([^]&\-]*) +& +([^]&\-]*)\]/[$1-$2]/; + $newname =~ s/\(704x396 x264 AAC\)//; + $newname =~ s/\] +\[/][/; + $newname =~ s/~([^~]+)~/- $1 /; + $newname =~ s/\[DVD[^]]+\]/[DVD]/; + $newname =~ s/(\[BD\])+/[BD]/; + #$newname =~ s/Ep //; + $newname =~ s/([[:digit:]])v([[:digit:]]) \[/$1 [v$2][/; + $newname =~ s/([^-]) ([0-9]{2,3}) /$1 - $2 /; + $newname =~ s/- *\[/ [/; + $newname =~ s/( ?- )+/ - /g; + #$newname =~ s/ Special - / Special /; + $newname =~ s/ (\)|\])/$1/; + $newname =~ s/(\(|\[) /$1/; + $newname =~ s/(\(\)|\[\])+//; + #$newname =~ s/\) +\[/) [BD][/; + #$newname =~ s/SP/- Special /; + $newname =~ s/\[(Final|End)\]/[End]/i; + #$newname =~ s/Gurren Lagann Parallel Works - 2/Gurren Lagann Parallel Works 2/; + $newname =~ s/ - special - ([[:digit:]]+) / - Special $1 /i; + $newname =~ s/ memories off - 3\.5 - / Memories Off 3.5 - /i; + $newname =~ s/ - Navigation - / - Navigation /; + $newname =~ s/ - Picture Drama - / - Picture Drama /; + $newname =~ s/\[W B\]/[W_B]/; + $newname =~ s/ - (Ending|Opening) - 1 / - $1 /; + $newname =~ s/Seed Character Theater - /SEED - Character Theater /; + $newname =~ s/ - (Ending|Opening) - ([[:digit:]]+) / - $1 $2 /; + $newname =~ s/ +/ /g; + print(qq($_: $newname already exists, skipping\n)) and next() if -e $newname and $_ ne $newname; + if ($_ eq $newname) { + print("$_: no need to rename, skipping\n"); + } else { + if($skip==1) { print("Result: $_ --> $newname\n"); } + else { + if(rename($_, $newname)) { print("$_ -> $newname\n"); } + else { print("$_: rename failed\n"); } + } + } + next(); +} + +exit(0);
--- a/setup Sat Jul 10 12:18:06 2010 +0000 +++ b/setup Sat Jul 10 12:38:52 2010 +0000 @@ -6,6 +6,7 @@ linker "tmux" ".tmux.conf" linker "hg" ".hgrc" linker "vim" ".vimrc" + linker "bin" "bin-ec" #modify cshrc uninstall_tcsh
--- a/tcsh Sat Jul 10 12:18:06 2010 +0000 +++ b/tcsh Sat Jul 10 12:38:52 2010 +0000 @@ -3,7 +3,7 @@ limit coredumpsize 0 set prompt="[%B%n@%m %~%b]%# " -set path=({,/usr}/{bin,sbin} "${HOME}/bin") +set path=({,/usr}/{bin,sbin} "${HOME}/bin" "${HOME}/bin-ec") set history=1000 set savehist=1000 set nobeep