View Single Post
Old 12-16-2011, 03:22 AM   #15
Arco Witter
Member
Arco Witter began at the beginning.
 
Posts: 21
Karma: 10
Join Date: Jan 2010
Device: iRex iLiad
Changed complete save-to-disk structure

Hello,

Using Calibre 0.8.30 I made a new function with this name: folderOnDevice:
Code:
def evaluate(self, formatter, kwargs, mi, locals, val, genretext, serietext, number_in_series, max_number_in_series, aantal_menu_items):
	import math

	titletext=val
	try:
		aant_mi = int(aantal_menu_items)
	except:
		return 'aantal_menu_items is geen aantal!'

	if number_in_series is None:
		num_in_serie = 0
	else:
		try:
			num_in_serie = int(number_in_series)
		except:
			num_in_serie = 0
			#return 'number_in_series is geen aantal!'

	maxAantInSerie = 0
	if num_in_serie > 0:
		if max_number_in_series is None:
			maxAantInSerie = num_in_serie
		else:
			try:
				maxAantInSerie = int(max_number_in_series)
			except:
				maxAantInSerie = num_in_serie
				# return 'max_number_in_series is niet ingevuld!'

	s = ''

	DoeBerekening = 1
	if maxAantInSerie == 0:
		DoeBerekening = 0
	if num_in_serie == 0:
		DoeBerekening = 0

	sResult=''
	if DoeBerekening == 1:
		#Bepaal maximum diepte (aantal submenus)
		menudiepte = 0
		while (int(math.floor(maxAantInSerie / (aant_mi ** menudiepte)))>aant_mi) and (menudiepte<10):
			menudiepte = menudiepte + 1

		#tbv formattering op juiste aantal cijfers
		ac=len('{0}'.format(maxAantInSerie))

		for MenuIndex in range(0, menudiepte):
			iPWplus1 = aant_mi**(MenuIndex+1)
			van = int(math.floor( (num_in_serie-1) / iPWplus1)      * iPWplus1 + 1)
			tot = int(math.floor(((num_in_serie-1) / iPWplus1) + 1) * iPWplus1    )
			if tot > maxAantInSerie:
				tot = maxAantInSerie
			sResult = '/{3} {1:0{0}}-{2:0{0}}'.format(ac, van, tot, serietext) + sResult

	sResult = genretext + '/' + '/' + serietext + sResult + '/'
	#Dubbele slashes verwijderen
	sResult=sResult.replace('//', '/')
	sResult=sResult.replace('//', '/')
	#Eerste slash verwijderen
	sResult=sResult.lstrip('/')

	return sResult
I also created a few columns:
max_number_in_series
genre

and two columns especially for showing the folder in which the books are kept:

folder_on_device_10
Script:
Code:
{title:folderOnDevice({#genre},{series},{series_index},{#max_number_in_series},10)}
folder_on_device_6
Script:
Code:
{title:folderOnDevice({#genre},{series},{series_index},{#max_number_in_series},6)}
So, now I use the save-to-disk function with this script:
Code:
{#folder_on_device_10:||/}{title}
Most of the time this works, but for some reason some books are wrong:
I see the correct name in the tree, for example the series (12 books) 'De wetten van de magie' had this in the folder_on_device column:
Code:
Book 01: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 02: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 03: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 04: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 05: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 06: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 07: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 08: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 09: Fictie/De wetten van de magie/De wetten van de magie 01-10/
Book 10: Fictie/De wetten van de magie/De wetten van de magie 11-12/
Book 11: Fictie/De wetten van de magie/De wetten van de magie 11-12/
Book 12: Fictie/De wetten van de magie/De wetten van de magie 11-12/
When I export to disk (to folder 'D:\eBooks\_ExportFromCalibre\'), all books are placed in this folder:
D:\eBooks\_ExportFromCalibre\#folder_on_device_10

so, while many books go to the correct folder, these won't, even while the column is correct. (All Perry Rhodan books for instance are correctly placed in sub folders)
Please, help me with this problem!
Arco Witter is offline   Reply With Quote