Example #1
0
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
Example #2
0
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
Example #3
0
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
Example #4
0
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