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
예제 #2
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 record(self):
		if self.event and self.service:
			event = self.event
			ref = self.service
			if event is None:
				return
			eventid = event.getEventId()
			eref = eServiceReference(str(ref))
			refstr = eref.toString()
			for timer in self.session.nav.RecordTimer.timer_list:
				if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
					cb_func = lambda ret : not ret or self.removeTimer(timer)
					self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
					break
			else:
				#newEntry = RecordTimerEntry(ServiceReference(ref), checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(self.event))
				begin, end, name, description, eit = parseEvent(self.event)
				
				from SeriesPlugin import refactorTitle, refactorDescription
				if self.data:
					name = refactorTitle(name, self.data)
					description = refactorDescription(description, self.data)
				
				#newEntry = RecordTimerEntry(ServiceReference(refstr), begin, end, name, description, eit, dirname = preferredTimerPath())
				newEntry = RecordTimerEntry(ServiceReference(str(ref)), begin, end, name, description, eit, dirname = preferredTimerPath())
				#newEntry = RecordTimerEntry(refstr, begin, end, name, description, eit, dirname = preferredTimerPath())
				self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
예제 #4
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
예제 #5
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)
	def keyRecord(self):
		log.debug("keyRecord")
		if self.event and self.service:
			event = self.event
			ref = self.service
			if event is None:
				return
			eventid = event.getEventId()
			eref = eServiceReference(str(ref))
			refstr = eref.toString()
			for timer in self.session.nav.RecordTimer.timer_list:
				if timer.eit == eventid and timer.service_ref.ref.toString() == refstr:
					cb_func = lambda ret : not ret or self.removeTimer(timer)
					self.session.openWithCallback(cb_func, MessageBox, _("Do you really want to delete %s?") % event.getEventName())
					break
			else:
				#newEntry = RecordTimerEntry(ServiceReference(ref), checkOldTimers = True, dirname = preferredTimerPath(), *parseEvent(self.event))
				begin, end, name, description, eit = parseEvent(self.event)
				
				from SeriesPlugin import refactorTitle, refactorDescription
				if self.data:
					name = refactorTitle(name, self.data)
					description = refactorDescription(description, self.data)
				
				#newEntry = RecordTimerEntry(ServiceReference(refstr), begin, end, name, description, eit, dirname = preferredTimerPath())
				newEntry = RecordTimerEntry(ServiceReference(str(ref)), begin, end, name, description, eit, dirname = preferredTimerPath())
				#newEntry = RecordTimerEntry(refstr, begin, end, name, description, eit, dirname = preferredTimerPath())
				self.session.openWithCallback(self.finishedAdd, TimerEntry, newEntry)
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)
예제 #8
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
예제 #9
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
	def timerCallback(self, timer, data=None):
		splog("SPT: timerCallback", data)
		splog(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))
			
			timer.log(610, "[SeriesPlugin] Success: Changed name: %s." % (timer.name))
		
		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
예제 #11
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
예제 #12
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
예제 #13
0
def rewriteMeta(servicepath, name, data):
    #TODO Use MetaSupport EitSupport classes from EMC ?
    if servicepath.endswith(".ts"):
        meta_file = servicepath + ".meta"
    else:
        meta_file = servicepath + ".ts.meta"

    # Create new meta for ts files
    if not os.path.exists(meta_file):
        if os.path.isfile(servicepath):
            _title = os.path.basename(os.path.splitext(servicepath)[0])
        else:
            _title = name
        _sid = ""
        _descr = ""
        _time = ""
        _tags = ""
        metafile = open(meta_file, "w")
        metafile.write("%s\n%s\n%s\n%s\n%s" %
                       (_sid, _title, _descr, _time, _tags))
        metafile.close()

    if os.path.exists(meta_file):
        metafile = open(meta_file, "r")
        sid = metafile.readline()
        oldtitle = metafile.readline().rstrip()
        olddescr = metafile.readline().rstrip()
        rest = metafile.read()
        metafile.close()

        if config.plugins.seriesplugin.pattern_title.value and not config.plugins.seriesplugin.pattern_title.value == "Off":
            title = refactorTitle(oldtitle, data)
        else:
            title = oldtitle
        log.debug("title", title)
        if config.plugins.seriesplugin.pattern_description.value and not config.plugins.seriesplugin.pattern_description.value == "Off":
            descr = refactorDescription(olddescr, data)
        else:
            descr = olddescr
        log.debug("descr", descr)

        metafile = open(meta_file, "w")
        metafile.write("%s%s\n%s\n%s" % (sid, title, descr, rest))
        metafile.close()
    return True
def renameMeta(servicepath, name, data):
	#TODO Use MetaSupport EitSupport classes from EMC ?
	if servicepath.endswith(".ts"):
		meta_file = servicepath + ".meta"
	else:
		meta_file = servicepath + ".ts.meta"
	
	# Create new meta for ts files
	if not os.path.exists(meta_file):
		if os.path.isfile(servicepath):
			_title = os.path.basename(os.path.splitext(servicepath)[0])
		else:
			_title = name
		_sid = ""
		_descr = ""
		_time = ""
		_tags = ""
		metafile = open(meta_file, "w")
		metafile.write("%s\n%s\n%s\n%s\n%s" % (_sid, _title, _descr, _time, _tags))
		metafile.close()
	
	if os.path.exists(meta_file):
		metafile = open(meta_file, "r")
		sid = metafile.readline()
		oldtitle = metafile.readline().rstrip()
		olddescr = metafile.readline().rstrip()
		rest = metafile.read()
		metafile.close()
		
		if config.plugins.seriesplugin.pattern_title.value and not config.plugins.seriesplugin.pattern_title.value == "Off":
			title = refactorTitle(oldtitle, data)
		else:
			title = oldtitle
		logDebug("SPR: title",title)
		if config.plugins.seriesplugin.pattern_description.value and not config.plugins.seriesplugin.pattern_description.value == "Off":
			descr = refactorDescription(olddescr, data)
		else:
			descr = olddescr
		logDebug("SPR: descr",descr)
		
		metafile = open(meta_file, "w")
		metafile.write("%s%s\n%s\n%s" % (sid, title, descr, rest))
		metafile.close()
	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
예제 #16
0
    def timerCallback(self, timer, data=None):
        splog("SPT: timerCallback", data)
        splog(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))

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

        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