mpv2oboeru

mpv helpers to create flashcards from movies and TV shows
git clone anongit@rnpnr.xyz:mpv2oboeru.git
Log | Files | Refs | Feed | README | LICENSE

Commit: 66d3392362a0585c6c802f6e4cadfe9c967554c7
Parent: 9abdafcb21f3fa9437b12c8dbbc5cde76ac26e2f
Author: Ren Tatsumoto
Date:   Mon,  2 Nov 2020 11:23:09 +0300

add a function to download forvo pronunciations

Diffstat:
Msubs2srs.lua | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/subs2srs.lua b/subs2srs.lua @@ -390,6 +390,23 @@ local function join_media_fields(note1, note2) return note1 end +local function get_forvo_pronunciation(word) + word = platform.windows and url_encode(word) or word + local forvo_format = config.audio_extension:sub(2) + local forvo_page = subprocess { 'curl', '-s', string.format('https://forvo.com/search/%s/ja', word) }.stdout + local play_params = string.match(forvo_page, "Play%((.-)%);") + if not play_params then + return '' + end + local iter = string.gmatch(play_params, "'(.-)'") + local formats = { mp3 = iter(), ogg = iter() } + local audio_url = string.format('https://audio00.forvo.com/%s/%s', forvo_format, base64d(formats[forvo_format])) + local pronunciation_filename = string.format('forvo_%s.%s', platform.windows and os.time() or word, forvo_format) + local pronunciation_path = utils.join_path(config.collection_path, pronunciation_filename) + mp.commandv('run', 'curl', audio_url, '-s', '-L', '-o', pronunciation_path) + return string.format('[sound:%s]', pronunciation_filename) +end + local validate_config do local function set_collection_path() @@ -479,6 +496,8 @@ local function init_platform_windows() return subprocess(args, completion_fn) end + self.windows = true + return self end