Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Recipes

Notices

Reply
 
Thread Tools Search this Thread
Old 01-01-2012, 08:39 PM   #1
luka6000
Junior Member
luka6000 began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Dec 2011
Device: Nook ST
downloading epub in recipe Biweekly.pl

Hello,

I'd like to share my recipe of english edition of polish cultural magazine biweekly.pl

Spoiler:

Code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

__license__ = 'GPL v3'
__copyright__ = u'Łukasz Grąbczewski 2011'
__version__ = '2.0'

import re, zipfile, os, time
from calibre.ptempfile import PersistentTemporaryDirectory
from calibre.ptempfile import PersistentTemporaryFile
from urlparse import urlparse

class biweekly(BasicNewsRecipe):
	__author__ = u'Łukasz Grąbczewski'
	title = 'Biweekly'
	language = 'en_EN'
	publisher = 'National Audiovisual Institute'
	publication_type = 'magazine'
	description = u'link with culture [English edition of Polish magazine]: literature, theatre, film, art, music, views, talks'
	
	conversion_options = {
		'authors' : 'Biweekly.pl'
		,'publisher' : publisher
		,'language' : language
		,'no_default_epub_cover' : True
		,'preserve_cover_aspect_ratio': True
	}

	def build_index(self):
		browser = self.get_browser()
		rc = browser.open('http://www.biweekly.pl/')

		# find the link
		epublink = browser.find_link(text_regex=re.compile('ePUB VERSION'))

		# Cheat calibre's recipe method
		self.report_progress(0,_('downloading'))
		response = browser.follow_link(epublink)
		dir = PersistentTemporaryDirectory()
		book_file = PersistentTemporaryFile(suffix='.epub')
		book_file.write(response.read())
		book_file.close()
				
		self.report_progress(0.2,_('Converting to OEB'))
		oebdir = self.output_dir + '/INPUT/'
		cmd = 'ebook-convert "' + book_file.name + '" "' + oebdir + '"'
		os.system(cmd)
		
		index = os.path.join(oebdir, 'content.opf')
		self.report_progress(0.2,_('successfully downloaded and extracted'))
		
		return index


Let me comment the code and then ask some questions :-)
Basically this recipe opens a web page, finds the epub link, downloads it and converts it to OEB directory structure and outputs that as recipe feed. I think this is a better way of managing this kind of downloadable ebook news than just using zipfile epub unzip as Lars Jacob and Starson17. Using conversion to OEB it is possible to use as input anything that conversion can recognize (mobi, html, txt etc). The problem with this code is that it will not work if ebook-convert is not in path. So my question is if someone could help me with using conversion not as a system call but using native python code. I've already have few more recipes of such "download ebook from here" sources but would like to establish a proper way of handling this kind of news. Thanks in advance!
luka6000 is offline   Reply With Quote
Old 01-01-2012, 10:45 PM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 45,194
Karma: 27110894
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
If you want to call ebook-convert programmatically, just do

from calibre.ebooks.conversion.cli import main
main(['ebook-convert', 'input.epub', 'oeb', 'whatever', 'options', 'you', 'need'])
kovidgoyal is offline   Reply With Quote
Advert
Old 01-02-2012, 06:43 PM   #3
luka6000
Junior Member
luka6000 began at the beginning.
 
Posts: 7
Karma: 10
Join Date: Dec 2011
Device: Nook ST
Recipe: biweekly.pl, dwutygodnik.com

thanks Kovid.

So here comes first two production ready (I think) recipes
biweekly.pl, favicon [EN]
dwutygodnik.com, favicon [PL]
luka6000 is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Financial Times recipe downloading slowly, empty pages mapex Recipes 34 06-06-2013 06:27 AM
Liberation recipe downloading only headlines emai7s2 Recipes 3 08-20-2011 12:47 AM
Beneath Ceaseless Skies recipe for direct epub downloading duckpuppy Recipes 5 02-23-2011 10:12 PM
Downloading several years of blogposts via custom recipe flyash Calibre 4 01-01-2011 02:02 AM
Biweekly recommendations of e-books for kindle vs1015 Reading Recommendations 0 11-01-2010 02:33 PM


All times are GMT -4. The time now is 07:35 AM.


MobileRead.com is a privately owned, operated and funded community.