# Copyright (C) 2024 Lunatixz
#
#
# This file is part of PseudoTV Live.
#
# PseudoTV Live Live is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# PseudoTV Live Live is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with PseudoTV Live Live. If not, see .
from globals import *
class NFOParser:
## NFO EXAMPLE ##
##
## 25
## 1575
##
##
##
##
##
##
def determineLength(self, filename: str) -> int and float:
duration = 0
fleName, fleExt = os.path.splitext(filename)
fleName += '.nfo'
if not FileAccess.exists(fleName):
log("NFOParser: Unable to locate NFO %s"%(fleName), xbmc.LOGERROR)
return 0
log("NFOParser: determineLength, file = %s, nfo = %s"%(filename,fleName))
try:
File = FileAccess.open(fleName, "rb")
dom = parse(File)
File.close()
except:
log("NFOParser: Unable to open the file %s"%(fleName), xbmc.LOGERROR)
return duration
try:
xmldurationinseconds = dom.getElementsByTagName('durationinseconds')[0].toxml()
duration = int(xmldurationinseconds.replace('','').replace('',''))
except Exception as e:
log("NFOParser: not found")
if duration == 0:
try:
xmlruntime = dom.getElementsByTagName('runtime')[0].toxml()
duration = int(xmlruntime.replace('','').replace('','').replace(' min.','')) * 60
except Exception as e:
log("NFOParser: not found")
if duration == 0:
try:
xmlruntime = dom.getElementsByTagName('duration')[0].toxml()
duration = int(xmlruntime.replace('','').replace('','')) * 60
except Exception as e:
log("NFOParser: not found")
log("NFOParser: Duration is %s"%(duration))
return duration