aboutsummaryrefslogtreecommitdiff
path: root/bulk-audio
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2023-10-07 12:40:08 +0200
committerlonkaars <loek@pipeframe.xyz>2023-10-07 12:40:08 +0200
commitfa5f1e9f4b119cb1fdf5902801562daba34de91d (patch)
treebedc6fd42bcdef4fd99c30ee8d0bde065b9150f3 /bulk-audio
parent6571144669ea21bab5f54a5b1681908c02979e88 (diff)
add audio get script
Diffstat (limited to 'bulk-audio')
-rw-r--r--bulk-audio/.gitignore1
-rwxr-xr-xbulk-audio/get54
2 files changed, 55 insertions, 0 deletions
diff --git a/bulk-audio/.gitignore b/bulk-audio/.gitignore
new file mode 100644
index 0000000..682d0c8
--- /dev/null
+++ b/bulk-audio/.gitignore
@@ -0,0 +1 @@
+*.mp3
diff --git a/bulk-audio/get b/bulk-audio/get
new file mode 100755
index 0000000..bd46e6b
--- /dev/null
+++ b/bulk-audio/get
@@ -0,0 +1,54 @@
+#!/bin/sh
+
+KANJI="$1"
+KANA="$2"
+OUTPUT="$3"
+
+if [ -z "$KANJI" -o -z "$KANA" -o -z "$OUTPUT" ]; then
+ cat << EOF
+usage: $0 <kanji> <kana> <output>
+
+return value is 0 if <output> was succesfully written, 1 if the word could not
+be found. this script searches languagepod101, languagepod101 (alt) and
+jisho.org.
+EOF
+ exit 1
+fi
+
+get_languagepod101() {
+ curl -so "$OUTPUT" "https://assets.languagepod101.com/dictionary/japanese/audiomp3.php?kanji=$KANJI&kana=$KANA"
+}
+
+get_languagepod101_alt() {
+ HTML="$(curl -s -X POST \
+ "https://www.japanesepod101.com/learningcenter/reference/dictionary_post" \
+ -H "Content-Type: application/x-www-form-urlencoded" \
+ -d "post=dictionary_reference&match_type=exact&search_query=$KANJI&vulgar=true" \
+ )"
+ [ $? -ne 0 ] && return 1
+ URL="$(echo "$HTML" | pup "audio source attr{src}" | head -n1)"
+ [ -z "$URL" ] && return 1
+ curl -so "$OUTPUT" "$URL"
+}
+
+get_jisho() {
+ HTML="$(curl -s "https://jisho.org/search/$KANJI")"
+ [ $? -ne 0 ] && return 1
+ URL="$(echo "$HTML" | pup "audio[id=\"audio_$KANJI:$KANA\"] source attr{src}" | head -n1)"
+ [ -z "$URL" ] && return 1
+ URL="https:$URL"
+ curl -so "$OUTPUT" "$URL"
+}
+
+get_languagepod101_alt
+[ $? -eq 0 ] && exit 0
+
+get_jisho
+[ $? -eq 0 ] && exit 0
+
+get_languagepod101
+[ $? -eq 0 ] && exit 0
+
+# if none were succesful, delete output file and exit with error
+rm -f "$OUTPUT"
+exit 1