Exemplo n.º 1
0
def renameFiles(servicepath, name, data):
    log.debug("servicepath", servicepath)

    path = os.path.dirname(servicepath)
    file_name = os.path.basename(os.path.splitext(servicepath)[0])
    log.debug("file_name", file_name)

    log.debug("name     ", name)
    # Refactor title
    name = refactorTitle(file_name, data)
    log.debug("name     ", name)
    #if config.recording.ascii_filenames.value:
    #	filename = ASCIItranslit.legacyEncode(filename)
    if config.plugins.seriesplugin.rename_legacy.value:
        name = newLegacyEncode(name)
        log.debug("name     ", name)

    src = os.path.join(path, file_name)
    log.debug("servicepathSrc", src)

    path = refactorDirectory(path, data)
    dst = os.path.join(path, name)
    log.debug("servicepathDst", dst)

    return osrename(src, dst)
Exemplo n.º 2
0
def bareGetSeasonEpisode(service_ref, name, begin, end, description, path, future=True, today=False, elapsed=False):
	result = _("SeriesPlugin is deactivated")
	if config.plugins.seriesplugin.enabled.value:
		
		startLog()
		
		logInfo("Bare:", service_ref, name, begin, end, description, path, future, today, elapsed)
		
		from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
		seriesPlugin = getInstance()
		data = seriesPlugin.getEpisodeBlocking(
			name, begin, end, service_ref, future, today, elapsed
		)
		
		global loop_counter
		loop_counter += 1
		
		if data and isinstance(data, dict):
			name = str(refactorTitle(name, data))
			description = str(refactorDescription(description, data))
			path = refactorDirectory(path, data)
			logInfo("Bare: Success", name, description, path)
			return (name, description, path, getLog())
		elif data:
			global loop_data
			loop_data.append( str(data) )
		
		logInfo("Bare: Failed", str(data))
		return str(data)
	
	return result
def renameFiles(servicepath, name, data):
	log.debug("servicepath", servicepath)
	
	path = os.path.dirname(servicepath)
	file_name = os.path.basename(os.path.splitext(servicepath)[0])
	log.debug("file_name", file_name)
	
	log.debug("name     ", name)
	# Refactor title
	name = refactorTitle(file_name, data)
	log.debug("name     ", name)
	#if config.recording.ascii_filenames.value:
	#	filename = ASCIItranslit.legacyEncode(filename)
	if config.plugins.seriesplugin.rename_legacy.value:
		name = newLegacyEncode(name)
		log.debug("name     ", name)
	
	src = os.path.join(path, file_name)
	log.debug("servicepathSrc", src)
	
	path = refactorDirectory(path, data)
	dst = os.path.join(path, name)
	log.debug("servicepathDst", dst)
	
	return osrename(src, dst)
Exemplo n.º 4
0
def bareGetSeasonEpisode(service_ref, name, begin, end, description, path, future=True, today=False, elapsed=False):
	result = None
	if config.plugins.seriesplugin.enabled.value:
		
		startLog()
		
		logInfo("Bare:", service_ref, name, begin, end, description, path, future, today, elapsed)
		
		from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
		seriesPlugin = getInstance()
		data = seriesPlugin.getEpisodeBlocking(
			name, begin, end, service_ref, future, today, elapsed
		)
		
		global loop_counter
		loop_counter += 1
		
		if data and len(data) == 4:
			name = str(refactorTitle(name, data))
			description = str(refactorDescription(description, data))
			path = refactorDirectory(path, data)
			logInfo("Bare: Success", name, description, path)
			return (name, description, path, getLog())
		elif data:
			global loop_data
			loop_data.append( str(data) )
		
		logInfo("Bare: Failed", str(data))
		return str(data)
	
	return result
