mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
IGN:...
This commit is contained in:
parent
0610852734
commit
64c641b207
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
|
|
||||||
@ -19,8 +20,11 @@ from calibre.ebooks.metadata.opf import OPFReader
|
|||||||
from calibre.ebooks.metadata.rtf import set_metadata as set_rtf_metadata
|
from calibre.ebooks.metadata.rtf import set_metadata as set_rtf_metadata
|
||||||
from calibre.ebooks.lrf.meta import set_metadata as set_lrf_metadata
|
from calibre.ebooks.lrf.meta import set_metadata as set_lrf_metadata
|
||||||
from calibre.ebooks.metadata.epub import set_metadata as set_epub_metadata
|
from calibre.ebooks.metadata.epub import set_metadata as set_epub_metadata
|
||||||
|
from calibre.libunrar import extract_first as rar_extract_first
|
||||||
|
from calibre.libunzip import extract_first as zip_extract_first
|
||||||
|
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
from calibre.ptempfile import TemporaryDirectory
|
||||||
|
|
||||||
_METADATA_PRIORITIES = [
|
_METADATA_PRIORITIES = [
|
||||||
'html', 'htm', 'xhtml', 'xhtm',
|
'html', 'htm', 'xhtml', 'xhtm',
|
||||||
@ -94,8 +98,33 @@ def get_metadata(stream, stream_type='lrf', use_libprs_metadata=False):
|
|||||||
if opf is not None:
|
if opf is not None:
|
||||||
base.smart_update(opf)
|
base.smart_update(opf)
|
||||||
|
|
||||||
|
if stream_type in ('cbr', 'cbz'):
|
||||||
|
try:
|
||||||
|
cdata = get_comic_cover(stream, stream_type)
|
||||||
|
if cdata is not None:
|
||||||
|
base.cover_data = cdata
|
||||||
|
except:
|
||||||
|
import traceback
|
||||||
|
traceback.print_exc()
|
||||||
|
pass
|
||||||
|
|
||||||
return base
|
return base
|
||||||
|
|
||||||
|
def get_comic_cover(stream, type):
|
||||||
|
with TemporaryDirectory('_comic_cover') as tdir:
|
||||||
|
extract_first = zip_extract_first if type == 'zip' else rar_extract_first
|
||||||
|
extract_first(stream, tdir)
|
||||||
|
files = os.listdir(tdir)
|
||||||
|
print tdir, files
|
||||||
|
if files:
|
||||||
|
path = os.path.join(tdir, files[0])
|
||||||
|
ext = os.path.splitext(path)[1].lower()
|
||||||
|
if ext:
|
||||||
|
ext = ext[1:]
|
||||||
|
return (ext, open(path, 'rb').read())
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def set_metadata(stream, mi, stream_type='lrf'):
|
def set_metadata(stream, mi, stream_type='lrf'):
|
||||||
if stream_type: stream_type = stream_type.lower()
|
if stream_type: stream_type = stream_type.lower()
|
||||||
if stream_type == 'lrf':
|
if stream_type == 'lrf':
|
||||||
|
@ -55,10 +55,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
item = QListWidgetItem(BooksModel.headers[col], self.columns)
|
item = QListWidgetItem(BooksModel.headers[col], self.columns)
|
||||||
item.setData(Qt.UserRole, QVariant(col))
|
item.setData(Qt.UserRole, QVariant(col))
|
||||||
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)
|
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)
|
||||||
if col in column_map:
|
item.setCheckState(Qt.Checked if col in column_map else Qt.Unchecked)
|
||||||
item.setCheckState(Qt.Checked)
|
|
||||||
else:
|
|
||||||
item.setCheckState(Qt.Unchecked)
|
|
||||||
self.connect(self.column_up, SIGNAL('clicked()'), self.up_column)
|
self.connect(self.column_up, SIGNAL('clicked()'), self.up_column)
|
||||||
self.connect(self.column_down, SIGNAL('clicked()'), self.down_column)
|
self.connect(self.column_down, SIGNAL('clicked()'), self.down_column)
|
||||||
|
|
||||||
@ -204,6 +202,8 @@ class ConfigDialog(QDialog, Ui_Dialog):
|
|||||||
prefs['network_timeout'] = int(self.timeout.value())
|
prefs['network_timeout'] = int(self.timeout.value())
|
||||||
path = qstring_to_unicode(self.location.text())
|
path = qstring_to_unicode(self.location.text())
|
||||||
cols = [unicode(self.columns.item(i).data(Qt.UserRole).toString()) for i in range(self.columns.count()) if self.columns.item(i).checkState()==Qt.Checked]
|
cols = [unicode(self.columns.item(i).data(Qt.UserRole).toString()) for i in range(self.columns.count()) if self.columns.item(i).checkState()==Qt.Checked]
|
||||||
|
if not cols:
|
||||||
|
cols = ['title']
|
||||||
config['column_map'] = cols
|
config['column_map'] = cols
|
||||||
config['toolbar_icon_size'] = self.ICON_SIZES[self.toolbar_button_size.currentIndex()]
|
config['toolbar_icon_size'] = self.ICON_SIZES[self.toolbar_button_size.currentIndex()]
|
||||||
config['show_text_in_toolbar'] = bool(self.show_toolbar_text.isChecked())
|
config['show_text_in_toolbar'] = bool(self.show_toolbar_text.isChecked())
|
||||||
|
@ -40,8 +40,7 @@ function create_table_headers() {
|
|||||||
|
|
||||||
|
|
||||||
function format_url(format, id, title) {
|
function format_url(format, id, title) {
|
||||||
return self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')) +
|
return 'get/'+format.toLowerCase() + '/'+title + '_' + id+'.'+format.toLowerCase();
|
||||||
'/get/'+format.toLowerCase() + '/'+title + '_' + id+'.'+format.toLowerCase();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function render_book(book) {
|
function render_book(book) {
|
||||||
@ -61,7 +60,7 @@ function render_book(book) {
|
|||||||
title += ' ({0} MB) '.format(size);
|
title += ' ({0} MB) '.format(size);
|
||||||
}
|
}
|
||||||
if (tags) title += '[{0}]'.format(tags);
|
if (tags) title += '[{0}]'.format(tags);
|
||||||
title += '<img style="display:none" alt="" src="{1}/get/cover/{0}" /></span>'.format(id, self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/')));
|
title += '<img style="display:none" alt="" src="get/cover/{0}" /></span>'.format(id);
|
||||||
title += '<p class="comments">{0}</p>'.format(comments)
|
title += '<p class="comments">{0}</p>'.format(comments)
|
||||||
// Render authors cell
|
// Render authors cell
|
||||||
var _authors = new Array();
|
var _authors = new Array();
|
||||||
@ -124,7 +123,7 @@ function fetch_library_books(start, num, timeout, sort, order, search) {
|
|||||||
|
|
||||||
current_library_request = $.ajax({
|
current_library_request = $.ajax({
|
||||||
type: "GET",
|
type: "GET",
|
||||||
url: self.location.pathname.substring(0,self.location.pathname.lastIndexOf('/'))+"/library",
|
url: "library",
|
||||||
data: data,
|
data: data,
|
||||||
cache: false,
|
cache: false,
|
||||||
timeout: timeout, //milliseconds
|
timeout: timeout, //milliseconds
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
"""
|
"""
|
||||||
@ -8,9 +9,10 @@ See ftp://ftp.rarlabs.com/rar/unrarsrc-3.7.5.tar.gz
|
|||||||
import os, ctypes, sys
|
import os, ctypes, sys
|
||||||
from ctypes import Structure, c_char_p, c_uint, c_void_p, POINTER, \
|
from ctypes import Structure, c_char_p, c_uint, c_void_p, POINTER, \
|
||||||
byref, c_wchar_p, c_int, c_char, c_wchar
|
byref, c_wchar_p, c_int, c_char, c_wchar
|
||||||
|
from tempfile import NamedTemporaryFile
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
from calibre import iswindows, load_library
|
from calibre import iswindows, load_library, CurrentDir
|
||||||
|
|
||||||
_librar_name = 'libunrar'
|
_librar_name = 'libunrar'
|
||||||
cdll = ctypes.cdll
|
cdll = ctypes.cdll
|
||||||
@ -182,3 +184,29 @@ def extract(path, dir):
|
|||||||
finally:
|
finally:
|
||||||
os.chdir(cwd)
|
os.chdir(cwd)
|
||||||
_libunrar.RARCloseArchive(arc_data)
|
_libunrar.RARCloseArchive(arc_data)
|
||||||
|
|
||||||
|
def extract_first(path, dir):
|
||||||
|
if hasattr(path, 'read'):
|
||||||
|
data = path.read()
|
||||||
|
f = NamedTemporaryFile(suffix='.rar')
|
||||||
|
f.write(data)
|
||||||
|
f.flush()
|
||||||
|
path = f.name
|
||||||
|
if not os.path.isdir( dir ):
|
||||||
|
os.makedirs(dir)
|
||||||
|
with CurrentDir(dir):
|
||||||
|
open_archive_data = RAROpenArchiveDataEx(ArcName=path, OpenMode=RAR_OM_EXTRACT, CmtBuf=None)
|
||||||
|
arc_data = _libunrar.RAROpenArchiveEx(byref(open_archive_data))
|
||||||
|
try:
|
||||||
|
if open_archive_data.OpenResult != 0:
|
||||||
|
raise UnRARException(_interpret_open_error(open_archive_data.OpenResult, path))
|
||||||
|
header_data = RARHeaderDataEx(CmtBuf=None)
|
||||||
|
if _libunrar.RARReadHeaderEx(arc_data, byref(header_data)) != 0:
|
||||||
|
raise UnRARException('%s has no files'%path)
|
||||||
|
PFCode = _libunrar.RARProcessFileW(arc_data, RAR_EXTRACT, None, None)
|
||||||
|
if PFCode != 0:
|
||||||
|
raise UnRARException(_interpret_process_file_error(PFCode))
|
||||||
|
finally:
|
||||||
|
_libunrar.RARCloseArchive(arc_data)
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import os
|
||||||
from calibre.utils import zipfile
|
from calibre.utils import zipfile
|
||||||
|
|
||||||
def update(pathtozip, patterns, filepaths, names, compression=zipfile.ZIP_DEFLATED, verbose=True):
|
def update(pathtozip, patterns, filepaths, names, compression=zipfile.ZIP_DEFLATED, verbose=True):
|
||||||
@ -41,3 +42,11 @@ def extract(filename, dir):
|
|||||||
"""
|
"""
|
||||||
zf = zipfile.ZipFile( filename )
|
zf = zipfile.ZipFile( filename )
|
||||||
zf.extractall(dir)
|
zf.extractall(dir)
|
||||||
|
|
||||||
|
def extract_first(filename, dir):
|
||||||
|
zf = zipfile.ZipFile(filename)
|
||||||
|
names = zf.namelist()
|
||||||
|
if not names:
|
||||||
|
raise ValueError('%s has no files'%filename)
|
||||||
|
bytes = zf.read(names[0])
|
||||||
|
open(os.path.join(dir, names[0]), 'wb').write(bytes)
|
@ -32,7 +32,6 @@
|
|||||||
|
|
||||||
</div>
|
</div>
|
||||||
<br />
|
<br />
|
||||||
<object width="250" height="250"><param name="movie" value="http://widget.chipin.com/widget/id/328a348be996a273"></param><param name="allowScriptAccess" value="always"></param><param name="wmode" value="transparent"></param><embed src="http://widget.chipin.com/widget/id/328a348be996a273" flashVars="" type="application/x-shockwave-flash" allowScriptAccess="always" wmode="transparent" width="250" height="250"></embed></object>
|
|
||||||
|
|
||||||
<h2>Note</h2>
|
<h2>Note</h2>
|
||||||
<div class="note">$note</div>
|
<div class="note">$note</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user