-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathplay.py
35 lines (29 loc) · 929 Bytes
/
play.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# encoding: utf-8
import subprocess
import webbrowser
import sys
import os
import youdao
from workflow import Workflow, web
def downloadAudio(wf, word):
BriURL = "http://dict.youdao.com/dictvoice?audio=" + word + "&type=1"
AmeURL = "http://dict.youdao.com/dictvoice?audio=" + word + "&type=2"
dirname = wf.cachedir + "/"
res = web.get(BriURL)
if res.status_code == 200:
res.save_to_path(dirname + word + ".bri")
res = web.get(AmeURL)
if res.status_code == 200:
res.save_to_path(dirname + word + ".ame")
def main(wf):
args = wf.args
if args[0].startswith("http"):
webbrowser.open(args[0])
else:
audioPath = wf.cachedir + "/" + args[0] + "." + args[1]
if not os.path.exists(audioPath):
downloadAudio(wf, args[0])
subprocess.call(["afplay", audioPath])
if __name__ == '__main__':
wf = Workflow()
sys.exit(wf.run(main))