mirror of
				https://github.com/advplyr/audiobookshelf.git
				synced 2025-10-27 11:18:14 +01:00 
			
		
		
		
	Add:Book folder name starting with number and has series folder use as volume number
This commit is contained in:
		
							parent
							
								
									779d22bf55
								
							
						
					
					
						commit
						c81b12f459
					
				| @ -203,7 +203,8 @@ class Db { | ||||
|     })) | ||||
| 
 | ||||
|     return this.audiobooksDb.insert(audiobooks).then((results) => { | ||||
|       Logger.debug(`[DB] Audiobooks inserted ${results.updated}`) | ||||
|       Logger.debug(`[DB] Audiobooks inserted ${results.inserted}`) | ||||
|       this.audiobooks = this.audiobooks.concat(audiobooks) | ||||
|       return true | ||||
|     }).catch((error) => { | ||||
|       Logger.error(`[DB] Audiobooks insert failed ${error}`) | ||||
|  | ||||
| @ -569,9 +569,8 @@ class Audiobook { | ||||
|       if (abmetadataText) { | ||||
|         var metadataUpdateObject = abmetadataGenerator.parse(abmetadataText) | ||||
|         if (metadataUpdateObject && metadataUpdateObject.book) { | ||||
|           Logger.debug(`[Audiobook] Updating book "${this.title}" details from metadata.abs file`, metadataUpdateObject) | ||||
|           if (this.update(metadataUpdateObject)) { | ||||
|             Logger.debug(`[Audiobook] Some details were updated from metadata.abs for "${this.title}"`) | ||||
|             Logger.debug(`[Audiobook] Some details were updated from metadata.abs for "${this.title}"`, metadataUpdateObject) | ||||
|             hasUpdates = true | ||||
|           } | ||||
|         } | ||||
| @ -834,7 +833,7 @@ class Audiobook { | ||||
|     if (abmetadataText) { | ||||
|       var metadataUpdateObject = abmetadataGenerator.parse(abmetadataText) | ||||
|       if (metadataUpdateObject && metadataUpdateObject.book) { | ||||
|         Logger.debug(`[Audiobook] "${this.title}" found book details from metadata.abs file`, metadataUpdateObject) | ||||
|         Logger.debug(`[Audiobook] "${this.title}" found metadata.abs file`) | ||||
|         for (const key in metadataUpdateObject.book) { | ||||
|           var value = metadataUpdateObject.book[key] | ||||
|           if (key && value !== undefined) { | ||||
|  | ||||
| @ -85,8 +85,10 @@ function parseAbMetadataText(text) { | ||||
|       bookDetails[key] = keyValue[1].trim() | ||||
| 
 | ||||
|       // Genres convert to array of strings
 | ||||
|       if (key === 'genres' && bookDetails[key]) { | ||||
|         bookDetails[key] = bookDetails[key].split(',').map(genre => genre.trim()) | ||||
|       if (key === 'genres') { | ||||
|         bookDetails[key] = bookDetails[key] ? bookDetails[key].split(',').map(genre => genre.trim()) : [] | ||||
|       } else if (!bookDetails[key]) { // Use null for empty details
 | ||||
|         bookDetails[key] = null | ||||
|       } | ||||
|     } | ||||
|   } | ||||
|  | ||||
| @ -196,32 +196,42 @@ function getAudiobookDataFromDir(folderPath, dir, parseSubtitle = false) { | ||||
| 
 | ||||
| 
 | ||||
|   // If in a series directory check for volume number match
 | ||||
|   /* ACCEPTS: | ||||
|   /* ACCEPTS | ||||
|     Book 2 - Title Here - Subtitle Here | ||||
|     Title Here - Subtitle Here - Vol 12 | ||||
|     Title Here - volume 9 - Subtitle Here | ||||
|     Vol. 3 Title Here - Subtitle Here | ||||
|     1980 - Book 2-Title Here | ||||
|     Title Here-Volume 999-Subtitle Here | ||||
|     2 - Book Title | ||||
|     100 - Book Title | ||||
|     0.5 - Book Title | ||||
|   */ | ||||
|   var volumeNumber = null | ||||
|   if (series) { | ||||
|     // New volume regex to match volumes with decimal (OLD: /(-? ?)\b((?:Book|Vol.?|Volume) (\d{1,3}))\b( ?-?)/i)
 | ||||
|     var volumeMatch = title.match(/(-? ?)\b((?:Book|Vol.?|Volume) (\d{0,3}(?:\.\d{1,2})?))\b( ?-?)/i) | ||||
|     if (volumeMatch && volumeMatch.length > 3 && volumeMatch[2] && volumeMatch[3]) { | ||||
|       volumeNumber = volumeMatch[3] | ||||
|       var replaceChunk = volumeMatch[2] | ||||
|     // Added 1.7.1: If title starts with a # that is 3 digits or less (or w/ 2 decimal), then use as volume number
 | ||||
|     var volumeMatch = title.match(/^(\d{1,3}(?:\.\d{1,2})?) - ./) | ||||
|     if (volumeMatch && volumeMatch.length > 1) { | ||||
|       volumeNumber = volumeMatch[1] | ||||
|       title = title.replace(`${volumeNumber} - `, '') | ||||
|     } else { | ||||
|       // Match volumes with decimal (OLD: /(-? ?)\b((?:Book|Vol.?|Volume) (\d{1,3}))\b( ?-?)/i)
 | ||||
|       var volumeMatch = title.match(/(-? ?)\b((?:Book|Vol.?|Volume) (\d{0,3}(?:\.\d{1,2})?))\b( ?-?)/i) | ||||
|       if (volumeMatch && volumeMatch.length > 3 && volumeMatch[2] && volumeMatch[3]) { | ||||
|         volumeNumber = volumeMatch[3] | ||||
|         var replaceChunk = volumeMatch[2] | ||||
| 
 | ||||
|       // "1980 - Book 2-Title Here"
 | ||||
|       // Group 1 would be "- "
 | ||||
|       // Group 3 would be "-"
 | ||||
|       // Only remove the first group
 | ||||
|       if (volumeMatch[1]) { | ||||
|         replaceChunk = volumeMatch[1] + replaceChunk | ||||
|       } else if (volumeMatch[4]) { | ||||
|         replaceChunk += volumeMatch[4] | ||||
|         // "1980 - Book 2-Title Here"
 | ||||
|         // Group 1 would be "- "
 | ||||
|         // Group 3 would be "-"
 | ||||
|         // Only remove the first group
 | ||||
|         if (volumeMatch[1]) { | ||||
|           replaceChunk = volumeMatch[1] + replaceChunk | ||||
|         } else if (volumeMatch[4]) { | ||||
|           replaceChunk += volumeMatch[4] | ||||
|         } | ||||
|         title = title.replace(replaceChunk, '').trim() | ||||
|       } | ||||
|       title = title.replace(replaceChunk, '').trim() | ||||
|     } | ||||
|   } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user