Browse code

Added 'mp' and 'wydir'

Jaidyn Lev authored on 2019-01-21 19:09:15
Showing 3 changed files
... ...
@@ -21,6 +21,9 @@ You'll need:
21 21
 ----------------------------------------
22 22
 USAGE
23 23
 ----------------------------------------
24
+
25
+WYRICS
26
+--------------------
24 27
 Just run "wyrics" like so:
25 28
 
26 29
 	wyrics -s "query"
... ...
@@ -49,6 +52,48 @@ Just type a number, hit enter, and the lyrics'll pop up.
49 52
 If you want to save lyrics to a file, you'll need to redirect the
50 53
 output-- "wyrics -s 'bob' > BOB.txt"
51 54
 
55
+--------------------
56
+
57
+
58
+... however, I've also included some more scripts that'll help make wyrics
59
+and listening to music with lyrics more convenient:
60
+
61
+
62
+WYDIR
63
+--------------------
64
+Runs "wyrics" over every song in a directory of a given file-extension.
65
+The lyrics are output to "$song.txt"
66
+
67
+Just run "wydir" like so:
68
+
69
+	wydir file-ext [prefix]
70
+
71
+file-ext        should be the file-extension of songs in the current dir.
72
+prefix          should be a prefix to search results to help make them
73
+                more accurate-- like, for example, the band-name, the
74
+                album, etc.
75
+
76
+This is really convenient if you wanna get the lyrics of an album in
77
+one go. =w=
78
+
79
+
80
+MP
81
+--------------------
82
+MP is a font-end to the music-player MPV.
83
+What MP does, is that before a song is played, it tries to "cat" it's
84
+lyrics file (assumed to be like "song.ogg.txt"), then executes MPV.
85
+
86
+Since it executes MPV once for every song passed, you're probably wondering
87
+how you could seek back or forward a song.
88
+
89
+Normally you'd use "<" or ">", but with MP, just use CTRL-C and "Q".
90
+
91
+The escape-code of CTRL-C (4) is caught by MP, and interpreted to mean you
92
+wanna go back a song.
93
+
94
+The regular escape-code of "Q" (0) is caught, and interpreted to mean you
95
+want to skip to the next song.
96
+
52 97
 
53 98
 
54 99
 ----------------------------------------
55 100
new file mode 100755
... ...
@@ -0,0 +1,123 @@
1
+#!/bin/sh
2
+########################################
3
+# name: mp
4
+# desc: front-end to MPV that displays
5
+#       lyrics text-files before playing
6
+#       a song.
7
+# main: Jenga Phoenix
8
+#       <jadedctrl@teknik.io>
9
+# lisc: CC 0
10
+########################################
11
+
12
+trap "" 2
13
+
14
+
15
+#---------------------------------------
16
+# generic
17
+
18
+# STRING --> STRING
19
+# Return the first 'word' (space-delimiter) of a string.
20
+function car {
21
+	local string="$1"
22
+
23
+	echo "$string" \
24
+	| awk '{ print $1 }'
25
+}
26
+
27
+# STRING --> STRING
28
+# Return all words after the first word of a string.
29
+function cdr {
30
+	local string="$1"
31
+
32
+	local car="$(car "$string")"
33
+
34
+	if test $(length "$string") -eq 1; then
35
+		echo ""
36
+	else
37
+		echo "$string" \
38
+		| sed 's/^'"$car"' //'
39
+	fi
40
+}
41
+
42
+# STRING --> NUMBER
43
+# Return the length of a string.
44
+function length {
45
+	local string="$1"
46
+
47
+	echo "$string" \
48
+	| wc -w \
49
+	| tr -d ' '
50
+}
51
+
52
+# NUMBER NUMBER --> NUMBER
53
+# Add two numbers together.
54
+function add {
55
+	operator="$1"
56
+	operatee="$2"
57
+
58
+	echo "$1 + $2" \
59
+	| bc
60
+}
61
+
62
+
63
+
64
+# --------------------------------------
65
+
66
+# NIL --> NUMBER
67
+# Return the amount of total items.
68
+function total_items {
69
+	add "$(length "$DISCARD")" "$(length "$ITEMS")"
70
+}
71
+
72
+# NIL --> NUMBER
73
+# Return the amount of discarded items.
74
+function discarded_items {
75
+	echo "$(length "$DISCARD")"
76
+}
77
+
78
+
79
+
80
+# --------------------------------------
81
+
82
+# NUMBER --> NIL
83
+# Handle the return code of `mpv` properly, according
84
+# to the cause.
85
+function handle_return {
86
+	local return=$1
87
+
88
+	case $return in
89
+		4)	# ^C
90
+			# rewind one file <<
91
+			ITEMS="$(car "$DISCARD") $ITEMS"
92
+			DISCARD="$(cdr "$DISCARD")"
93
+			;;
94
+		0)	# normal
95
+			# put current file to discard
96
+			DISCARD="$(car "$ITEMS") $DISCARD"
97
+			ITEMS="$(cdr "$ITEMS")"
98
+			;;
99
+		2)	# no file
100
+			# don't even discard it-- BURN IT
101
+			ITEMS="$(cdr "$ITEMS")"
102
+			;;
103
+	esac
104
+}
105
+
106
+
107
+
108
+# --------------------------------------
109
+# invocation
110
+
111
+DISCARD=""
112
+ITEMS="$@"
113
+
114
+while test -n "$ITEMS"; do
115
+	local item="$(car "$ITEMS")"
116
+
117
+	cat "${item}.txt" 2> /dev/null
118
+	echo "===$(discarded_items)/$(total_items)==="
119
+	mpv "$item"
120
+
121
+	return=$?
122
+	handle_return "$return"
123
+done
0 124
new file mode 100755
... ...
@@ -0,0 +1,62 @@
1
+#!/bin/sh
2
+########################################
3
+# name: wydir
4
+# desc: run `wyrics` over every song in
5
+#       a directory of given file-ext
6
+# main: Jenga Phoenix
7
+#       <jadedctrl@teknik.io>
8
+# lisc: CC 0
9
+########################################
10
+
11
+
12
+# STRING STRING --> STRING
13
+# Return a version of a filename suitable for making a
14
+# query. Replace "_" with spaces, get rid of file-ext.
15
+function query_name {
16
+	filename="$1"
17
+	suffix="$2"
18
+
19
+	basename "$filename" ".$suffix" \
20
+	| sed 's/_/ /g'
21
+}
22
+
23
+# STRING --> STRING
24
+# Return the name of a file's lyrics text-file.
25
+# Will be the full-name + .txt
26
+function text_name {
27
+	filename="$1"
28
+
29
+	echo "${filename}.txt"
30
+}
31
+
32
+
33
+
34
+# --------------------------------------
35
+# invocation
36
+
37
+function usage {
38
+	echo "usage: wydir file-ext [prefix]"
39
+	echo "       'file-ext' should be the ext to songs in this dir"
40
+	echo "       'prefix'   should be a prefix (I.E., band-name) to"
41
+	echo "                  help make search-results more accurate."
42
+
43
+	exit 2
44
+}
45
+
46
+# --------------------------------------
47
+
48
+SUFFIX="$1"
49
+PREFIX="$2"
50
+
51
+if test -z "$SUFFIX"; then
52
+	usage
53
+fi
54
+
55
+for file in $(ls *.$1); do
56
+	echo "... $file ..."
57
+	lyrics="$(wyrics -s "$PREFIX $(query_name "$file" "$SUFFIX")")"
58
+
59
+	if test -n "$lyrics"; then
60
+		echo "$lyrics" > "$(text_name "$file")"
61
+	fi
62
+done