Update to fix time extraction

Replaced inconsistent regular expression evaluation with string based operation.
This commit is contained in:
Jayapraveen 2021-04-30 18:52:37 +05:30
parent d5fbdf10f4
commit 2b83a1536a

View File

@ -1,5 +1,5 @@
#dashdrmmultisegmentdownloader #dashdrmmultisegmentdownloader
import os,requests,shutil,json,glob,re import os,requests,shutil,json,glob
from mpegdash.parser import MPEGDASHParser from mpegdash.parser import MPEGDASHParser
from mpegdash.nodes import Descriptor from mpegdash.nodes import Descriptor
from mpegdash.utils import ( from mpegdash.utils import (
@ -14,7 +14,7 @@ working_dir = os.getcwd() + "\working_dir" # set the folder to download ephemera
keyfile_path = download_dir + "\keyfile_test.json" keyfile_path = download_dir + "\keyfile_test.json"
if not os.path.exists(working_dir): if not os.path.exists(working_dir):
os.makedirs() os.makedirs(working_dir)
#Get the keys #Get the keys
with open(keyfile_path,'r') as keyfile: with open(keyfile_path,'r') as keyfile:
@ -45,20 +45,15 @@ Descriptor.__init__ = __init__
Descriptor.parse = parse Descriptor.parse = parse
Descriptor.write = write Descriptor.write = write
#Compiled regex time
days = re.compile("([\d.]+)D")
hours = re.compile("([\d.]+)H")
minutes = re.compile("([\d.]+)M")
seconds = re.compile("([\d.]+)S")
def durationtoseconds(period): def durationtoseconds(period):
#Duration format in PTxDxHxMxS #Duration format in PTxDxHxMxS
if(period[:2] == "PT"): if(period[:2] == "PT"):
period = period[2:] period = period[2:]
day = int(days.match(period).group(1)) if days.match(period) else 0 # Probably never happens day = int(period.split("D")[0] if 'D' in period else 0)
hour = int(hours.match(period).group(1)) if hours.match(period) else 0 hour = int(period.split("H")[0].split("D")[-1] if 'H' in period else 0)
minute = int(minutes.match(period).group(1)) if minutes.match(period) else 0 minute = int(period.split("M")[0].split("H")[-1] if 'M' in period else 0)
second = seconds.match(period).group(1) second = period.split("S")[0].split("M")[-1]
print(day,hour,minute,second)
total_time = float(str((day * 24 * 60 * 60) + (hour * 60 * 60) + (minute * 60) + (int(second.split('.')[0]))) + '.' + str(int(second.split('.')[-1]))) total_time = float(str((day * 24 * 60 * 60) + (hour * 60 * 60) + (minute * 60) + (int(second.split('.')[0]))) + '.' + str(int(second.split('.')[-1])))
return total_time return total_time