def DeleteImageRendition(ImageRendition=None): if ImageRendition is not None: image_path = models.GetPath("image_local_path") print ("DeleteImageRendition(): Delete Image rendition file Name: %s" % ImageRendition.file_name) try: os.unlink(image_path + '/' + ImageRendition.file_name) except: print ("ERROR: DeleteVideoRendition(): Unable to delete file: %s" % ImageRendition.file_name) ImageRendition.delete()
def DeleteVideoRendition(VideoRendition=None): if VideoRendition is not None: video_path = models.GetPath("video_local_path") print ("DeleteVideoRendition(): Delete video rendition file Name: %s" % VideoRendition.file_name) try: os.unlink(video_path + '/' + VideoRendition.file_name) except: print ("ERROR: DeleteVideoRendition(): Unable to delete file: %s" % VideoRendition.file_name) VideoRendition.delete()
def Main(): while True: path = models.GetPath("video_local_path") list = os.listdir(path) for file in list: if not file.startswith('PREVIEW_'): try: models.VideoRendition.objects.get(file_name=file) except: print file os.unlink(path + '/'+file) time.sleep(1296000)
def DeleteVideoRendition(item=None): if item is not None: logging.info("DeleteVideoRendition(): Item: %s" % item.name) VideoRendition = models.VideoRendition.objects.filter(item=item) video_path = models.GetPath("video_local_path") for VRendition in VideoRendition: logging.info( "DeleteVideoRendition(): Delete video rendition file Name: %s" % VRendition.file_name) try: os.unlink(video_path + '/' + VRendition.file_name) except: logging.error( "DeleteVideoRendition(): Unable to delete file: %s" % VRendition.file_name) VRendition.delete()
def DeleteImageRendition(item=None): if item is not None: logging.info("DeleteImageRendition(): Item: %s" % item.name) ImageRendition = models.ImageRendition.objects.filter(item=item) image_path = models.GetPath("image_local_path") for IRendition in ImageRendition: logging.info( "DeleteImageRendition(): Delete Image rendition file Name: %s" % IRendition.file_name) try: os.unlink(image_path + '/' + IRendition.file_name) except: logging.error( "DeleteImageRendition(): Unable to delete file: %s" % IRendition.file_name) IRendition.delete()
def CancelVideoRenditions(): logging.info("CancelVideoRendition(): Start Canceling Video Rendition") video_local_path = models.GetPath("video_local_path") if video_local_path is None: logging.error("CanceVideoRenditions(): Config Error, video_local_path not defined") return False logging.debug("CancelVideoRenditions(): video_local_path: " + video_local_path) # # Agrega / si no es que exite al final # if not video_local_path.endswith('/'): video_local_path = video_local_path + '/' for VRendition in models.VideoRendition.objects.filter(status='C'): JobState, Progress = GetJobState(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) logging.info("GetJobState(): Job Progress: " + str(Progress)) logging.info("GetJobState(): Job State: " + JobState) if JobState == 'NEX_JOB_COMPLETED': # # Si el Job termino de procesarse # logging.info("CancelVideoRenditions(): Video Rendition finish transcoding: -> Unlink: " + VRendition.file_name) os.unlink(video_local_path + VRendition.file_name) else: logging.info("CancelVideoRenditions(): Stopping Job: " + VRendition.transcoding_job_guid + " Server: " + VRendition.transcoding_server_ip_address ) StopJob(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) VRendition.delete()
def DeleteRenditionQueue(item=None): if item is not None: logging.info("DeleteRenditionQueue(): Item: %s" % item.name) RenditionQueue = models.RenditionQueue.objects.filter(item=item) for RQueue in RenditionQueue: if RQueue.local_file == 'Y': path = models.GetPath("local_master_path") if not path.endswith('/'): path = path + '/' try: os.unlink(path + RQueue.file_name) except: logging.error( "DeleteRenditionQueue(): Unable to delete file: %s" % path + RQueue.file_name) logging.info("DeleteRenditionQueue(): ID: " + str(RQueue.id)) RQueue.delete()
def makeImageRendition(irm): sufix = irm.image_profile.sufix.replace('_', '') plist = getImageProfiles(sufix) ir = getImageRendition(plist, irm.item) if irm.status != 'F': return srcpath = models.GetPath('image_local_path') if not srcpath.endswith('/'): srcpath = srcpath + '/' basename = splitExtension(irm.file_name) bitmapname = str(splitExtension(irm.file_name) + '.bmp') ret = derivatebitmap(srcpath + irm.file_name, srcpath + bitmapname) for image_rendition in ir: dst_file = basename + image_rendition.image_profile.sufix + '.' + image_rendition.image_profile.file_extension if image_rendition.image_profile.format == 'SD': ret = scaleImage( srcpath + irm.file_name, image_rendition.image_profile.image_aspect_ratio.replace( 'x', ':').replace(' ', ''), srcpath + dst_file) if (ret == True): image_rendition.file_name = dst_file image_rendition.status = 'F' image_rendition.save() elif image_rendition.image_profile.format == 'HD': # # Genera la imagen derivada # if image_rendition.image_profile.language == 'P': bmp = PyBitMap.PyBitMap() logo = PyBitMap.PyBitMap() print srcpath + bitmapname bmp.load(str(srcpath + bitmapname)) if sufix.startswith('H'): logo.load(LOGOPATH + 'HHDPO.bmp') x = 0 y = 0 else: logo.load(LOGOPATH + 'VHDPO.bmp') x = 0 y = 0 else: bmp = PyBitMap.PyBitMap() logo = PyBitMap.PyBitMap() bmp.load(str(srcpath + bitmapname)) if sufix.startswith('H'): logo.load(LOGOPATH + 'HHD.bmp') x = 570 y = 20 else: logo.load(LOGOPATH + 'VHD.bmp') x = 600 y = 20 bmp.overlap(logo, x, y) bmp.save(str(srcpath + bitmapname)) ret = scaleImage( srcpath + bitmapname, image_rendition.image_profile.image_aspect_ratio.replace( 'x', ':').replace(' ', ''), srcpath + dst_file) if (ret == True): image_rendition.file_name = dst_file image_rendition.status = 'F' image_rendition.save() irm.status = 'D' irm.save()
def ReScheduleUnasignedRenditions(ForceSchedule=False): global ErrorString ErrorString = '' logging.info( "ReSheduleUnasignedRenditions(): Start Checking Unassingned Video Renditions" ) # # Trae todas las Video Renditions que no fueron Asignadas # UVRenditions = models.GetVideoRenditionUnassigned() if len(UVRenditions) > 0: # # Si hay Elementos en la Cola # # 1- Inicia el carbon Pool # logging.info( "ReSheduleUnasignedRenditions(): Init Transcoding server pool") CPool = InitCarbonPool() while CPool is None: logging.info( "ReSheduleUnasignedRenditions(): No transcoding server configured in database... Sleep" ) time.sleep(10) CPool = InitCarbonPool() for VRendition in UVRenditions: # # Arma los parametros de transcodificacion # logging.info("ReSheduleUnasignedRenditions(): -----") logging.info( "ReSheduleUnasignedRenditions(): VideoRendition ID: %d" % VRendition.id) logging.info( "ReSheduleUnasignedRenditions(): Item -> [%s], VideoProfile -> [%s]" % (VRendition.item.name, VRendition.video_profile.name)) # # Arma los parametros de transcodificacion # # if len(VRendition.item.internal_brand.logo.filter(format=VRendition.video_profile.format)) != 0: # Logo = VRendition.item.internal_brand.logo.filter(format=VRendition.video_profile.format) if len( VRendition.item.brand.logo.filter( format=VRendition.video_profile.format)) != 0: Logo = VRendition.item.brand.logo.filter( format=VRendition.video_profile.format) BitMap = BitmapKeying() BitMap.Filename = Logo[0].filename BitMap.Dialog_BIN = Logo[0].dialog BitMap.Position_DWD = Logo[0].position BitMap.Scale_DBL = Logo[0].scale BitMap.Offset_DBL = Logo[0].offset BitMap.Opacity_DBL = Logo[0].opacity logging.info( "ReScheduleUnasignedRenditions(): Adding logo: %s (%s)" % (Logo[0].name, Logo[0].filename)) if VRendition.subtitle_burned == 'N': TranscodeInfo = { 'd_guid': VRendition.video_profile.guid, 'd_basename': SplitExtension(VRendition.file_name), 'd_path': models.GetPath("video_smb_path"), 'logo': BitMap.ToElement() } else: try: subtitle_profile = models.SubtitleProfile.objects.get( format=VRendition.video_profile.format) except: logging.error = "ReSecheduleUnassignedVideoRenditions(): Unable to get SubtitleProfile in %s" % ( VRendition.video_profile.format) ErrorString = "Unable to get SubtitleProfile in %s" % ( VRendition.video_profile.format) return False XmlTitlerElement = StlToXmlTitler(subtitle_profile, VRendition.sub_file_name) TranscodeInfo = { 'd_guid': VRendition.video_profile.guid, 'd_basename': SplitExtension(VRendition.file_name), 'd_path': models.GetPath("video_smb_path"), 'subtitle': XmlTitlerElement.ToElement(), 'logo': BitMap.ToElement() } else: if VRendition.subtitle_burned == 'N': TranscodeInfo = { 'd_guid': VRendition.video_profile.guid, 'd_basename': SplitExtension(VRendition.file_name), 'd_path': models.GetPath("video_smb_path") } else: try: subtitle_profile = models.SubtitleProfile.objects.get( format=VRendition.video_profile.format) except: logging.error = "ReSecheduleUnassignedVideoRenditions(): Unable to get SubtitleProfile in %s" % ( VRendition.video_profile.format) ErrorString = "Unable to get SubtitleProfile in %s" % ( VRendition.video_profile.format) return False XmlTitlerElement = StlToXmlTitler(subtitle_profile, VRendition.sub_file_name) TranscodeInfo = { 'd_guid': VRendition.video_profile.guid, 'd_basename': SplitExtension(VRendition.file_name), 'd_path': models.GetPath("video_smb_path"), 'subtitle': XmlTitlerElement.ToElement() } logging.debug("ReSheduleUnasignedRenditions(): Transcode Info: " + str(TranscodeInfo)) # # Crea el XML con el Job de Transcodificacion # try: XmlJob = CreateCarbonXMLJob(VRendition.src_svc_path, VRendition.src_file_name, [], [TranscodeInfo], None, None) except: e = sys.exc_info()[0] logging.error( "ReSheduleUnasignedRenditions(): 01: Exception making Carbon XML Job. Catch: " + e) ErrorString = '01: Exception making Carbon XML Job. Catch: ' + e return False if XmlJob is None: logging.error( "ReSheduleUnasignedRenditions(): 01: Error making Carbon XML Job" ) ErrorString = '01: Error making Carbon XML Job' return False JobReply = StartJobCarbonPool(CPool, XmlJob, ForceSchedule) if JobReply.Result == True: # # Si puedo Asignarle un Transcoding Server # # 1- Lo Marca como Encolado # 2- Carga en Base de Datos el GUID del Job # 3- Carga el Transcoding Server Asignado # VRendition.status = 'Q' VRendition.transcoding_job_guid = JobReply.Job.GetGUID() try: TServer = models.TranscodingServer.objects.get( ip_address=JobReply.Job.GetCarbonHostname()) logging.info( "ReSheduleUnasignedRenditions(): Carbon Server ->" + TServer.ip_address) except: # # Si no encuentra el transcoding Server Asignado # ErrorString = '02: Can not find the Assigned Carbon Server' logging.error( "ReSheduleUnasignedRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False VRendition.stimestamp = str(int(time.time())) VRendition.transcoding_server = TServer VRendition.save() else: if JobReply.Error == False: logging.info( "ReSheduleUnasignedRenditions(): Can Not Assign Carbon Server ( No one have slots )" ) return True else: ErrorString = '02: Error sending Job' logging.error( "MakeVideoRendition(): 02: Error sending Job") return False logging.info( "ReSheduleUnasignedRenditions(): End Checking Unassingned Video Renditions" ) return True
def MakeVideoRenditions(RenditionTask=None, CPool=None, ForceSchedule=False): # CPool = CarbonPool() global ErrorString ErrorString = '' if RenditionTask is None: logging.error("MakeVideoRenditions(): ImportTask is None") return False try: LocalZone = models.ExportZone.objects.get(zone_name=Zone.LOCAL) Settings = models.Settings.objects.get(zone=LocalZone) except: e = sys.exc_info()[0] d = sys.exc_info()[1] logging.error( "MakeVideoRenditions(): Error in LocalZone / Settings [%s -> %s]" % (e, d)) return False try: Item = RenditionTask.item except: e = sys.exc_info()[0] logging.error( "MakeVideoRenditions(): ImportTask not have an Item. Catch: %s" % e) ErrorString = "ImportTask not have an Item. Catch: %s" % e return False logging.info("MakeVideoRenditions(): Creating video rendition for item: " + Item.name) if Settings.optimize_profiles_with_brand == 'Y': VProfileList_pre = models.GetVideoProfilesBrand(Item.internal_brand) if Item.internal_brand.format == 'HD' and Item.format == 'SD': logging.warning( "MakeVideoRenditions(): Internal Brand is HD but Item format is SD -> Eliminate HD Profiles" ) # # Hay que eliminar los HD # VProfileList = [] for VProfile in VProfileList_pre: if VProfile.format == 'SD': VProfileList.append(VProfile) else: VProfileList = VProfileList_pre else: # # Define que tipos de Video Profiles debe usar # SD o HD # if Item.format == 'HD': VProfileList = models.GetVideoProfiles() elif Item.format == 'SD': VProfileList = models.GetVideoProfiles('SD') if RenditionTask.local_file == 'Y': local_master_path = models.GetPath('local_master_path') if local_master_path is not None: if not local_master_path.endswith('/'): local_master_path = local_master_path + '/' else: ErrorString = "MakeVideoRenditions(): local_master_path is None" logging.error("MakeVideoRenditions(): local_master_path is None") return False else: ErrorString = "MakeVideoRenditions(): local_file is No" logging.error("MakeVideoRenditions(): local_file is No") return False File = RenditionTask.file_name subtitle_local_path = models.GetPath('subtitle_local_path') if subtitle_local_path is not None: if not subtitle_local_path.endswith('/'): subtitle_local_path = subtitle_local_path + '/' # # Por cada video profile crea un video rendition ahora deberia chequear si Tiene subtitulo y si existe el archivo # for VProfile in VProfileList: burn_spa = False burn_prt = False burn_none = False sub_spa = None sub_prt = None if Item.subtitle_spa != '': if FileExist(subtitle_local_path, Item.subtitle_spa): if len( models.Customer.objects.filter( subtitle_language='S', video_profile=VProfile)) > 0: # # Hay almenos un cliente que tiene este video profile con esta opcion de subtitlado # burn_spa = True sub_spa = subtitle_local_path + Item.subtitle_spa else: burn_spa = False else: # # Que hacemos aca? # ErrorString = "MakeVideoRenditions(): Can not Find the file in local_svc_path [%s]" % ( subtitle_local_path + Item.subtitle_spa) logging.error( "MakeVideoRenditions(): Can not Find the file in local_svc_path [%s]" % (subtitle_local_path + Item.subtitle_spa)) return False else: burn_none = True if Item.subtitle_prt != '': if FileExist(subtitle_local_path, Item.subtitle_prt): if len( models.Customer.objects.filter( subtitle_language='P', video_profile=VProfile)) > 0: # # Hay almenos un cliente que tiene este video profile con esta opcion de subtitlado # burn_prt = True sub_prt = subtitle_local_path + Item.subtitle_prt else: burn_prt = False else: # # Que hacemos aca? # ErrorString = "MakeVideoRenditions(): Can not Find the file in local_svc_path [%s]" % ( subtitle_local_path + Item.subtitle_prt) logging.error( "MakeVideoRenditions(): Can not Find the file in local_svc_path [%s]" % (subtitle_local_path + Item.subtitle_prt)) return False else: burn_none = True if len( models.Customer.objects.filter(subtitle_language='N', video_profile=VProfile)) > 0: burn_none = True logging.info("MakeVideoRenditions(): VProfile: " + VProfile.name) TranscodeGuid = VProfile.guid if FileExist(local_master_path, RenditionTask.file_name): logging.info( "MakeVideoRenditions(): File Exist in local_svc_path [%s]" % (local_master_path + RenditionTask.file_name)) Source = GetSmbLocalPath() if Source is None: ErrorString = "MakeVideoRenditions(): Fail in GetSmbLocalPath" logging.error("MakeVideoRenditions(): Fail in GetSmbLocalPath") return False else: ErrorString = "MakeVideoRenditions(): Can not Find the file in local_svc_path [%s]" % ( local_master_path + RenditionTask.file_name) logging.error( "MakeVideoRenditions(): Can not Find the file in local_svc_path [%s]" % (local_master_path + RenditionTask.file_name)) return False logging.info("MakeVideoRenditions(): Source-> " + Source + " File-> " + File) logging.info("MakeVideoRenditions(): VProfileList len: " + str(len(VProfileList))) # # Si existe ya existe un video rendition con ese profile para ese item # no lo procesa y continua con el siguiente profile # if burn_none: if not CheckVideoRendition(Item, VProfile, 'N'): logging.warning( "MakeVideoRendition(): Video Profile exist-> Continue. [VP: %s]" % VProfile.name) burn_none = False if burn_spa: if not CheckVideoRendition(Item, VProfile, 'S'): logging.warning( "MakeVideoRendition(): Video Profile exist-> Continue. [VP: %s - Subtitle: SPA]" % VProfile.name) burn_spa = False if burn_prt: if not CheckVideoRendition(Item, VProfile, 'S'): logging.warning( "MakeVideoRendition(): Video Profile exist-> Continue. [VP: %s - Subtitle: PRT]" % VProfile.name) burn_prt = False if burn_none == False and burn_spa == False and burn_prt == False: continue if burn_none == True: # # Arma el destination filename y el basename # DstFilename = RenditionFileName(File, VProfile.sufix, VProfile.file_extension) if DstFilename is None: logging.error = "MakeVideoRenditions(): 03: Unable stablish DstFileName, [FILE]-> " + File + " ,[SUFIX]-> " + VProfile.sufix ErrorString = "03: Unable stablish DstFileName, [FILE]-> " + File + " ,[SUFIX]-> " + VProfile.sufix return False DstFilename = DstFilename.replace(' ', '') DstFilename = PrefixStrId(Item.id) + '-' + DstFilename #### # Reemplaza los signos de puntuacion por vacio # for c in string.punctuation: if c != '.' and c != '-' and c != '_': DstFilename = DstFilename.replace(c, '') DstBasename = SplitExtension(DstFilename) if DstBasename is None: logging.error = "MakeVideoRenditions(): 04: Unable to stablish DstBasename" ErrorString = "04: Unable stablish DstBasename" return False if burn_spa == True: # # Arma el destination filename y el basename # DstFilename_Spa = RenditionFileName( File, VProfile.sufix + '_' + VProfile.sufix_sub_spa, VProfile.file_extension) if DstFilename_Spa is None: logging.error = "MakeVideoRenditions(): 03: Unable stablish DstFileName_Spa, [FILE]-> " + File + " ,[SUFIX]-> " + VProfile.sufix ErrorString = "03: Unable stablish DstFileName_Spa, [FILE]-> " + File + " ,[SUFIX]-> " + VProfile.sufix return False DstFilename_Spa = DstFilename_Spa.replace(' ', '') DstFilename_Spa = PrefixStrId(Item.id) + '-' + DstFilename_Spa #### # Reemplaza los signos de puntuacion por vacio # for c in string.punctuation: if c != '.' and c != '-' and c != '_': DstFilename_Spa = DstFilename_Spa.replace(c, '') DstBasename_Spa = SplitExtension(DstFilename_Spa) if DstBasename_Spa is None: logging.error = "MakeVideoRenditions(): 04: Unable to stablish DstBasename_Spa" ErrorString = "04: Unable stablish DstBasename" return False try: subtitle_profile = models.SubtitleProfile.objects.get( format=VProfile.format) except: logging.error = "MakeVideoRenditions(): Unable to get SubtitleProfile in %s" % ( VProfile.format) ErrorString = "Unable to get SubtitleProfile in %s" % ( VProfile.format) return False XmlTitlerElementSpa = StlToXmlTitler(subtitle_profile, sub_spa) if burn_prt == True: # # Arma el destination filename y el basename # DstFilename_Prt = RenditionFileName( File, VProfile.sufix + '_' + VProfile.sufix_sub_prt, VProfile.file_extension) if DstFilename_Prt is None: logging.error = "MakeVideoRenditions(): 03: Unable stablish DstFileName_Prt, [FILE]-> " + File + " ,[SUFIX]-> " + VProfile.sufix ErrorString = "03: Unable stablish DstFileName_Prt, [FILE]-> " + File + " ,[SUFIX]-> " + VProfile.sufix return False DstFilename_Prt = DstFilename_Prt.replace(' ', '') DstFilename_Prt = PrefixStrId(Item.id) + '-' + DstFilename_Prt #### # Reemplaza los signos de puntuacion por vacio # for c in string.punctuation: if c != '.' and c != '-' and c != '_': DstFilename_Prt = DstFilename_Prt.replace(c, '') DstBasename_Prt = SplitExtension(DstFilename_Prt) if DstBasename_Prt is None: logging.error = "MakeVideoRenditions(): 04: Unable to stablish DstBasename_Prt" ErrorString = "04: Unable stablish DstBasename_Prt" return False try: subtitle_profile = models.SubtitleProfile.objects.get( format=VProfile.format) except: logging.error = "MakeVideoRenditions(): Unable to get SubtitleProfile in %s" % ( VProfile.format) ErrorString = "Unable to get SubtitleProfile in %s" % ( VProfile.format) return False XmlTitlerElementPrt = StlToXmlTitler(subtitle_profile, sub_prt) # # Arma los parametros de transcodificacion # TranscodeInfo = None TranscodeInfoSpa = None TranscodeInfoPrt = None if len(Item.brand.logo.filter(format=VProfile.format)) != 0: # if len(Item.internal_brand.logo.filter(format=VProfile.format)) != 0: # Logo = Item.internal_brand.logo.filter(format=VProfile.format) Logo = Item.brand.logo.filter(format=VProfile.format) BitMap = BitmapKeying() BitMap.Filename = Logo[0].filename BitMap.Dialog_BIN = Logo[0].dialog BitMap.Position_DWD = Logo[0].position BitMap.Scale_DBL = Logo[0].scale BitMap.Offset_DBL = Logo[0].offset BitMap.Opacity_DBL = Logo[0].opacity logging.info("MakeVideoRenditions(): Adding logo: %s (%s)" % (Logo[0].name, Logo[0].filename)) if burn_none == True: TranscodeInfo = { 'd_guid': TranscodeGuid, 'd_basename': DstBasename, 'd_path': models.GetPath("video_smb_path"), 'logo': BitMap.ToElement() } if burn_spa == True: TranscodeInfoSpa = { 'd_guid': TranscodeGuid, 'd_basename': DstBasename_Spa, 'd_path': models.GetPath("video_smb_path"), 'logo': BitMap.ToElement(), 'subtitle': XmlTitlerElementSpa.ToElement() } if burn_prt == True: TranscodeInfoPrt = { 'd_guid': TranscodeGuid, 'd_basename': DstBasename_Prt, 'd_path': models.GetPath("video_smb_path"), 'logo': BitMap.ToElement(), 'subtitle': XmlTitlerElementPrt.ToElement() } else: if burn_none == True: TranscodeInfo = { 'd_guid': TranscodeGuid, 'd_basename': DstBasename, 'd_path': models.GetPath("video_smb_path") } if burn_spa == True: TranscodeInfoSpa = { 'd_guid': TranscodeGuid, 'd_basename': DstBasename_Spa, 'd_path': models.GetPath("video_smb_path"), 'subtitle': XmlTitlerElementSpa.ToElement() } if burn_prt == True: TranscodeInfoPrt = { 'd_guid': TranscodeGuid, 'd_basename': DstBasename_Prt, 'd_path': models.GetPath("video_smb_path"), 'subtitle': XmlTitlerElementPrt.ToElement() } logging.debug("MakeVideoRenditions(): Transcode Info: " + str(TranscodeInfo)) logging.debug("MakeVideoRenditions(): Transcode Info Spa: " + str(TranscodeInfoSpa)) logging.debug("MakeVideoRenditions(): Transcode Info Prt: " + str(TranscodeInfoPrt)) # # Envia el Job a transcodificar # XmlJob = None XmlJobSpa = None XmlJobPrt = None try: if burn_none == True: XmlJob = CreateCarbonXMLJob(Source, File, [], [TranscodeInfo], None, None) if burn_spa == True: XmlJobSpa = CreateCarbonXMLJob(Source, File, [], [TranscodeInfoSpa], None, None) if burn_prt == True: XmlJobPrt = CreateCarbonXMLJob(Source, File, [], [TranscodeInfoPrt], None, None) except: e = sys.exc_info()[0] logging.error( "MakeVideoRendition(): 01: Exception making Carbon XML Job. Catch: " + e) ErrorString = '01: Exception making Carbon XML Job. Catch: ' + e if burn_none == True and XmlJob is None: logging.error( "MakeVideoRendition(): 01: Error making Carbon XML Job") ErrorString = '01: Error making Carbon XML Job' return False if burn_spa == True and XmlJobSpa is None: logging.error( "MakeVideoRendition(): 01: Error making Carbon XML Job Spa") ErrorString = '01: Error making Carbon XML Job' return False if burn_prt == True and XmlJobPrt is None: logging.error( "MakeVideoRendition(): 01: Error making Carbon XML Job Prt") ErrorString = '01: Error making Carbon XML Job' return False if burn_none == True: JobReply = StartJobCarbonPool(CPool, XmlJob, ForceSchedule) VRendition = models.VideoRendition() VRendition.file_name = DstFilename VRendition.src_file_name = File VRendition.src_svc_path = Source VRendition.video_profile = VProfile VRendition.item = Item VRendition.subtitle_burned = 'N' VRendition.subtitle_language = 'N' if Item.format == 'HD': if VProfile.format == 'HD': VRendition.screen_format = 'Widescreen' else: VRendition.screen_format = 'Letterbox' elif Item.format == 'SD': VRendition.screen_format = 'Standard' if JobReply.Result == True: # # Crea el Video Rendition en el modelo # VRendition.transcoding_job_guid = JobReply.Job.GetGUID() VRendition.stimestamp = str(int(time.time())) VRendition.status = 'Q' # Queued try: TServer = models.TranscodingServer.objects.get( ip_address=JobReply.Job.GetCarbonHostname()) VRendition.transcoding_server = TServer logging.info("MakeVideoRenditions(): Carbon Server ->" + VRendition.transcoding_server.ip_address) except: logging.error( "MakeVideoRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False else: if JobReply.Error == False and ForceSchedule == False: # # No lo pudo planificar porque no hay ningun Carbon Coder Disponible # VRendition.transcoding_job_guid = '' VRendition.status = 'U' # Unasigned try: TServer = models.TranscodingServer.objects.get( ip_address='(Dummy)') VRendition.transcoding_server = TServer logging.info( "MakeVideoRenditions(): Carbon Server ->" + VRendition.transcoding_server.ip_address) except: logging.error( "MakeVideoRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False logging.info( "MakeVideoRenditions(): Can Not Assign Carbon Server (No one have slots )" ) else: ErrorString = '02: Error sending Job' logging.error( "MakeVideoRendition(): 02: Error sending Job") return False time.sleep(0.5) VRendition.save() if burn_spa == True: JobReply = StartJobCarbonPool(CPool, XmlJobSpa, ForceSchedule) VRendition = models.VideoRendition() VRendition.file_name = DstFilename_Spa VRendition.src_file_name = File VRendition.src_svc_path = Source VRendition.video_profile = VProfile VRendition.sub_file_name = sub_spa VRendition.item = Item VRendition.subtitle_burned = 'Y' VRendition.subtitle_language = 'S' if Item.format == 'HD': if VProfile.format == 'HD': VRendition.screen_format = 'Widescreen' else: VRendition.screen_format = 'Letterbox' elif Item.format == 'SD': VRendition.screen_format = 'Standard' if JobReply.Result == True: # # Crea el Video Rendition en el modelo # VRendition.transcoding_job_guid = JobReply.Job.GetGUID() VRendition.stimestamp = str(int(time.time())) VRendition.status = 'Q' # Queued try: TServer = models.TranscodingServer.objects.get( ip_address=JobReply.Job.GetCarbonHostname()) VRendition.transcoding_server = TServer logging.info("MakeVideoRenditions(): Carbon Server ->" + VRendition.transcoding_server.ip_address) except: logging.error( "MakeVideoRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False else: if JobReply.Error == False and ForceSchedule == False: # # No lo pudo planificar porque no hay ningun Carbon Coder Disponible # VRendition.transcoding_job_guid = '' VRendition.status = 'U' # Unasigned try: TServer = models.TranscodingServer.objects.get( ip_address='(Dummy)') VRendition.transcoding_server = TServer logging.info( "MakeVideoRenditions(): Carbon Server ->" + VRendition.transcoding_server.ip_address) except: logging.error( "MakeVideoRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False logging.info( "MakeVideoRenditions(): Can Not Assign Carbon Server (No one have slots )" ) else: ErrorString = '02: Error sending Job' logging.error( "MakeVideoRendition(): 02: Error sending Job") return False time.sleep(0.5) VRendition.save() if burn_prt == True: JobReply = StartJobCarbonPool(CPool, XmlJobPrt, ForceSchedule) VRendition = models.VideoRendition() VRendition.file_name = DstFilename_Prt VRendition.src_file_name = File VRendition.src_svc_path = Source VRendition.video_profile = VProfile VRendition.sub_file_name = sub_prt VRendition.item = Item VRendition.subtitle_burned = 'Y' VRendition.subtitle_language = 'P' if Item.format == 'HD': if VProfile.format == 'HD': VRendition.screen_format = 'Widescreen' else: VRendition.screen_format = 'Letterbox' elif Item.format == 'SD': VRendition.screen_format = 'Standard' if JobReply.Result == True: # # Crea el Video Rendition en el modelo # VRendition.transcoding_job_guid = JobReply.Job.GetGUID() VRendition.stimestamp = str(int(time.time())) VRendition.status = 'Q' # Queued try: TServer = models.TranscodingServer.objects.get( ip_address=JobReply.Job.GetCarbonHostname()) VRendition.transcoding_server = TServer logging.info("MakeVideoRenditions(): Carbon Server ->" + VRendition.transcoding_server.ip_address) except: logging.error( "MakeVideoRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False else: if JobReply.Error == False and ForceSchedule == False: # # No lo pudo planificar porque no hay ningun Carbon Coder Disponible # VRendition.transcoding_job_guid = '' VRendition.status = 'U' # Unasigned try: TServer = models.TranscodingServer.objects.get( ip_address='(Dummy)') VRendition.transcoding_server = TServer logging.info( "MakeVideoRenditions(): Carbon Server ->" + VRendition.transcoding_server.ip_address) except: logging.error( "MakeVideoRenditions(): Can not find the Assigned Carbon Server -> " + JobReply.Job.GetCarbonHostname()) return False logging.info( "MakeVideoRenditions(): Can Not Assign Carbon Server (No one have slots )" ) else: ErrorString = '02: Error sending Job' logging.error( "MakeVideoRendition(): 02: Error sending Job") return False time.sleep(0.5) VRendition.save() return True
def CheckItemStatus(): logging.info("CheckItemStatus(): Start Item check") for Item in models.GetProcessingItems(): logging.info("CheckItemStatus(): Checking item: %s" % Item.name) VRenditionList = models.VideoRendition.objects.filter(item=Item) vr_total = len(VRenditionList) vr_queued = 0 vr_unassig = 0 vr_finished = 0 vr_error = 0 for VRendition in VRenditionList: if VRendition.status == 'Q': vr_queued = vr_queued + 1 elif VRendition.status == 'F': vr_finished = vr_finished + 1 elif VRendition.status == 'E': vr_error = vr_error + 1 IRenditionList = models.ImageRendition.objects.filter(item=Item) ir_total = len(IRenditionList) ir_unfilled = 0 ir_filled = 0 ir_done = 0 ir_error = 0 for IRendition in IRenditionList: if IRendition.status == 'U': ir_unfilled = ir_unfilled + 1 elif IRendition.status == 'F': ir_filled = ir_filled + 1 elif IRendition.status == 'D': ir_done = ir_done + 1 elif IRendition.status == 'E': ir_error = ir_error + 1 master_path = models.GetPath("local_master_path") if not master_path.endswith('/'): master_path = master_path + '/' if vr_total <= vr_finished + vr_error: try: RQ = models.RenditionQueue.objects.get(item=Item) if RQ.local_file == 'Y': logging.info("CheckItemStatus(): Deleting Master File: %s" % master_path+RQ.file_name) if FileExist(master_path,RQ.file_name): os.unlink(master_path+RQ.file_name) RQ.local_file = 'N' RQ.local_svc_path = '' RQ.save() except: logging.error("CheckItemStatus(): Deleting Master File: %s" % master_path+RQ.file_name) if vr_total == vr_finished and ir_total == ir_done: # # Termino de procesarse todo # Item.status = 'D' Item.save() else: if vr_error > 0 or ir_error > 0: Item.status = 'W' Item.save() logging.info("CheckItemStatus(): End Item Check")
def CheckVideoRenditionStatus(): logging.info("CheckVideoRenditionStatus(): Start Check Video Rendition Status") video_local_path = models.GetPath("video_local_path") if video_local_path is None: logging.error("CheckVideoRenditionStatus(): Config Error, video_local_path not defined") return False logging.debug("CheckVideoRenditionStatus(): video_local_path: " + video_local_path) # # Agrega / si no es que exite al final # if not video_local_path.endswith('/'): video_local_path = video_local_path + '/' # # Trae todos los video rendition cuyo Status = Q # for VRendition in models.GetVideoRenditionQueue(): logging.info("CheckVideoRenditionStatus(): Video Rendition Check: " + VRendition.file_name) logging.info("CheckVideoRenditionStatus(): Video Rendition Item: " + VRendition.item.name) logging.info("CheckVideoRenditionStatus(): Transcoding Server: " + VRendition.transcoding_server.ip_address) logging.info("CheckVideoRenditionStatus(): Job GUID: " + VRendition.transcoding_job_guid) JobState, Progress = GetJobState(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) logging.info("GetJobState(): Job Progress: " + str(Progress)) logging.info("GetJobState(): Job State: " + JobState) if JobState == 'NEX_JOB_COMPLETED': # # Si el Job termino de procesarse correctamente # # Comprueba la existencia del File # logging.info("CheckVideoRenditionStatus(): Video Rendition finish transcoding: " + VRendition.file_name) if VRendition.video_profile.need_to_be_checked == 'T': if FileExist(video_local_path, VRendition.file_name): # # Si el archivo existe # # - Calcula su checksum # - Calcula su filesize # - Establece su Status en F -> Finished VRendition.checksum = md5_checksum(video_local_path + VRendition.file_name) logging.debug("CheckVideoRenditionStatus(): Video Rendition Checksum: " + VRendition.file_name + "," + VRendition.checksum) VRendition.file_size = os.stat(video_local_path + VRendition.file_name).st_size logging.debug("CheckVideoRenditionStatus(): Video Rendition FileSize: " + VRendition.file_name + "," + str(VRendition.file_size)) VRendition.duration = str( int(time.time()) - int(VRendition.stimestamp) ) VRendition.status = 'F' VRendition.progress = '100' VRendition.save() logging.info("RemoveJob(): Job Removing: " + VRendition.transcoding_job_guid) RemoveJob(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) logging.info("CheckVideoRenditionStatus(): Video Rendition finish all procesing: " + VRendition.file_name) else: # # Si el archivo no existe es porque se produjo un error # logging.error("CheckVideoRenditionStatus(): Video Rendition not exist: [FILE]-> " + VRendition.file_name + ", [PATH]-> " + video_local_path) VRendition.status = 'E' VRendition.error = "Video Rendition not exist: [FILE]-> " + VRendition.file_name + ", [PATH]-> " + video_local_path VRendition.save() else: VRendition.status = 'F' VRendition.progress = '100' logging.info("RemoveJob(): Job Removing: " + VRendition.transcoding_job_guid) RemoveJob(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) VRendition.save() # if VRendition.status == 'F' and VRendition.video_profile.cloud_duplicate == 'Y': if VRendition.status == 'F' and NeedToDuplicateVideo(VRendition): logging.info("CheckVideoRenditionStatus(): Send to the cloud: [%s]" % VRendition.file_name) video_cloud = models.GetPath ('cloud_duplicate_video') if not video_cloud.endswith('/'): video_cloud = video_cloud + '/' try: os.link(video_local_path + VRendition.file_name, video_cloud + VRendition.file_name) except: logging.error("CheckVideoRenditionStatus(): File exist in the cloud folder: [%s]" % VRendition.file_name) else: if JobState == 'NEX_JOB_STARTED': VRendition.speed = GetJobSpeed(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) VRendition.progress = str(Progress) VRendition.save() if JobState == 'NEX_JOB_ERROR': # # Si el job termino con errores # VRendition.status = 'E' VRendition.error = GetJobError(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) logging.info("RemoveJob(): Job Removing: " + VRendition.transcoding_job_guid) #RemoveJob(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) VRendition.save() if JobState == 'NEX_JOB_STOPPED': # # Alguien Freno el Job # VRendition.status = 'E' VRendition.error = "Stop Job" logging.info("RemoveJob(): Job Removing: " + VRendition.transcoding_job_guid) #RemoveJob(VRendition.transcoding_server.ip_address, VRendition.transcoding_job_guid) VRendition.save() if JobState == '': VRendition.status = 'E' VRendition.error = "Job State Empty" VRendition.save() logging.info("CheckVideoRenditionStatus(): End Check Video Rendition Status") return True
def CheckImageRenditionStatus(): logging.info("CheckImageRenditionStatus(): Start Check Imagen Rendition Status") image_local_path = models.GetPath("image_local_path") if image_local_path is None: logging.error("CheckImageRenditionStatus(): Config Error, image_local_path not defined") return False logging.debug("CheckImageRenditionStatus(): image_local_path: " + image_local_path) # # Agrega / si no es que exite al final # if not image_local_path.endswith('/'): image_local_path = image_local_path + '/' # # Trae todos los image rendition cuyo Status = F # for IRendition in models.GetImageRenditionQueue(): logging.info("CheckImageRenditionStatus(): Image Rendition Check: " + IRendition.file_name) logging.info("CheckImageRenditionStatus(): Image Rendition Item: " + IRendition.item.name) if FileExist(image_local_path, IRendition.file_name): # # Si el archivo existe # # - Calcula su checksum # - Calcula su filesize # - Establece su Status en F -> Finished IRendition.checksum = md5_checksum(image_local_path + IRendition.file_name) logging.debug("CheckImageoRenditionStatus(): Image Rendition Checksum: " + IRendition.file_name + "," + IRendition.checksum) IRendition.file_size = os.stat(image_local_path + IRendition.file_name).st_size logging.debug("CheckImageRenditionStatus(): Image Rendition FileSize: " + IRendition.file_name + "," + str(IRendition.file_size)) IRendition.status = 'D' IRendition.save() # if IRendition.image_profile.cloud_duplicate == 'Y': if NeedToDuplicateImage(IRendition): logging.info("CheckImageRenditionStatus(): Send to the cloud: [%s]" % IRendition.file_name) image_cloud = models.GetPath ('cloud_duplicate_image') if not image_cloud.endswith('/'): image_cloud = image_cloud + '/' try: os.link(image_local_path + IRendition.file_name, image_cloud + IRendition.file_name) except: pass logging.info("CheckImageRenditionStatus(): Image Rendition finish all procesing: " + IRendition.file_name) else: # # Si el archivo no existe es porque se produjo un error # logging.error("CheckImageRenditionStatus(): Image Rendition not exist: [FILE]-> " + IRendition.file_name + ", [PATH]-> " + image_local_path) IRendition.status = 'E' IRendition.error = "Image Rendition not exist: [FILE]-> " + IRendition.file_name + ", [PATH]-> " + image_local_path IRendition.save() logging.info("CheckImageRenditionStatus(): End Check Image Rendition Status") return True
def ProcessWaitingRenditionQueue(): logging.info( "ProcessWaitingRenditionQueue(): Start Processing Waiting Rendition Queue" ) LocalRepository = models.GetPath('local_master_path') ExternRepositorySD = models.GetPath('remote_nfs_sd') ExternRepositoryHD = models.GetPath('remote_nfs_hd') logging.info("ProcessWaitingRenditionQueue(): Local Repository -> %s" % LocalRepository) logging.info("ProcessWaitingRenditionQueue(): Exter Repository SD -> %s" % ExternRepositorySD) logging.info("ProcessWaitingRenditionQueue(): Exter Repository HD -> %s" % ExternRepositoryHD) try: LocalZone = models.ExportZone.objects.get(zone_name=Zone.LOCAL) Settings = models.Settings.objects.get(zone=LocalZone) except: e = sys.exc_info()[0] d = sys.exc_info()[1] logging.error( "ProcessWaitingRenditionQueue(): Error in LocalZone / Settings [%s -> %s]" % (e, d)) return False if LocalRepository is not None and ExternRepositorySD is not None and ExternRepositoryHD is not None: QueueLst = models.GetWaitingRenditionQueue() for Queue in QueueLst: logging.info( "ProcessWaitingRenditionQueue(): Item -> [%s], File Name -> [%s]" % (Queue.item.name, Queue.file_name)) # # Chequea que los repositorios esten OK # if not ExternRepositorySD.endswith('/'): ExternRepositorySD = ExternRepositorySD + '/' if not ExternRepositoryHD.endswith('/'): ExternRepositoryHD = ExternRepositoryHD + '/' if not LocalRepository.endswith('/'): LocalRepository = LocalRepository + '/' if not PathInQuota(LocalRepository, int(Settings.max_quota)): if not FileExist(LocalRepository, Queue.file_name): logging.info( "ProcessWaitingRenditionQueue(): Maximum Quota Limit Exceeded -> [%d]" % int(Settings.max_quota)) logging.info( "ProcessWaitingRenditionQueue(): End Processing Waiting Queue" ) return True if FileExist(ExternRepositorySD, Queue.file_name): logging.info( "ProcessWaitingRenditionQueue(): File Exist in -> [%s]" % ExternRepositorySD) if FileExist(LocalRepository, Queue.file_name): logging.info( "ProcessWaitingRenditionQueue(): File Exist local -> [%s]" % LocalRepository + Queue.file_name) logging.info( "ProcessWaitingRenditionQueue(): Overwrite Policy -> [%s]" % Settings.overwrite_pull_files) if Settings.overwrite_pull_files == 'T': logging.info( "ProcessWaitingRenditionQueue(): Pulling File -> [%s]" % Queue.file_name) Queue.queue_status = 'P' Queue.save() if PullFile(ExternRepositorySD, Queue.file_name, LocalRepository): Queue.local_file = 'Y' Queue.queue_status = 'Q' Queue.save() logging.info( "ProcessWaitingRenditionQueue(): Success") else: logging.error( "ProcessWaitingRenditionQueue(): Pulling file -> [%s], Error -> [%s]" % (Queue.file_name, ErrorString)) Queue.queue_status = 'E' logging.info( "ProcessWaitingRenditionQueue(): Put Queue [%d] in Error State" % Queue.id) Queue.error = "Can not retrive file [%s] to local_master_path [%s] -> %s" % ( Queue.file_name, LocalRepository, ErrorString) Queue.save() else: logging.info( "ProcessWaitingRenditionQueue(): Using Existing file [%s]" % (LocalRepository + Queue.file_name)) Queue.local_file = 'Y' Queue.queue_status = 'Q' Queue.save() else: logging.info( "ProcessWaitingRenditionQueue(): Pulling File -> [%s]" % Queue.file_name) Queue.queue_status = 'P' Queue.save() if PullFile(ExternRepositorySD, Queue.file_name, LocalRepository): Queue.local_file = 'Y' Queue.queue_status = 'Q' Queue.save() logging.info("ProcessWaitingRenditionQueue(): Success") else: logging.error( "ProcessWaitingRenditionQueue(): Pulling file -> [%s], Error -> [%s]" % (Queue.file_name, ErrorString)) Queue.queue_status = 'E' logging.info( "ProcessWaitingRenditionQueue(): Put Queue [%d] in Error State" % Queue.id) Queue.error = "Can not retrive file [%s] to local_master_path [%s] -> %s" % ( Queue.file_name, LocalRepository, ErrorString) Queue.save() elif FileExist(ExternRepositoryHD, Queue.file_name): logging.info( "ProcessWaitingRenditionQueue(): File Exist in -> [%s]" % ExternRepositoryHD) if FileExist(LocalRepository, Queue.file_name): logging.info( "ProcessWaitingRenditionQueue(): File Exist local -> [%s]" % LocalRepository + Queue.file_name) logging.info( "ProcessWaitingRenditionQueue(): Overwrite Policy -> [%s]" % Settings.overwrite_pull_files) if Settings.overwrite_pull_files == 'T': logging.info( "ProcessWaitingRenditionQueue(): Pulling File -> [%s]" % Queue.file_name) Queue.queue_status = 'P' Queue.save() if PullFile(ExternRepositoryHD, Queue.file_name, LocalRepository): Queue.local_file = 'Y' Queue.queue_status = 'Q' Queue.save() logging.info( "ProcessWaitingRenditionQueue(): Success") else: logging.error( "ProcessWaitingRenditionQueue(): Pulling file -> [%s], Error -> [%s]" % (Queue.file_name, ErrorString)) Queue.queue_status = 'E' logging.info( "ProcessWaitingRenditionQueue(): Put Queue [%d] in Error State" % Queue.id) Queue.error = "Can not retrive file [%s] to local_master_path [%s] -> %s" % ( Queue.file_name, LocalRepository, ErrorString) Queue.save() else: logging.info( "ProcessWaitingRenditionQueue(): Using Existing file [%s]" % (LocalRepository + Queue.file_name)) Queue.local_file = 'Y' Queue.queue_status = 'Q' Queue.save() else: logging.info( "ProcessWaitingRenditionQueue(): Pulling File -> [%s]" % Queue.file_name) Queue.queue_status = 'P' Queue.save() if PullFile(ExternRepositoryHD, Queue.file_name, LocalRepository): Queue.local_file = 'Y' Queue.queue_status = 'Q' Queue.save() logging.info("ProcessWaitingRenditionQueue(): Success") else: logging.error( "ProcessWaitingRenditionQueue(): Pulling file -> [%s], Error -> [%s]" % (Queue.file_name, ErrorString)) Queue.queue_status = 'E' logging.info( "ProcessWaitingRenditionQueue(): Put Queue [%d] in Error State" % Queue.id) Queue.error = "Can not retrive file [%s] to local_master_path [%s] -> %s" % ( Queue.file_name, LocalRepository, ErrorString) Queue.save() else: Queue.queue_status = 'E' Queue.error = 'Unable to find file in any Repository' Queue.save() logging.error( "ProcessWaitingRenditionQueue(): Unable to find file [%s] in any Repository" % Queue.file_name) else: logging.error( "ProcessWaitingRenditionQueue(): Repository bad configured") return False logging.info("End Processing Waiting Rendition Queue") return True