Skip to content

Commit

Permalink
Updated to 2.32
Browse files Browse the repository at this point in the history
  • Loading branch information
Maxe committed May 22, 2022
1 parent b5d0f36 commit 619bb5e
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 8 deletions.
15 changes: 15 additions & 0 deletions source/doc/zh_TW/changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# 更新日誌

## V2.32, 2022.5.22

### 新增項目

1. 現在可以從《字幕閱讀器》功能表開啟更新日誌檔案,預防更新時沒看到日誌的狀況。

### 修正巷木

1. 在以下影片發現字幕被重複朗讀的問題,原因是此影片連續出現兩次多行字幕,而兩次出現的字幕,個只有其中一行相同而沒有忽略相同內容所導致。
所以現在起,加入使用字幕的每一行來尋找相同點的功能。
影片:[《 Embrace 》 復甦島2主題曲 Official Music Video|Leggy、Paroto|玩樂幫](https://www.youtube.com/watch?v=lc7mhbfg5sY&ab_channel=%E7%8E%A9%E6%A8%82%E5%B9%AB)
P.S: 追隨卡蜜拉

---

## V2.31, 2022.4.4

### 新增項目
Expand Down
71 changes: 67 additions & 4 deletions source/globalPlugins/subtitle_reader/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ 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.openChangeLog, menu.openChangeLog)
gui.tray.Bind(gui.wx.EVT_MENU, self.update.toggleCheckAutomatic, menu.checkUpdateAutomatic)
menu.switch.Check(conf['switch'])
menu.infoCardPrompt.Check(conf['infoCardPrompt'])
Expand Down Expand Up @@ -153,17 +154,79 @@ def read_subtitle(self):
return

msg = subtitle
# 若新的字幕內容是前一字幕開頭的一部分,則不報讀。
if self.subtitle.find(subtitle) == 0 and subtitle in self.subtitle:

# 若新的字幕內容是前一字幕的一部分,則不報讀。
if subtitle in self.subtitle:
msg = None

# 若新的字幕開頭為前一字幕的內容,則只報讀填充的部分。
if self.subtitle and subtitle.find(self.subtitle) == 0 and self.subtitle in subtitle:
# 若新的字幕包含前一字幕的內容,則只報讀填充的部分。
if self.subtitle and self.subtitle in subtitle:
msg = subtitle.replace(self.subtitle, '', 1)

split = self.subtitle.split('\r\n')
for part in split:
if part in msg:
msg = msg.replace(part, '')


ui.message(msg)
self.subtitle = subtitle

def getStartOrEndSameStr(self, a, b):
def getStartSameStr(a, b):
same = []
for i in range(0, len(a)):
if a[i] != b[i:i+1]:
break

same.append(a[i])

return ''.join(same)

sameStr = ['', '', '', '']
maxLen = 0
maxLenIndex = -1
if a[0:1] == b[0:1]:
s = getStartSameStr(a, b)
sameStr[0] = s
maxLen = len(s)
maxLenIndex = 0

n = a.rfind(b[-1:])
if n >= 0:
if a[:n+1] == b[n*-1-1:]:
sameStr[1] = a[:n+1]
if len(sameStr[1]) > maxLen:
maxLen = len(sameStr[1])
maxLenIndex = 1



a = a[::-1]
b = b[::-1]

if a[0:1] == b[0:1]:
s = getStartSameStr(a, b)
sameStr[2] = s[::-1]
if len(sameStr[2]) > maxLen:
maxLen = len(s)
maxLenIndex = 0

n = a.find(b[-1:])
if n >= 0:
if a[:n+1] == b[n*-1-1:]:
sameStr[3] = a[:n+1:-1][::-1]
if len(sameStr[1]) > maxLen:
maxLen = len(sameStr[1])
maxLenIndex = 1



if maxLenIndex == -1:
return ''

return sameStr[maxLenIndex]

def toggleInfoCardPrompt(self, evt):
conf['infoCardPrompt'] = not conf['infoCardPrompt']
self.menu.infoCardPrompt.Check(conf['infoCardPrompt'])
Expand Down
2 changes: 2 additions & 0 deletions source/globalPlugins/subtitle_reader/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def __init__(self):

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

self.openChangeLog = self.Append(wx.ID_ANY, u'開啟更新日至(&O)')

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

Expand Down
5 changes: 5 additions & 0 deletions source/globalPlugins/subtitle_reader/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from .version import version
from .config import conf
from .gui import UpdateDialog, wx
from globalVars import appArgs

soundPath = os.path.dirname(__file__) + r'\sounds'
sourceUrl = 'https://raw.githubusercontent.com/maxe-hsieh/subtitle_reader/main/source'
Expand Down Expand Up @@ -43,6 +44,10 @@ def manualCheck(self, event):
play(soundPath + r'\updateChecking.ogg')
self.execute()

def openChangeLog(self, event):
filePath = appArgs.configPath + r'\addons\subtitle_reader\doc\zh_TW\changelog.md'
os.system('start ' + filePath)

def toggleCheckAutomatic(self, event):
menu = event.GetEventObject()
id = menu.FindItem(u'啟動時檢查更新(&A)')
Expand Down
6 changes: 3 additions & 3 deletions source/globalPlugins/subtitle_reader/youtube.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ def chromeGetSubtitle(self):
return ''

subtitle = ''
obj = obj.firstChild
while obj is not None and 'caption-window-' in str(obj.IA2Attributes.get('id')):
obj = obj.firstChild.firstChild
while obj is not None:
# 取得多行字幕
if obj.name.strip() != subtitle.strip():
if obj.name.strip():
subtitle += obj.name + '\r\n'

obj = obj.next
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.31
version = 2.32
docFileName = readme.html
lastTestedNVDAVersion = 2022.1

0 comments on commit 619bb5e

Please sign in to comment.