Exemplo n.º 5
0
	def timerCallback(self, timer, data=None):
		log.debug("timerCallback", data)
		
		if data and isinstance(data, dict) and timer:
			
			# Episode data available, refactor name and description
			timer.name = str(refactorTitle(timer.name, data))
			timer.description = str(refactorDescription(timer.description, data))
			
			timer.dirname = str(refactorDirectory(timer.dirname or config.usage.default_path.value, data))
			timer.calculateFilename()
			
			msg = _("Success: %s" % (timer.name))
			log.debug(msg)
			timer.log(610, "[SeriesPlugin]" + " " + msg)
			
			if config.plugins.seriesplugin.timer_add_tag.value:
				timer.tags.append(TAG)
		
		elif data:
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			timer.log(611, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		else:
			msg = _("No data available")
			log.debug(msg)
			timer.log(612, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		timer.sp_in_queue = False
		
		SeriesPluginTimer.counter = SeriesPluginTimer.counter +1
		
		# Maybe there is a better way to avoid multiple Popups
		from SeriesPlugin import getInstance
		
		instance = getInstance()
		
		if instance.thread.empty() and instance.thread.finished():
		
			if SeriesPluginTimer.data:
				msg = "SeriesPlugin:\n" + _("Timer rename has been finished with %d errors:\n") % (len(SeriesPluginTimer.data)) +"\n" +"\n".join(SeriesPluginTimer.data)
				log.warning(msg)
				
			else:
				if SeriesPluginTimer.counter > 0:
					msg = "SeriesPlugin:\n" + _("%d timer renamed successfully") % (SeriesPluginTimer.counter)
					log.success(msg)
				
			SeriesPluginTimer.data = []
			SeriesPluginTimer.counter = 0
		
		return timer
Exemplo n.º 6
0
	def timerCallback(self, timer, data=None):
		log.debug("timerCallback", data)
		
		if data and isinstance(data, dict) and timer:
			
			# Episode data available, refactor name and description
			timer.name = str(refactorTitle(timer.name, data))
			timer.description = str(refactorDescription(timer.description, data))
			
			timer.dirname = str(refactorDirectory(timer.dirname or config.usage.default_path.value, data))
			timer.calculateFilename()
			
			msg = _("Success: %s" % (timer.name))
			log.debug(msg)
			timer.log(610, "[SeriesPlugin]" + " " + msg)
			
			if config.plugins.seriesplugin.timer_add_tag.value:
				timer.tags.append(TAG)
		
		elif data:
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			timer.log(611, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		else:
			msg = _("No data available")
			log.debug(msg)
			timer.log(612, "[SeriesPlugin]" + " " + msg)
			SeriesPluginTimer.data.append(
				str(timer.name) + ": " + msg
			)
		
		timer.sp_in_queue = False
		
		SeriesPluginTimer.counter = SeriesPluginTimer.counter +1
		
		# Maybe there is a better way to avoid multiple Popups
		from SeriesPlugin import getInstance
		
		instance = getInstance()
		
		if instance.thread.empty() and instance.thread.finished():
		
			if SeriesPluginTimer.data:
				msg = "SeriesPlugin:\n" + _("Timer rename has been finished with %d errors:\n") % (len(SeriesPluginTimer.data)) +"\n" +"\n".join(SeriesPluginTimer.data)
				log.warning(msg)
				
			else:
				if SeriesPluginTimer.counter > 0:
					msg = "SeriesPlugin:\n" + _("%d timer renamed successfully") % (SeriesPluginTimer.counter)
					log.success(msg)
				
			SeriesPluginTimer.data = []
			SeriesPluginTimer.counter = 0
		
		return timer
Exemplo n.º 7
0
def bareGetEpisode(service_ref,
                   name,
                   begin,
                   end,
                   description,
                   path,
                   future=True,
                   today=False,
                   elapsed=False):
    result = _("SeriesPlugin is deactivated")
    if config.plugins.seriesplugin.enabled.value:

        log.start()

        log.info("Bare:", service_ref, name, begin, end, description, path,
                 future, today, elapsed)

        from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
        seriesPlugin = getInstance()
        data = seriesPlugin.getEpisode(None,
                                       name,
                                       begin,
                                       end,
                                       service_ref,
                                       future,
                                       today,
                                       elapsed,
                                       block=True)

        global loop_counter
        loop_counter += 1

        if data and isinstance(data, dict):
            name = str(refactorTitle(name, data))
            description = str(refactorDescription(description, data))
            path = refactorDirectory(path, data)
            log.info("Bare: Success", name, description, path)
            return (name, description, path, log.get())

        elif data and isinstance(data, basestring):
            global loop_data
            msg = _("Failed: %s." % (str(data)))
            log.debug(msg)
            loop_data.append(name + ": " + msg)

        else:
            global loop_data
            msg = _("No data available")
            log.debug(msg)
            loop_data.append(name + ": " + msg)

        log.info("Bare: Failed", str(data))
        return str(data)

    return result
def renameFile(servicepath, name, data, tidy=False):
	logDebug("SPR: servicepath", servicepath)
	
	path = os.path.dirname(servicepath)
	file_name = os.path.basename(os.path.splitext(servicepath)[0])
	logDebug("SPR: file_name", file_name)
	
	logDebug("SPR: name     ", name)
	# Refactor title
	if config.plugins.seriesplugin.rename_tidy.value or tidy:
		name = refactorTitle(name, data)
	else:
		name = refactorTitle(file_name, data)
	logDebug("SPR: name     ", name)
	#if config.recording.ascii_filenames.value:
	#	filename = ASCIItranslit.legacyEncode(filename)
	if config.plugins.seriesplugin.rename_legacy.value:
		name = newLegacyEncode(name)
		logDebug("SPR: name     ", name)
	
	src = os.path.join(path, file_name)
	logDebug("SPR: servicepathSrc", src)
	
	path = refactorDirectory(path, data)
	dst = os.path.join(path, name)
	logDebug("SPR: servicepathDst", dst)

	#Py3 for f in glob( escape(src) + "*" ):
	glob_src = CompiledRegexpGlobEscape.sub("[\\1]", src)
	logDebug("SPR: glob_src      ", glob_src)
	for f in glob( glob_src + ".*" ):
		logDebug("SPR: servicepathRnm", f)
		to = f.replace(src, dst)
		logDebug("SPR: servicepathTo ", to)
		
		
		#TODO Check and create directory
		
		
		if not os.path.exists(to):
			try:
				os.rename(f, to)
			except:
				logDebug("SPR: rename error", f, to)
		elif config.plugins.seriesplugin.rename_existing_files.value:
			logDebug("SPR: Destination file already exists", to, " - Append _")
			renameFile(servicepath, name + "_", data, True)
			break
		else:
			logDebug("SPR: Destination file alreadey exists", to, " - Skip rename")
	return True
Exemplo n.º 9
0
def renameFile(servicepath, name, data, tidy=False):
    logDebug("SPR: servicepath", servicepath)

    path = os.path.dirname(servicepath)
    file_name = os.path.basename(os.path.splitext(servicepath)[0])
    logDebug("SPR: file_name", file_name)

    logDebug("SPR: name     ", name)
    # Refactor title
    if config.plugins.seriesplugin.rename_tidy.value or tidy:
        name = refactorTitle(name, data)
    else:
        name = refactorTitle(file_name, data)
    logDebug("SPR: name     ", name)
    #if config.recording.ascii_filenames.value:
    #	filename = ASCIItranslit.legacyEncode(filename)
    if config.plugins.seriesplugin.rename_legacy.value:
        name = newLegacyEncode(name)
        logDebug("SPR: name     ", name)

    src = os.path.join(path, file_name)
    logDebug("SPR: servicepathSrc", src)

    path = refactorDirectory(path, data)
    dst = os.path.join(path, name)
    logDebug("SPR: servicepathDst", dst)

    #Py3 for f in glob( escape(src) + "*" ):
    glob_src = CompiledRegexpGlobEscape.sub("[\\1]", src)
    logDebug("SPR: glob_src      ", glob_src)
    for f in glob(glob_src + ".*"):
        logDebug("SPR: servicepathRnm", f)
        to = f.replace(src, dst)
        logDebug("SPR: servicepathTo ", to)

        #TODO Check and create directory

        if not os.path.exists(to):
            try:
                os.rename(f, to)
            except:
                logDebug("SPR: rename error", f, to)
        elif config.plugins.seriesplugin.rename_existing_files.value:
            logDebug("SPR: Destination file already exists", to, " - Append _")
            renameFile(servicepath, name + "_", data, True)
            break
        else:
            logDebug("SPR: Destination file alreadey exists", to,
                     " - Skip rename")
    return True
def bareGetEpisode(service_ref, name, begin, end, description, path, future=True, today=False, elapsed=False, returnData=False):
	result = _("SeriesPlugin is deactivated")
	if config.plugins.seriesplugin.enabled.value:
		
		log.start()
		
		log.info("Bare:", service_ref, name, begin, end, description, path, future, today, elapsed)
		
		from SeriesPlugin import getInstance, refactorTitle, refactorDescription, refactorDirectory
		seriesPlugin = getInstance()
		data = seriesPlugin.getEpisode(
			None, 
			name, begin, end, service_ref, future, today, elapsed, block=True
		)
		
		global loop_counter
		loop_counter += 1
		
		if data and isinstance(data, dict):
			name = str(refactorTitle(name, data))
			description = str(refactorDescription(description, data))
			path = refactorDirectory(path, data)
			log.info("Bare: Success", name, description, path)
			if returnData:
				return (name, description, path, log.get(), data)
			else:
				return (name, description, path, log.get())
		
		elif data and isinstance(data, basestring):
			global loop_data
			msg = _("Failed: %s." % ( str( data ) ))
			log.debug(msg)
			loop_data.append( name + ": " + msg )
		
		else:
			global loop_data
			msg = _("No data available")
			log.debug(msg)
			loop_data.append( name + ": " + msg )
		
		log.info("Bare: Failed", str(data))
		return str(data)
	
	return result
Exemplo n.º 11
0
    def timerCallback(self, timer, data=None):
        logDebug("SPT: timerCallback", data)
        logDebug(data)

        if data and len(data) == 4 and timer:

            # Episode data available, refactor name and description
            #from SeriesPluginRenamer import newLegacyEncode
            timer.name = str(refactorTitle(timer.name, data))
            #timer.name = newLegacyEncode(refactorTitle(timer.name, data))
            timer.description = str(
                refactorDescription(timer.description, data))

            #try: timer.Filename
            #except: timer.calculateFilename()
            if not hasattr(timer, 'Filename'):
                timer.calculateFilename()

            if not timer.dirname:
                logDebug("SPT: SeriesPluginTimer: No dirname")
                timer.dirname = str(
                    refactorDirectory(config.usage.default_path.value, data))
            else:
                timer.dirname = str(refactorDirectory(timer.dirname, data))

            timer.log(
                610,
                "[SeriesPlugin] Success: Changed name: %s." % (timer.name))

            timer.tags.append(TAG)

        elif data:
            timer.log(611, "[SeriesPlugin] Failed: %s." % (str(data)))
            SeriesPluginTimer.data.append(str(timer.name) + " " + str(data))

        else:
            timer.log(612, "[SeriesPlugin] Failed.")
            SeriesPluginTimer.data.append(
                str(timer.name) + " " + _("No data available"))

        timer.sp_in_queue = False

        if config.plugins.seriesplugin.timer_popups.value or config.plugins.seriesplugin.timer_popups_success.value:

            SeriesPluginTimer.counter = SeriesPluginTimer.counter + 1

            if SeriesPluginTimer.data or config.plugins.seriesplugin.timer_popups_success.value:

                # Maybe there is a better way to avoid multiple Popups
                from SeriesPlugin import getInstance

                instance = getInstance()

                if instance.thread.empty() and instance.thread.finished():

                    if SeriesPluginTimer.data:
                        AddPopup(
                            "SeriesPlugin:\n" +
                            _("Timer rename has been finished with %d errors:\n"
                              ) % (len(SeriesPluginTimer.data)) + "\n" +
                            "\n".join(SeriesPluginTimer.data),
                            MessageBox.TYPE_ERROR,
                            int(config.plugins.seriesplugin.
                                timer_popups_timeout.value),
                            'SP_PopUp_ID_TimerFinished')
                    else:
                        AddPopup(
                            "SeriesPlugin:\n" +
                            _("%d timer renamed successfully") %
                            (SeriesPluginTimer.counter), MessageBox.TYPE_INFO,
                            int(config.plugins.seriesplugin.
                                timer_popups_timeout.value),
                            'SP_PopUp_ID_TimerFinished')
                    SeriesPluginTimer.data = []
                    SeriesPluginTimer.counter = 0

        return timer
	def timerCallback(self, timer, data=None):
		logDebug("SPT: timerCallback", data)
		logDebug(data)
		
		if data and len(data) == 4 and timer:
			
			# Episode data available, refactor name and description
			#from SeriesPluginRenamer import newLegacyEncode
			timer.name = str(refactorTitle(timer.name, data))
			#timer.name = newLegacyEncode(refactorTitle(timer.name, data))
			timer.description = str(refactorDescription(timer.description, data))
			
			#try: timer.Filename
			#except: timer.calculateFilename()
			if not hasattr(timer, 'Filename'):
				timer.calculateFilename()
			
			if not timer.dirname:
				logDebug("SPT: SeriesPluginTimer: No dirname")
				timer.dirname  = str(refactorDirectory(config.usage.default_path.value, data))
			else:
				timer.dirname  = str(refactorDirectory(timer.dirname, data))
			
			timer.log(610, "[SeriesPlugin] Success: Changed name: %s." % (timer.name))
			
			timer.tags.append(TAG)
		
		elif data:
			timer.log(611, "[SeriesPlugin] Failed: %s." % ( str( data ) ))
			SeriesPluginTimer.data.append(
				str(timer.name) + " " + str( data )
			)
		
		else:
			timer.log(612, "[SeriesPlugin] Failed." )
			SeriesPluginTimer.data.append(
				str(timer.name) + " " + _("No data available")
			)
		
		timer.sp_in_queue = False
		
		if config.plugins.seriesplugin.timer_popups.value or config.plugins.seriesplugin.timer_popups_success.value:
			
			SeriesPluginTimer.counter = SeriesPluginTimer.counter +1
			
			if SeriesPluginTimer.data or config.plugins.seriesplugin.timer_popups_success.value:
				
				# Maybe there is a better way to avoid multiple Popups
				from SeriesPlugin import getInstance
				
				instance = getInstance()
				
				if instance.thread.empty() and instance.thread.finished():
				
					if SeriesPluginTimer.data:
						AddPopup(
							"SeriesPlugin:\n" + _("Timer rename has been finished with %d errors:\n") % (len(SeriesPluginTimer.data)) +"\n" +"\n".join(SeriesPluginTimer.data),
							MessageBox.TYPE_ERROR,
							int(config.plugins.seriesplugin.timer_popups_timeout.value),
							'SP_PopUp_ID_TimerFinished'
						)
					else:
						AddPopup(
							"SeriesPlugin:\n" + _("%d timer renamed successfully") % (SeriesPluginTimer.counter),
							MessageBox.TYPE_INFO,
							int(config.plugins.seriesplugin.timer_popups_timeout.value),
							'SP_PopUp_ID_TimerFinished'
						)
					SeriesPluginTimer.data = []
					SeriesPluginTimer.counter = 0
		
		return timer