Import Bookpedia -> iTunes

Any trouble you encounter with the Pedias, here's the place to ask for help.
Post Reply
Ennilyn
Contributor
Contributor
Posts: 8
Joined: Mon May 17, 2010 8:53 am

Import Bookpedia -> iTunes

Post by Ennilyn »

Hi there.

I just wanted to check if there is a possibility to import ebooks from Bookpedia into iTunes. :?:

I have about 3000 ebooks (epub) in one Bookpedia-collection. Those books are all stored in one folder on my hard drive.
I made an extra collection with about 430 ebooks which I really want to read.
Don't wanna import all 3000 books into iTunes - which would be quite simple, but only those 430 interesting ebooks.
The link to each ebook-file is stored in the book-details under "links".

Is there any way to import my collection directly into iTunes? Maybe by using Automator or AppleScripts?

Thanks for your help,
Melanie
User avatar
sjk
Addicted to Bruji
Addicted to Bruji
Posts: 529
Joined: Sat Feb 21, 2009 9:01 pm
Location: Eugene

Re: Import Bookpedia -> iTunes

Post by sjk »

Hi, Melanie.

I don't think it's possible to iTunes import eBook epub files directly from their link references in Bookpedia entries. Is there any Spotlight metadata or other criteria outside of Bookpedia you could use to match the ~430 files of interest? If not, generating a file list from a Bookpedia collection could be done using sqlite commands on the database or extracted from File > Export Collection… (Command-S) XML output. After you've got that list it's relatively easy to iTunes import the files (either leaving them in current locations or copying them into iTuned Media folder locations).

Since it could take me awhile to learn enough to generate the file list my method of getting results you want would be less elegant (and still time consuming): iTunes import files that'll include all those of interest, then delete any unwanted iTunes items. That "add more than necessary then delete what's not" approach comes in handy in other contexts. :)

Hopefully someone else has a more optimal solution to offer.
User avatar
Conor
Top Dog
Posts: 5344
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: Import Bookpedia -> iTunes

Post by Conor »

I would go the AppleScript route. Create a text template by copying the below AppleScript template, taken from Doug's Scripts and saving it as iTunes Export.applescript in the following Bookpedia template folder ~/Library/Application Support/Bookpedia/Templates.

Code: Select all

tell application "iTunes"
	launch
	try
		<!--BeginRepeat-->
		set this_file to (POSIX file "[linksBegin][link:url][linksEnd]")		
		add this_file <!--EndRepeat-->
	end try
end tell
After that you can select your collection in Bookpedia and use the File -> Export command and you will see "iTunes Export" as an option in the text export tab as template option. Clicking export will generate an Applescript and actually open it up in Script Editor, were you can press the "Run" button to have it executed and your books imported.

The only issue I ran into with testing is that the path is quoted as a URL, so if you have any spaces in your folders you have to quickly run find "%20" and replace all for " ". You can do this directly in Script Editor when it opens. It will also import duplicates, so you might want to amend the AppleScript to do a search in iTunes first based on the title.

Also the script can be updated to add specific details from the Bookpedia data with:

Code: Select all

...
set itunes_track to (add this_file)
set artist of itunes_track to "[key:author]"
set genre of itunes_track to "[key:genre]"
A full ist of all the track elements can be found by using "Open Dictionary" in Script Editor and selecting iTunes and looking for the track property, but here are some of the more interesting ones:
properties
album (text) : the album name of the track
album artist (text) : the album artist of the track
album rating (integer) : the rating of the album for this track (0 to 100)
artist (text) : the artist/source of the track
category (text) : the category of the track
comment (text) : freeform notes about the track
date added (date, r/o) : the date the track was added to the playlist
description (text) : the description of the track
duration (real, r/o) : the length of the track in seconds
enabled (boolean) : is this track checked for playback?
genre (text) : the music/audio genre (category) of the track
kind (text, r/o) : a text description of the track
long description (text)
modification date (date, r/o) : the modification date of the content of this track
rating (integer) : the rating of this track (0 to 100)
release date (date, r/o) : the release date of this track
sort album (text) : override string to use for the track when sorting by album
sort artist (text) : override string to use for the track when sorting by artist
sort album artist (text) : override string to use for the track when sorting by album artist
sort name (text) : override string to use for the track when sorting by name
sort composer (text) : override string to use for the track when sorting by composer
year (integer) : the year the track was recorded/released
User avatar
sjk
Addicted to Bruji
Addicted to Bruji
Posts: 529
Joined: Sat Feb 21, 2009 9:01 pm
Location: Eugene

Re: Import Bookpedia -> iTunes

Post by sjk »

Ahh, creating a new text template is what I was overlooking. Should have just posted nothing and waited for your actually helpful reply. :)
Ennilyn
Contributor
Contributor
Posts: 8
Joined: Mon May 17, 2010 8:53 am

Re: Import Bookpedia -> iTunes

Post by Ennilyn »

Thanks so far for your help, Connor.

When I export my collection with the template you quoted it generates an rtf-file with all the data I specified.
After replacing "%20" for " " I copied the whole data into the script editor, but I cannot execute the file. It says:
Es wurde „end“ oder „end tell“ erwartet, aber ein Unbekanntes Token wurde gefunden.
... and the cursor is in line 2 next to "launch"

Any ideas?

Thanks again, Melanie
User avatar
Conor
Top Dog
Posts: 5344
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: Import Bookpedia -> iTunes

Post by Conor »

The copy paste should work.

Put in case of possible encodings errors make the file a text file instead of RTF. In TextEdit use "Format -> Make Plain Text" command-shift-T. Also if you then name the file with the extension .applescript it will open directly in Script Editor from Bookpedia.

If I had to guess it likely an issue with the new line encoding. For testing you can delete everything but the first two lines and the last one (as that alone should launch iTunes):

Code: Select all

tell application "iTunes"
   launch
end tell
If it still gives you the error please send me the exported file via email and I can test it out here. I won't have the files but I can test that it understands the AppleScript.
Ennilyn
Contributor
Contributor
Posts: 8
Joined: Mon May 17, 2010 8:53 am

Re: Import Bookpedia -> iTunes

Post by Ennilyn »

It works !!! :D

Thank you so much for your help. I always loved Bookpedia, but this extra is just fantastic !!

By the way, converting the file into plain text and then saving it as applescript worked just fine.

Only tiny problem left is that I could not import the summaries of the books, because an " in the description halted the script.
But never mind, I'm most likely using Pocketpedia to decide on a book.

Thanks again, Melanie :D
User avatar
sjk
Addicted to Bruji
Addicted to Bruji
Posts: 529
Joined: Sat Feb 21, 2009 9:01 pm
Location: Eugene

Re: Import Bookpedia -> iTunes

Post by sjk »

Glad to hear Conor's wizardry helped you, Melanie.

What I'd like is a way to keep links to external files in DVDpedia synchronized with corresponding video track references in my iTunes library, but that's another topic …
User avatar
Conor
Top Dog
Posts: 5344
Joined: Sat Jul 03, 2004 12:58 pm
Contact:

Re: Import Bookpedia -> iTunes

Post by Conor »

Excellent.

The quote is escaped with a backslash \". But you wouldn't be able to do a find and replace as you would capture the quote from the file path. You would have to update the quotes of the file path to something that does not appear in your text say #. Then you would be able to run these find and replace to create the final file:

%20 for space
" for \"
# for "

For those who want to go further, here is how to do searching in iTunes. It would mean you can update the AppleScript to search before importing and add details if the book already exists in iTunes instead of doing a new import.
Post Reply