msg = 'Starting xml update in '.format(updatexmlwatched)
Debug(msg)
pchtrakt.logger.info(msg)
if pchtrakt.isMovie:
xmlpath = updatexmlwatched + "Other*.xml"
for name in glob.glob(xmlpath):
if myMedia.oStatus.fileName[:-4] in open(name).read():#gets xml file name as name
tree = ElementTree.parse(name)
for movie in tree.findall('movies/movie'):
if movie.find('baseFilenameBase').text == myMedia.oStatus.fileName[:-4]:#for content in penContents:
movie.find('watched').text = 'true'
for mfile in movie.findall('files/file'):
mfile.set('watched', 'true')
bak_name = name[:-4]+'.bak'
tree.write(bak_name)
os.rename(bak_name, name)
txt = name.replace(updatexmlwatched, '') + ' has been modified as watched for ' + myMedia.oStatus.fileName
Debug(txt)
pchtrakt.logger.info(txt)
break
elif pchtrakt.isTvShow:
a = re.split("([-|.]*[Ss]\\d\\d[Ee]\\d\\d.)", myMedia.oStatus.fileName)
ep_name = a[2][:-4].replace(".", " ").replace("- ", "")
season_xml = a[0][:-3].replace(".", " ").replace(" - ", "")
f_size = str(os.path.getsize(myMedia.oStatus.fullPath))
ep_no = '01'
fileinfo = updatexmlwatched + "Set_" + season_xml + "*.xml"
for name in glob.glob(fileinfo):
if myMedia.oStatus.fileName in open(name).read():
tree = ElementTree.parse(name)
for movie in tree.findall('*/movie/files/file'):
if movie.get('firstPart') == str(myMedia.parsedInfo.episode_numbers[myMedia.idxEpisode]) and movie.get('season') == str(myMedia.parsedInfo.season_number):
movie.set('watched', 'true')
bak_name = name[:-4]+'.bak'
tree.write(bak_name)
os.rename(bak_name, name)
txt = name.replace(updatexmlwatched, '') + ' has been modified as watched for ' + myMedia.oStatus.fileName
Debug(txt)
pchtrakt.logger.info(txt)
break
fileinfo = updatexmlwatched + "Other*.xml"
for name in glob.glob(fileinfo):
if myMedia.oStatus.fileName in open(name).read():
tree = ElementTree.parse(name)
for movie in tree.findall('*/movie/files/file'):
if movie.get('size') == f_size and movie.get('firstPart') == str(myMedia.parsedInfo.episode_numbers[myMedia.idxEpisode]) and movie.get('season') == str(myMedia.parsedInfo.season_number):
movie.set('watched', 'true')
bak_name = name[:-4]+'.bak'
tree.write(bak_name)
os.rename(bak_name, name)
txt = name.replace(updatexmlwatched, '') + ' has been modified as watched for ' + myMedia.oStatus.fileName
Debug(txt)
pchtrakt.logger.info(txt)
break
这就是我最终的结果。它确实有效,但如果 xml 在网络共享上,有时会导致正在播放的媒体卡顿。我相信它正在搜索包含变量的 xml 时发生。在低功耗媒体播放器上运行时,是否有一种不那么耗费系统的方式来执行此操作。
谢谢