Skip to content

Commit

Permalink
更新到 V2.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxe committed Mar 21, 2022
1 parent 4d43137 commit abff34e
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 25 deletions.
2 changes: 1 addition & 1 deletion source/doc/zh_CN/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2 id="introduction">簡介</h2>
<h2 id="description">說明</h2>
<h3 id="features">特色</h3>
<ul>
<li>支援 Disney+, Youtube, MaruMaru 等網站</li>
<li>支援 Netflix, Disney+, Youtube, MaruMaru 等網站</li>
<li>支援常用瀏覽器。</li>
<li>自動尋找網頁上的 CC 字幕。</li>
<li>語音與點字回饋。</li>
Expand Down
17 changes: 17 additions & 0 deletions source/doc/zh_TW/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# 更新日誌

## V2.2

### 新增項目

1. 新增 Netflix 字幕支援。
測試影片:[庫洛魔法使:透明牌篇 - 小櫻和兔子和月之歌](https://www.netflix.com/watch/80995962?trackId=14170289&tctx=2%2C0%2C9ef5c8f2-42a7-433c-9f56-f808e8b08534-153578124%2C49eb2250-db6e-40ea-81e1-f499f5f033ee_218390925X3XX1647885067214%2C49eb2250-db6e-40ea-81e1-f499f5f033ee_ROOT%2C%2C%2C)
P.S 透明牌篇之後的內容啥時候要出啦啦啦!

### 修改項目

1. 啟動時檢查更新:改為自動檢查更新,其行為除了在字幕閱讀器啟動時檢查更新,同時也在一天後再次檢查更新。
但若一天後的最新版本與啟動時檢查的最新版本相同,則不再詢問使用者是否需要更新。

---

## V2.11

### 新增項目
Expand All @@ -12,6 +27,8 @@
1. 修正 Disney+ 影片播放器全螢幕時不讀字幕的錯誤。
2. 修正 Disney+ 非中文台灣語言介面不讀字幕的錯誤。

---

## V2.1, 2022.02.01

### 新增項目
Expand Down
2 changes: 1 addition & 1 deletion source/doc/zh_TW/readme.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ <h2 id="introduction">簡介</h2>
<h2 id="description">說明</h2>
<h3 id="features">特色</h3>
<ul>
<li>支援 Disney+, Youtube, MaruMaru 等網站</li>
<li>支援 Netflix, Disney+, Youtube, MaruMaru 等網站</li>
<li>支援常用瀏覽器。</li>
<li>自動尋找網頁上的 CC 字幕。</li>
<li>語音與點字回饋。</li>
Expand Down
6 changes: 4 additions & 2 deletions source/globalPlugins/subtitle_reader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .youtube import Youtube
from .maru_maru import MaruMaru
from .disney_plus import DisneyPlus
from .netflix import Netflix
from .update import Update

wx = gui.wx
Expand All @@ -30,6 +31,7 @@ def __init__(self, *args, **kwargs):
'.+ - YouTube': Youtube(self),
'.+-MARUMARU': MaruMaru(self),
'^Disney\+ \| ': DisneyPlus(self),
'^Netflix': Netflix(self),
}
self.subtitleAlg = None
self.supportedBrowserAppNames = ('chrome', 'brave', 'firefox', 'msedge')
Expand All @@ -50,10 +52,10 @@ def initMenu(self):
gui.tray.Bind(gui.wx.EVT_MENU, self.script_toggleSwitch, menu.switch)
gui.tray.Bind(gui.wx.EVT_MENU, self.toggleInfoCardPrompt, menu.infoCardPrompt)
gui.tray.Bind(gui.wx.EVT_MENU, self.update.manualCheck, menu.checkForUpdate)
gui.tray.Bind(gui.wx.EVT_MENU, self.update.toggleCheckOnStartup, menu.checkUpdateOnStartup)
gui.tray.Bind(gui.wx.EVT_MENU, self.update.toggleCheckAutomatic, menu.checkUpdateAutomatic)
menu.switch.Check(conf['switch'])
menu.infoCardPrompt.Check(conf['infoCardPrompt'])
menu.checkUpdateOnStartup.Check(conf['checkUpdateOnStartup'])
menu.checkUpdateAutomatic.Check(conf['checkUpdateAutomatic'])

def terminate(self):
# 關閉 NVDA 時,儲存開關狀態到使用者設定檔。
Expand Down
2 changes: 1 addition & 1 deletion source/globalPlugins/subtitle_reader/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Config(dict):
def load(self, fileName):
self.fileName = fileName
# 讓預設值為 True
self.update({'switch': True, 'infoCardPrompt': True, 'checkUpdateOnStartup': True, 'skipVersion': '0'})
self.update({'switch': True, 'infoCardPrompt': True, 'checkUpdateAutomatic': True, 'skipVersion': '0'})
# 從使用者設定檔取得開關狀態
try:
with codecs.open(fileName) as file:
Expand Down
4 changes: 2 additions & 2 deletions source/globalPlugins/subtitle_reader/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ def __init__(self):

self.checkForUpdate = self.Append(wx.ID_ANY, u'立即檢查更新(&C)')

self.checkUpdateOnStartup = self.AppendCheckItem(wx.ID_ANY, u'啟動時檢查更新(&A)')
self.checkUpdateOnStartup.Check(True)
self.checkUpdateAutomatic = self.AppendCheckItem(wx.ID_ANY, u'啟動時檢查更新(&A)')
self.checkUpdateAutomatic.Check(True)


