| 1 |
#!/usr/bin/env python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
__license__ = 'GPL v3' |
| 5 |
__copyright__ = 'Łukasz Grąbczewski 2011' |
| 6 |
__version__ = '2.0' |
| 7 |
|
| 8 |
import os |
| 9 |
import re |
| 10 |
|
| 11 |
from calibre import walk |
| 12 |
from calibre.ptempfile import PersistentTemporaryFile |
| 13 |
from calibre.utils.zipfile import ZipFile |
| 14 |
from calibre.web.feeds.news import BasicNewsRecipe |
| 15 |
|
| 16 |
|
| 17 |
class dwutygodnik(BasicNewsRecipe): |
| 18 |
__author__ = 'Łukasz Grąbczewski' |
| 19 |
title = 'Dwutygodnik' |
| 20 |
language = 'pl' |
| 21 |
publisher = 'Narodowy Instytut Audiowizualny' |
| 22 |
publication_type = 'magazine' |
| 23 |
description = 'Strona Kultury: literatura, teatr, film, sztuka, muzyka, felietony, rozmowy' |
| 24 |
|
| 25 |
conversion_options = { |
| 26 |
'authors': 'Dwutygodnik.com', |
| 27 |
'publisher': publisher, |
| 28 |
'language': language, |
| 29 |
'comments': description, |
| 30 |
'no_default_epub_cover': True, |
| 31 |
'preserve_cover_aspect_ratio': True, |
| 32 |
} |
| 33 |
|
| 34 |
def build_index(self): |
| 35 |
browser = self.get_browser() |
| 36 |
browser.open('http://www.dwutygodnik.com/') |
| 37 |
|
| 38 |
# find the link |
| 39 |
epublink = browser.find_link(text_regex=re.compile(r'Wydanie EPUB')) |
| 40 |
|
| 41 |
# download ebook |
| 42 |
self.report_progress(0, _('Downloading ePUB')) |
| 43 |
response = browser.follow_link(epublink) |
| 44 |
book_file = PersistentTemporaryFile(suffix='.epub') |
| 45 |
book_file.write(response.read()) |
| 46 |
book_file.close() |
| 47 |
|
| 48 |
# convert |
| 49 |
self.report_progress(0.2, _('Converting to OEB')) |
| 50 |
oeb = self.output_dir + '/INPUT/' |
| 51 |
if not os.path.exists(oeb): |
| 52 |
os.makedirs(oeb) |
| 53 |
with ZipFile(book_file.name) as f: |
| 54 |
f.extractall(path=oeb) |
| 55 |
|
| 56 |
for f in walk(oeb): |
| 57 |
if f.endswith('.opf'): |
| 58 |
return f |