class UpdateDialog(wx.Dialog):
Expand Down
44 changes: 44 additions & 0 deletions source/globalPlugins/subtitle_reader/netflix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#coding=utf-8

from .subtitle_alg import SubtitleAlg
from .object_finder import find

class Netflix(SubtitleAlg):
def getVideoPlayer(self):
obj = self.main.focusObject
return find(obj, 'parent', 'role', 52)

def getSubtitleContainer(self):
videoPlayer = self.main.videoPlayer
appName = videoPlayer.appModule.appName
return getattr(self, appName + 'GetSubtitleContainer')()

def chromeGetSubtitleContainer(self):
obj = self.main.videoPlayer
obj = find(obj, 'firstChild', 'role', 56)
return obj

def firefoxGetSubtitleContainer(self):
obj = self.main.videoPlayer
obj = find(obj, 'firstChild', 'role', 56)
return obj

def getSubtitle(self):
subtitle = ''
obj = self.main.subtitleContainer
obj = obj.next
while obj and not obj.name:
try:
obj = obj.firstChild
except:
obj = None


while obj:
if obj.name:
subtitle += obj.name + '\r\n'

obj = obj.next

return subtitle

6 changes: 5 additions & 1 deletion source/globalPlugins/subtitle_reader/object_finder.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
from logHandler import log

def find(obj, nextAttr, attrName, attrValue):
o = obj
while o:
value = getattr(o, attrName, None)
if not value:
try:
value = o.IA2Attributes[attrName]
value = o.IA2Attributes.get(attrName)
except:
pass


if value == attrValue:
log.debug(attrName + ' = ' + str(attrValue) + ' found. ')
return o

o = getattr(o, nextAttr)

log.debug(attrName + ' = ' + str(attrValue) + ' not found. ')
36 changes: 20 additions & 16 deletions source/globalPlugins/subtitle_reader/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,56 +24,60 @@

class Update:
def __init__(self):
self.new = {}
self.checkThreadObj = None
self.dialog = None
self.downloadThreadObj = None
self.checkOnStartup()
self.checkAutomatic()

def checkOnStartup(self):
if not conf['checkUpdateOnStartup']:
def checkAutomatic(self):
if not conf['checkUpdateAutomatic']:
return

self.execute(onStartup=True)
self.execute(automatic=True)
self.automaticTimer = wx.PyTimer(self.checkAutomatic)
self.automaticTimer.StartOnce(1000*60*60*24)

def manualCheck(self, event):
conf['skipVersion'] = '0'
play(soundPath + r'\updateChecking.wav')
self.execute()

def toggleCheckOnStartup(self, event):
def toggleCheckAutomatic(self, event):
menu = event.GetEventObject()
id = menu.FindItem(u'啟動時檢查更新(&A)')
item = menu.FindItemById(id)
status = conf['checkUpdateOnStartup'] = not conf['checkUpdateOnStartup']
status = conf['checkUpdateAutomatic'] = not conf['checkUpdateAutomatic']
item.Check(status)

def execute(self, onStartup=False):
def execute(self, automatic=False):
if self.checkThreadObj and self.checkThreadObj.is_alive():
return

if self.dialog:
return

self.checkThreadObj = Thread(target=self.checkThread, kwargs={'onStartup': onStartup})
self.checkThreadObj = Thread(target=self.checkThread, kwargs={'automatic': automatic})
self.checkThreadObj.start()

def checkThread(self, onStartup=False):
info = self.newVersion = self.getNewVersion()
def checkThread(self, automatic=False):
info = self.getNewVersion()
if not info:
if not onStartup:
if not automatic:
wx.CallAfter(self.isLatestVersion)

return

if info['error']:
if not onStartup:
if not automatic:
wx.CallAfter(self.checkError)

return

if onStartup and info['version'] == conf['skipVersion']:
if automatic and (info['version'] == conf['skipVersion'] or self.new.get('version') == info['version']):
return

self.new = info
play(soundPath + r'\newVersionFound.wav')
wx.CallAfter(self.showDialog)

Expand Down Expand Up @@ -112,8 +116,8 @@ def checkError(self):
wx.MessageBox(u'檢查更新失敗', '錯誤', style=wx.ICON_ERROR)

def showDialog(self):
dlg = self.dialog = UpdateDialog(self.newVersion['version'])
dlg.changelogText.SetValue(self.newVersion['changelog'])
dlg = self.dialog = UpdateDialog(self.new['version'])
dlg.changelogText.SetValue(self.new['changelog'])
dlg.updateNow.Bind(wx.EVT_BUTTON, self.updateNow)
dlg.skipVersion.Bind(wx.EVT_BUTTON, self.skipVersion)
dlg.later.Bind(wx.EVT_BUTTON, self.later)
Expand Down Expand Up @@ -152,7 +156,7 @@ def downloadError(self):

def skipVersion(self, event):
play(soundPath + r'\skipVersion.wav')
conf['skipVersion'] = self.newVersion['version']
conf['skipVersion'] = self.new['version']
self.dialog.Close()

def later(self, event):
Expand Down
2 changes: 1 addition & 1 deletion source/manifest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ summary = 字幕閱讀器
description = "當焦點位於網頁上的影片撥放器時,讓 NVDA 讀出字幕。"
author = "謝福恩 <[email protected]>"
url = https://github.com/maxe-hsieh/subtitle_reader
version = 2.11
version = 2.2
docFileName = readme.html
lastTestedNVDAVersion = 2021.3.1

0 comments on commit abff34e

Please sign in to comment.