This commit is contained in:
GRiker 2012-09-21 04:02:53 -06:00
commit d850cec66f
186 changed files with 45580 additions and 31792 deletions

View File

@ -19,6 +19,62 @@
# new recipes:
# - title:
- version: 0.8.70
date: 2012-09-21
new features:
- title: "Support for connecting MTP (non disk based) devices via USB, such as the Nexus 7 and the Kindle Fire HD (Windows Vista and newer and Linux only)"
type: major
description: "calibre can now detect and connect to devices that do not present themselves as USB disks to the operating system. Newer Android devices all use the 'MTP' protocol when connected via USB. calibre now supports devices using this protocol on both Windows (Vista and newer) and Linux."
- title: "Calibre Portable: Create a new installer that does not require manually unzipping the Calibre Portable folder. Instead just run the installer and point it to the location you want to install to."
- title: "Calibre Portable: Add support for multiple libraries created inside the 'Calibre Portable' folder."
- title: "In the main book list when editing a blank published date, use a default value of Jan 2000 so that changing the date it easier"
- title: "Template language: Add function approximate_formats() to get list of formats saved in the db for a book as opposed to the formats that actually exist on disk"
- title: "Template language: Add a couple of new functions to get the path to individual book formats and the calibre library as a whole"
- title: "Drivers for HTC Flyer and Trekstor 4ink"
bug fixes:
- title: "Conversion: Do not error out when tags have unparseable color attributes."
tickets: [1053583]
- title: "AZW3 Output: Do not error out if the input document contains embedded fonts of less than 1040 bytes."
tickets: [1052892]
- title: "Catalogs: Fix AZW3 output not properly indexed"
- title: "Get Books: Remove Beam Books due to lack of response to issues with the store."
- title: "Windows: Ignore drives A: and B: when scanning for the drives belonging to a device"
- title: "Kindle driver: Fix generation of apnx files for newer kindle firmware."
- title: "News download: If the output format is set to azw3, generate periodicals in mobi format as amazon does not support azw3 periodicals."
improved recipes:
- Indian Express
- Anadtech
- London Review of Books (subscrption version)
- Livemint
- xkcd
- Doghouse Diaries
new recipes:
- title: Various Hungarian recipes
author: laca
- title: NSFW Corp
author: Darko Miletic.
- title: FC Knudde and Stamgasten
author: drMerry
- version: 0.8.69
date: 2012-09-14

View File

@ -9,7 +9,7 @@ the file are big-endian.
Layout
------
bytes content comments
bytes content comments
4 00010001 Format identifier. Value of 65537 little-endian.
4 start of next The offset after ending location of the first header.
@ -25,7 +25,7 @@ Starts next sequence
2 unknown Always 32
N second header String containing the page mapping header
4*N padding The first number given in the page mapping header indicates the number of 0 bytes.
4*N page list
4*N page list
Content Header
@ -44,6 +44,14 @@ Example:
{"contentGuid":"d8c14b0","asin":"B000JML5VM","cdeType":"EBOK","fileRevisionId":"1296874359405"}
In devices with KF8 support, we're seeing an extended content header (which seems to be required by some FW versions for KF8 files, like FW 3.4):
format Mobi version. MOBI_8 for KF8, MOBI_7 for legacy mobi files.
acr Palm DB name
Example:
{"contentGuid":"f2fc7597","asin":"B003M68YKM","cdeType":"EBOK","format":"MOBI_8","fileRevisionId":"1342776186889","acr":"CR!1F5WDHWWVN4Y78MA87Z13H9K6RKE"}
Page Mapping Header
-------------------

BIN
icons/install.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 25 KiB

237
imgsrc/mimetypes/azw2.svg Normal file
View File

@ -0,0 +1,237 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
width="128"
height="128"
id="svg2606"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="azw2.svg"
inkscape:export-filename="/home/niluje/Patchland/calibre/imgsrc/mimetypes/azw2.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1025"
id="namedview45"
showgrid="false"
inkscape:zoom="1.84375"
inkscape:cx="-11.118644"
inkscape:cy="42.305085"
inkscape:window-x="-2"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:current-layer="svg2606" />
<defs
id="defs2608">
<linearGradient
id="linearGradient10207">
<stop
id="stop10209"
style="stop-color:#a2a2a2;stop-opacity:1"
offset="0" />
<stop
id="stop10211"
style="stop-color:#ffffff;stop-opacity:1"
offset="1" />
</linearGradient>
<linearGradient
x1="96"
y1="104"
x2="88.000198"
y2="96.000198"
id="XMLID_12_"
gradientUnits="userSpaceOnUse">
<stop
id="stop83"
style="stop-color:#888a85;stop-opacity:1"
offset="0" />
<stop
id="stop85"
style="stop-color:#8c8e89;stop-opacity:1"
offset="0.0072" />
<stop
id="stop87"
style="stop-color:#abaca9;stop-opacity:1"
offset="0.0673" />
<stop
id="stop89"
style="stop-color:#c5c6c4;stop-opacity:1"
offset="0.1347" />
<stop
id="stop91"
style="stop-color:#dbdbda;stop-opacity:1"
offset="0.2652576" />
<stop
id="stop93"
style="stop-color:#ebebeb;stop-opacity:1"
offset="0.37646064" />
<stop
id="stop95"
style="stop-color:#f7f7f6;stop-opacity:1"
offset="0.48740286" />
<stop
id="stop97"
style="stop-color:#fdfdfd;stop-opacity:1"
offset="0.6324091" />
<stop
id="stop99"
style="stop-color:#ffffff;stop-opacity:1"
offset="1" />
</linearGradient>
<radialGradient
cx="102"
cy="112.3047"
r="139.55859"
id="XMLID_8_"
gradientUnits="userSpaceOnUse">
<stop
id="stop41"
style="stop-color:#b7b8b9;stop-opacity:1"
offset="0" />
<stop
id="stop47"
style="stop-color:#ececec;stop-opacity:1"
offset="0.18851049" />
<stop
id="stop49"
style="stop-color:#fafafa;stop-opacity:1"
offset="0.25718147" />
<stop
id="stop51"
style="stop-color:#ffffff;stop-opacity:1"
offset="0.30111277" />
<stop
id="stop53"
style="stop-color:#fafafa;stop-opacity:1"
offset="0.53130001" />
<stop
id="stop55"
style="stop-color:#ebecec;stop-opacity:1"
offset="0.84490001" />
<stop
id="stop57"
style="stop-color:#e1e2e3;stop-opacity:1"
offset="1" />
</radialGradient>
<filter
x="-0.19200002"
y="-0.19199999"
width="1.3839999"
height="1.3839999"
color-interpolation-filters="sRGB"
id="filter6697">
<feGaussianBlur
id="feGaussianBlur6699"
stdDeviation="1.9447689" />
</filter>
<clipPath
id="clipPath7084">
<path
d="m 72,88 -32,32 -8,0 0,-40 40,0 0,8 z"
id="path7086"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none" />
</clipPath>
<radialGradient
cx="102"
cy="112.3047"
r="139.55859"
id="radialGradient9437"
xlink:href="#XMLID_8_"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.9996653,2e-6,0.00301608)" />
<linearGradient
x1="98.617439"
y1="106.41443"
x2="91.228737"
y2="99.254974"
id="linearGradient10213"
xlink:href="#linearGradient10207"
gradientUnits="userSpaceOnUse" />
<filter
color-interpolation-filters="sRGB"
id="filter2770">
<feGaussianBlur
id="feGaussianBlur2772"
stdDeviation="2.0786429" />
</filter>
</defs>
<metadata
id="metadata2611">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1">
<path
d="m 16,8 0,112 c 0,0 63.15625,0 63.15625,0 l 0.03125,0 c 3e-6,0 11.90625,-9.90625 17.40625,-15.40625 C 102.09375,99.09375 112,87.1875 112,87.1875 L 112,87.15625 112,8 16,8 z"
transform="matrix(1.0416667,0,0,1.0267857,-2.6666667,-1.2142891)"
id="path7865"
style="opacity:0.5;fill:#000000;fill-opacity:1;filter:url(#filter2770)" />
<path
d="M 16.000001,8 16,120 c 0,0 63.146418,0 63.146418,0 L 112,87.14642 112,8 16.000001,8 z"
id="path34"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m 18.000002,9.0000034 c -0.551,0 -1,0.44885 -1,0.999665 l 0,107.9638516 c 0,0.55181 0.449,0.99966 1,0.99966 l 59.171997,0 c 0.263,0 2.76268,0.11813 2.948681,-0.0688 L 110.707,88.094202 C 110.894,87.907264 111,85.40942 111,85.146508 l 0,-75.1468396 c 0,-0.550815 -0.448,-0.999665 -1,-0.999665 l -91.999998,0 z"
id="path59"
style="fill:url(#radialGradient9437);fill-opacity:1" />
<path
d="m 41.879531,115.98249 c 0,0 24.309609,-24.309614 24.309609,-24.309614 0,0 -9.35314,2.913124 -19.60314,2.913124 0,10.25 -4.706469,21.39649 -4.706469,21.39649 z"
transform="translate(40,0)"
clip-path="url(#clipPath7084)"
id="path5540"
style="opacity:0.4;fill:#000000;fill-opacity:1;filter:url(#filter6697)" />
<path
d="m 79.172,120 c 0,0 11.914,-9.914 17.414,-15.414 5.5,-5.5 15.414,-17.414 15.414,-17.414 0,0 -13.75,8.828 -24,8.828 0,10.25 -8.828,24 -8.828,24 z"
id="path14523"
style="fill:url(#linearGradient10213);fill-opacity:1" />
<text
x="63.980469"
y="32.160156"
id="text3772"
xml:space="preserve"
style="font-size:24px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3021"
x="63.980469"
y="32.160156">Kindlet</tspan></text>
<path
d="m 68.227,60.477999 c 0,2.157 0.052,3.954 -1.035,5.874 -0.88,1.561 -2.279,2.517 -3.833,2.517 -2.121,0 -3.366,-1.62 -3.366,-4.015 C 59.993,60.14 64.225,59.283 68.226,59.283 v 1.194999 z m 5.579,13.496 c -0.365,0.332 -0.896,0.352 -1.307,0.132 -1.838,-1.528 -2.167,-2.231 -3.174,-3.69 -3.035,3.094 -5.188,4.023 -9.123,4.023 -4.663,0 -8.284,-2.876 -8.284,-8.629 0,-4.49 2.433,-7.543999 5.899,-9.044999 3.005,-1.317 7.202,-1.556 10.41,-1.914 v -0.723 c 0,-1.313 0.104,-2.875 -0.671,-4.012 -0.674,-1.021 -1.968,-1.437 -3.106,-1.437 -2.111,0 -3.99,1.078 -4.45,3.321 -0.097,0.498 -0.46,0.991 -0.962,1.017 l -5.364,-0.581 c -0.456,-0.102 -0.958,-0.463 -0.828,-1.155 1.233,-6.511 7.109,-8.475 12.378,-8.475 2.693,0 6.215,0.719 8.335,2.757 2.692997,2.515 2.431997,5.869 2.431997,9.524 v 8.622999 c 0,2.596 1.081,3.732 2.091,5.128 0.354,0.503 0.434,1.103 -0.018,1.473 -1.131,0.949 -3.138997,2.693 -4.243997,3.676 l -0.014,-0.013 z"
id="path4047"
style="fill-rule:evenodd" />
<path
d="m 99.325111,79.885297 c -8.716894,6.432161 -21.357191,9.853809 -32.243032,9.853809 -15.251419,0 -28.989193,-5.636741 -39.38419,-15.021522 -0.815557,-0.738364 -0.08726,-1.746902 0.89191,-1.173831 C 39.807066,80.071565 53.675732,84 68,84 c 9.664184,0 20.284886,-2.004491 30.058986,-6.151079 1.474215,-0.623415 2.709284,0.97246 1.266125,2.036376 z"
id="path3858"
style="fill:#ff9201;fill-rule:evenodd" />
<path
d="m 104,76 c -1.11342,-1.426386 -7.371903,-0.676274 -10.179364,-0.337298 -0.853315,0.09817 -0.984206,-0.641874 -0.217315,-1.184739 4.990671,-3.505554 13.168059,-2.491141 14.119539,-1.318987 0.95736,1.187256 -0.25087,9.384779 -4.92858,13.293915 -0.71907,0.604117 -1.40373,0.286117 -1.08573,-0.510142 C 102.75988,83.311486 105.11761,77.427225 104,76 z"
id="path3860"
style="fill:#ff9201;fill-rule:evenodd" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.1 KiB

237
imgsrc/mimetypes/azw3.svg Normal file
View File

@ -0,0 +1,237 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
width="128"
height="128"
id="svg2606"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="azw3.svg"
inkscape:export-filename="/home/niluje/Patchland/calibre/imgsrc/mimetypes/azw3.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1025"
id="namedview45"
showgrid="false"
inkscape:zoom="1.84375"
inkscape:cx="-11.118644"
inkscape:cy="42.305085"
inkscape:window-x="-2"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:current-layer="svg2606" />
<defs
id="defs2608">
<linearGradient
id="linearGradient10207">
<stop
id="stop10209"
style="stop-color:#a2a2a2;stop-opacity:1"
offset="0" />
<stop
id="stop10211"
style="stop-color:#ffffff;stop-opacity:1"
offset="1" />
</linearGradient>
<linearGradient
x1="96"
y1="104"
x2="88.000198"
y2="96.000198"
id="XMLID_12_"
gradientUnits="userSpaceOnUse">
<stop
id="stop83"
style="stop-color:#888a85;stop-opacity:1"
offset="0" />
<stop
id="stop85"
style="stop-color:#8c8e89;stop-opacity:1"
offset="0.0072" />
<stop
id="stop87"
style="stop-color:#abaca9;stop-opacity:1"
offset="0.0673" />
<stop
id="stop89"
style="stop-color:#c5c6c4;stop-opacity:1"
offset="0.1347" />
<stop
id="stop91"
style="stop-color:#dbdbda;stop-opacity:1"
offset="0.2652576" />
<stop
id="stop93"
style="stop-color:#ebebeb;stop-opacity:1"
offset="0.37646064" />
<stop
id="stop95"
style="stop-color:#f7f7f6;stop-opacity:1"
offset="0.48740286" />
<stop
id="stop97"
style="stop-color:#fdfdfd;stop-opacity:1"
offset="0.6324091" />
<stop
id="stop99"
style="stop-color:#ffffff;stop-opacity:1"
offset="1" />
</linearGradient>
<radialGradient
cx="102"
cy="112.3047"
r="139.55859"
id="XMLID_8_"
gradientUnits="userSpaceOnUse">
<stop
id="stop41"
style="stop-color:#b7b8b9;stop-opacity:1"
offset="0" />
<stop
id="stop47"
style="stop-color:#ececec;stop-opacity:1"
offset="0.18851049" />
<stop
id="stop49"
style="stop-color:#fafafa;stop-opacity:1"
offset="0.25718147" />
<stop
id="stop51"
style="stop-color:#ffffff;stop-opacity:1"
offset="0.30111277" />
<stop
id="stop53"
style="stop-color:#fafafa;stop-opacity:1"
offset="0.53130001" />
<stop
id="stop55"
style="stop-color:#ebecec;stop-opacity:1"
offset="0.84490001" />
<stop
id="stop57"
style="stop-color:#e1e2e3;stop-opacity:1"
offset="1" />
</radialGradient>
<filter
x="-0.19200002"
y="-0.19199999"
width="1.3839999"
height="1.3839999"
color-interpolation-filters="sRGB"
id="filter6697">
<feGaussianBlur
id="feGaussianBlur6699"
stdDeviation="1.9447689" />
</filter>
<clipPath
id="clipPath7084">
<path
d="m 72,88 -32,32 -8,0 0,-40 40,0 0,8 z"
id="path7086"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none" />
</clipPath>
<radialGradient
cx="102"
cy="112.3047"
r="139.55859"
id="radialGradient9437"
xlink:href="#XMLID_8_"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.9996653,2e-6,0.00301608)" />
<linearGradient
x1="98.617439"
y1="106.41443"
x2="91.228737"
y2="99.254974"
id="linearGradient10213"
xlink:href="#linearGradient10207"
gradientUnits="userSpaceOnUse" />
<filter
color-interpolation-filters="sRGB"
id="filter2770">
<feGaussianBlur
id="feGaussianBlur2772"
stdDeviation="2.0786429" />
</filter>
</defs>
<metadata
id="metadata2611">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title />
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1">
<path
d="m 16,8 0,112 c 0,0 63.15625,0 63.15625,0 l 0.03125,0 c 3e-6,0 11.90625,-9.90625 17.40625,-15.40625 C 102.09375,99.09375 112,87.1875 112,87.1875 L 112,87.15625 112,8 16,8 z"
transform="matrix(1.0416667,0,0,1.0267857,-2.6666667,-1.2142891)"
id="path7865"
style="opacity:0.5;fill:#000000;fill-opacity:1;filter:url(#filter2770)" />
<path
d="M 16.000001,8 16,120 c 0,0 63.146418,0 63.146418,0 L 112,87.14642 112,8 16.000001,8 z"
id="path34"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m 18.000002,9.0000034 c -0.551,0 -1,0.44885 -1,0.999665 l 0,107.9638516 c 0,0.55181 0.449,0.99966 1,0.99966 l 59.171997,0 c 0.263,0 2.76268,0.11813 2.948681,-0.0688 L 110.707,88.094202 C 110.894,87.907264 111,85.40942 111,85.146508 l 0,-75.1468396 c 0,-0.550815 -0.448,-0.999665 -1,-0.999665 l -91.999998,0 z"
id="path59"
style="fill:url(#radialGradient9437);fill-opacity:1" />
<path
d="m 41.879531,115.98249 c 0,0 24.309609,-24.309614 24.309609,-24.309614 0,0 -9.35314,2.913124 -19.60314,2.913124 0,10.25 -4.706469,21.39649 -4.706469,21.39649 z"
transform="translate(40,0)"
clip-path="url(#clipPath7084)"
id="path5540"
style="opacity:0.4;fill:#000000;fill-opacity:1;filter:url(#filter6697)" />
<path
d="m 79.172,120 c 0,0 11.914,-9.914 17.414,-15.414 5.5,-5.5 15.414,-17.414 15.414,-17.414 0,0 -13.75,8.828 -24,8.828 0,10.25 -8.828,24 -8.828,24 z"
id="path14523"
style="fill:url(#linearGradient10213);fill-opacity:1" />
<text
x="64.392578"
y="32.103516"
id="text3772"
xml:space="preserve"
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3026"
x="64.392578"
y="32.103516">KF8</tspan></text>
<path
d="m 68.227,60.477999 c 0,2.157 0.052,3.954 -1.035,5.874 -0.88,1.561 -2.279,2.517 -3.833,2.517 -2.121,0 -3.366,-1.62 -3.366,-4.015 C 59.993,60.14 64.225,59.283 68.226,59.283 v 1.194999 z m 5.579,13.496 c -0.365,0.332 -0.896,0.352 -1.307,0.132 -1.838,-1.528 -2.167,-2.231 -3.174,-3.69 -3.035,3.094 -5.188,4.023 -9.123,4.023 -4.663,0 -8.284,-2.876 -8.284,-8.629 0,-4.49 2.433,-7.543999 5.899,-9.044999 3.005,-1.317 7.202,-1.556 10.41,-1.914 v -0.723 c 0,-1.313 0.104,-2.875 -0.671,-4.012 -0.674,-1.021 -1.968,-1.437 -3.106,-1.437 -2.111,0 -3.99,1.078 -4.45,3.321 -0.097,0.498 -0.46,0.991 -0.962,1.017 l -5.364,-0.581 c -0.456,-0.102 -0.958,-0.463 -0.828,-1.155 1.233,-6.511 7.109,-8.475 12.378,-8.475 2.693,0 6.215,0.719 8.335,2.757 2.692997,2.515 2.431997,5.869 2.431997,9.524 v 8.622999 c 0,2.596 1.081,3.732 2.091,5.128 0.354,0.503 0.434,1.103 -0.018,1.473 -1.131,0.949 -3.138997,2.693 -4.243997,3.676 l -0.014,-0.013 z"
id="path4047"
style="fill-rule:evenodd" />
<path
d="m 99.325111,79.885297 c -8.716894,6.432161 -21.357191,9.853809 -32.243032,9.853809 -15.251419,0 -28.989193,-5.636741 -39.38419,-15.021522 -0.815557,-0.738364 -0.08726,-1.746902 0.89191,-1.173831 C 39.807066,80.071565 53.675732,84 68,84 c 9.664184,0 20.284886,-2.004491 30.058986,-6.151079 1.474215,-0.623415 2.709284,0.97246 1.266125,2.036376 z"
id="path3858"
style="fill:#ff9201;fill-rule:evenodd" />
<path
d="m 104,76 c -1.11342,-1.426386 -7.371903,-0.676274 -10.179364,-0.337298 -0.853315,0.09817 -0.984206,-0.641874 -0.217315,-1.184739 4.990671,-3.505554 13.168059,-2.491141 14.119539,-1.318987 0.95736,1.187256 -0.25087,9.384779 -4.92858,13.293915 -0.71907,0.604117 -1.40373,0.286117 -1.08573,-0.510142 C 102.75988,83.311486 105.11761,77.427225 104,76 z"
id="path3860"
style="fill:#ff9201;fill-rule:evenodd" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -8,10 +8,37 @@
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
width="128"
height="128"
id="svg2606">
id="svg2606"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="mobi.svg"
inkscape:export-filename="/home/niluje/Patchland/calibre/imgsrc/mimetypes/mobi.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1025"
id="namedview45"
showgrid="false"
inkscape:zoom="1.84375"
inkscape:cx="64"
inkscape:cy="64"
inkscape:window-x="-2"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:current-layer="svg2606" />
<defs
id="defs2608">
<linearGradient
@ -184,15 +211,16 @@
id="path14523"
style="fill:url(#linearGradient10213);fill-opacity:1" />
<text
x="32"
y="32"
x="64.902344"
y="32.103516"
id="text3772"
xml:space="preserve"
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;fill:#000000;fill-opacity:1;stroke:none;font-family:FreeSans;-inkscape-font-specification:FreeSans"><tspan
x="32"
y="32"
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
sodipodi:linespacing="125%"><tspan
x="64.902344"
y="32.103516"
id="tspan3774"
style="font-size:28px;fill:#000000;fill-opacity:1">mobi</tspan></text>
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans">mobi</tspan></text>
<path
d="m 68.227,60.477999 c 0,2.157 0.052,3.954 -1.035,5.874 -0.88,1.561 -2.279,2.517 -3.833,2.517 -2.121,0 -3.366,-1.62 -3.366,-4.015 C 59.993,60.14 64.225,59.283 68.226,59.283 v 1.194999 z m 5.579,13.496 c -0.365,0.332 -0.896,0.352 -1.307,0.132 -1.838,-1.528 -2.167,-2.231 -3.174,-3.69 -3.035,3.094 -5.188,4.023 -9.123,4.023 -4.663,0 -8.284,-2.876 -8.284,-8.629 0,-4.49 2.433,-7.543999 5.899,-9.044999 3.005,-1.317 7.202,-1.556 10.41,-1.914 v -0.723 c 0,-1.313 0.104,-2.875 -0.671,-4.012 -0.674,-1.021 -1.968,-1.437 -3.106,-1.437 -2.111,0 -3.99,1.078 -4.45,3.321 -0.097,0.498 -0.46,0.991 -0.962,1.017 l -5.364,-0.581 c -0.456,-0.102 -0.958,-0.463 -0.828,-1.155 1.233,-6.511 7.109,-8.475 12.378,-8.475 2.693,0 6.215,0.719 8.335,2.757 2.692997,2.515 2.431997,5.869 2.431997,9.524 v 8.622999 c 0,2.596 1.081,3.732 2.091,5.128 0.354,0.503 0.434,1.103 -0.018,1.473 -1.131,0.949 -3.138997,2.693 -4.243997,3.676 l -0.014,-0.013 z"
id="path4047"

Before

Width:  |  Height:  |  Size: 8.1 KiB

After

Width:  |  Height:  |  Size: 9.3 KiB

237
imgsrc/mimetypes/tpz.svg Normal file
View File

@ -0,0 +1,237 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.0"
width="128"
height="128"
id="svg2606"
inkscape:version="0.48.3.1 r9886"
sodipodi:docname="tpz.svg"
inkscape:export-filename="/home/niluje/Patchland/calibre/imgsrc/mimetypes/tpz.png"
inkscape:export-xdpi="90"
inkscape:export-ydpi="90">
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1920"
inkscape:window-height="1025"
id="namedview45"
showgrid="false"
inkscape:zoom="1.84375"
inkscape:cx="-11.118644"
inkscape:cy="42.305085"
inkscape:window-x="-2"
inkscape:window-y="-3"
inkscape:window-maximized="1"
inkscape:current-layer="svg2606" />
<defs
id="defs2608">
<linearGradient
id="linearGradient10207">
<stop
id="stop10209"
style="stop-color:#a2a2a2;stop-opacity:1"
offset="0" />
<stop
id="stop10211"
style="stop-color:#ffffff;stop-opacity:1"
offset="1" />
</linearGradient>
<linearGradient
x1="96"
y1="104"
x2="88.000198"
y2="96.000198"
id="XMLID_12_"
gradientUnits="userSpaceOnUse">
<stop
id="stop83"
style="stop-color:#888a85;stop-opacity:1"
offset="0" />
<stop
id="stop85"
style="stop-color:#8c8e89;stop-opacity:1"
offset="0.0072" />
<stop
id="stop87"
style="stop-color:#abaca9;stop-opacity:1"
offset="0.0673" />
<stop
id="stop89"
style="stop-color:#c5c6c4;stop-opacity:1"
offset="0.1347" />
<stop
id="stop91"
style="stop-color:#dbdbda;stop-opacity:1"
offset="0.2652576" />
<stop
id="stop93"
style="stop-color:#ebebeb;stop-opacity:1"
offset="0.37646064" />
<stop
id="stop95"
style="stop-color:#f7f7f6;stop-opacity:1"
offset="0.48740286" />
<stop
id="stop97"
style="stop-color:#fdfdfd;stop-opacity:1"
offset="0.6324091" />
<stop
id="stop99"
style="stop-color:#ffffff;stop-opacity:1"
offset="1" />
</linearGradient>
<radialGradient
cx="102"
cy="112.3047"
r="139.55859"
id="XMLID_8_"
gradientUnits="userSpaceOnUse">
<stop
id="stop41"
style="stop-color:#b7b8b9;stop-opacity:1"
offset="0" />
<stop
id="stop47"
style="stop-color:#ececec;stop-opacity:1"
offset="0.18851049" />
<stop
id="stop49"
style="stop-color:#fafafa;stop-opacity:1"
offset="0.25718147" />
<stop
id="stop51"
style="stop-color:#ffffff;stop-opacity:1"
offset="0.30111277" />
<stop
id="stop53"
style="stop-color:#fafafa;stop-opacity:1"
offset="0.53130001" />
<stop
id="stop55"
style="stop-color:#ebecec;stop-opacity:1"
offset="0.84490001" />
<stop
id="stop57"
style="stop-color:#e1e2e3;stop-opacity:1"
offset="1" />
</radialGradient>
<filter
x="-0.19200002"
y="-0.19199999"
width="1.3839999"
height="1.3839999"
color-interpolation-filters="sRGB"
id="filter6697">
<feGaussianBlur
id="feGaussianBlur6699"
stdDeviation="1.9447689" />
</filter>
<clipPath
id="clipPath7084">
<path
d="m 72,88 -32,32 -8,0 0,-40 40,0 0,8 z"
id="path7086"
style="fill:#000000;fill-opacity:1;fill-rule:evenodd;stroke:none" />
</clipPath>
<radialGradient
cx="102"
cy="112.3047"
r="139.55859"
id="radialGradient9437"
xlink:href="#XMLID_8_"
gradientUnits="userSpaceOnUse"
gradientTransform="matrix(1,0,0,0.9996653,2e-6,0.00301608)" />
<linearGradient
x1="98.617439"
y1="106.41443"
x2="91.228737"
y2="99.254974"
id="linearGradient10213"
xlink:href="#linearGradient10207"
gradientUnits="userSpaceOnUse" />
<filter
color-interpolation-filters="sRGB"
id="filter2770">
<feGaussianBlur
id="feGaussianBlur2772"
stdDeviation="2.0786429" />
</filter>
</defs>
<metadata
id="metadata2611">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
<dc:title></dc:title>
</cc:Work>
</rdf:RDF>
</metadata>
<g
id="layer1">
<path
d="m 16,8 0,112 c 0,0 63.15625,0 63.15625,0 l 0.03125,0 c 3e-6,0 11.90625,-9.90625 17.40625,-15.40625 C 102.09375,99.09375 112,87.1875 112,87.1875 L 112,87.15625 112,8 16,8 z"
transform="matrix(1.0416667,0,0,1.0267857,-2.6666667,-1.2142891)"
id="path7865"
style="opacity:0.5;fill:#000000;fill-opacity:1;filter:url(#filter2770)" />
<path
d="M 16.000001,8 16,120 c 0,0 63.146418,0 63.146418,0 L 112,87.14642 112,8 16.000001,8 z"
id="path34"
style="fill:#ffffff;fill-opacity:1" />
<path
d="m 18.000002,9.0000034 c -0.551,0 -1,0.44885 -1,0.999665 l 0,107.9638516 c 0,0.55181 0.449,0.99966 1,0.99966 l 59.171997,0 c 0.263,0 2.76268,0.11813 2.948681,-0.0688 L 110.707,88.094202 C 110.894,87.907264 111,85.40942 111,85.146508 l 0,-75.1468396 c 0,-0.550815 -0.448,-0.999665 -1,-0.999665 l -91.999998,0 z"
id="path59"
style="fill:url(#radialGradient9437);fill-opacity:1" />
<path
d="m 41.879531,115.98249 c 0,0 24.309609,-24.309614 24.309609,-24.309614 0,0 -9.35314,2.913124 -19.60314,2.913124 0,10.25 -4.706469,21.39649 -4.706469,21.39649 z"
transform="translate(40,0)"
clip-path="url(#clipPath7084)"
id="path5540"
style="opacity:0.4;fill:#000000;fill-opacity:1;filter:url(#filter6697)" />
<path
d="m 79.172,120 c 0,0 11.914,-9.914 17.414,-15.414 5.5,-5.5 15.414,-17.414 15.414,-17.414 0,0 -13.75,8.828 -24,8.828 0,10.25 -8.828,24 -8.828,24 z"
id="path14523"
style="fill:url(#linearGradient10213);fill-opacity:1" />
<text
x="64.703125"
y="32.175781"
id="text3772"
xml:space="preserve"
style="font-size:28px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:center;line-height:125%;writing-mode:lr-tb;text-anchor:middle;fill:#000000;fill-opacity:1;stroke:none;font-family:DejaVu Sans;-inkscape-font-specification:DejaVu Sans"
sodipodi:linespacing="125%"><tspan
sodipodi:role="line"
id="tspan3021"
x="64.703125"
y="32.175781">Topaz</tspan></text>
<path
d="m 68.227,60.477999 c 0,2.157 0.052,3.954 -1.035,5.874 -0.88,1.561 -2.279,2.517 -3.833,2.517 -2.121,0 -3.366,-1.62 -3.366,-4.015 C 59.993,60.14 64.225,59.283 68.226,59.283 v 1.194999 z m 5.579,13.496 c -0.365,0.332 -0.896,0.352 -1.307,0.132 -1.838,-1.528 -2.167,-2.231 -3.174,-3.69 -3.035,3.094 -5.188,4.023 -9.123,4.023 -4.663,0 -8.284,-2.876 -8.284,-8.629 0,-4.49 2.433,-7.543999 5.899,-9.044999 3.005,-1.317 7.202,-1.556 10.41,-1.914 v -0.723 c 0,-1.313 0.104,-2.875 -0.671,-4.012 -0.674,-1.021 -1.968,-1.437 -3.106,-1.437 -2.111,0 -3.99,1.078 -4.45,3.321 -0.097,0.498 -0.46,0.991 -0.962,1.017 l -5.364,-0.581 c -0.456,-0.102 -0.958,-0.463 -0.828,-1.155 1.233,-6.511 7.109,-8.475 12.378,-8.475 2.693,0 6.215,0.719 8.335,2.757 2.692997,2.515 2.431997,5.869 2.431997,9.524 v 8.622999 c 0,2.596 1.081,3.732 2.091,5.128 0.354,0.503 0.434,1.103 -0.018,1.473 -1.131,0.949 -3.138997,2.693 -4.243997,3.676 l -0.014,-0.013 z"
id="path4047"
style="fill-rule:evenodd" />
<path
d="m 99.325111,79.885297 c -8.716894,6.432161 -21.357191,9.853809 -32.243032,9.853809 -15.251419,0 -28.989193,-5.636741 -39.38419,-15.021522 -0.815557,-0.738364 -0.08726,-1.746902 0.89191,-1.173831 C 39.807066,80.071565 53.675732,84 68,84 c 9.664184,0 20.284886,-2.004491 30.058986,-6.151079 1.474215,-0.623415 2.709284,0.97246 1.266125,2.036376 z"
id="path3858"
style="fill:#ff9201;fill-rule:evenodd" />
<path
d="m 104,76 c -1.11342,-1.426386 -7.371903,-0.676274 -10.179364,-0.337298 -0.853315,0.09817 -0.984206,-0.641874 -0.217315,-1.184739 4.990671,-3.505554 13.168059,-2.491141 14.119539,-1.318987 0.95736,1.187256 -0.25087,9.384779 -4.92858,13.293915 -0.71907,0.604117 -1.40373,0.286117 -1.08573,-0.510142 C 102.75988,83.311486 105.11761,77.427225 104,76 z"
id="path3860"
style="fill:#ff9201;fill-rule:evenodd" />
</g>
</svg>

After

Width:  |  Height:  |  Size: 9.1 KiB

View File

@ -126,9 +126,11 @@ Device Integration
What devices does |app| support?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At the moment |app| has full support for the SONY PRS line, Barnes & Noble Nook line, Cybook Gen 3/Opus, Amazon Kindle line, Entourage Edge, Longshine ShineBook, Ectaco Jetbook, BeBook/BeBook Mini, Irex Illiad/DR1000, Foxit eSlick, PocketBook line, Italica, eClicto, Iriver Story, Airis dBook, Hanvon N515, Binatone Readme, Teclast K3 and clones, SpringDesign Alex, Kobo Reader, various Android phones and the iPhone/iPad. In addition, using the :guilabel:`Connect to folder` function you can use it with any ebook reader that exports itself as a USB disk.
There is also a special ``User Defined`` device plugin that can be used to connect to arbitrary devices that present their memory as disk drives. See the device plugin ``Preferences -> Plugins -> Device Plugins -> User Defined`` and ``Preferences -> Miscelleaneous -> Get information to setup the user defined device`` for more information.
|app| can directly connect to all the major (and most of the minor) ebook reading devices,
smarthphones, tablets, etc.
In addition, using the :guilabel:`Connect to folder` function you can use it with any ebook reader that exports itself as a USB disk.
You can even connect to Apple devices (via iTunes), using the :guilabel:`Connect to iTunes`
function.
.. _devsupport:
@ -159,8 +161,8 @@ Follow these steps to find the problem:
* Make sure that you are connecting only a single device to your computer at a time. Do not have another |app| supported device like an iPhone/iPad etc. at the same time.
* If you are connecting an Apple iDevice (iPad, iPod Touch, iPhone), use the 'Connect to iTunes' method in the 'Getting started' instructions in `Calibre + Apple iDevices: Start here <http://www.mobileread.com/forums/showthread.php?t=118559>`_.
* Make sure you are running the latest version of |app|. The latest version can always be downloaded from `the calibre website <http://calibre-ebook.com/download>`_.
* Ensure your operating system is seeing the device. That is, the device should be mounted as a disk, that you can access using Windows explorer or whatever the file management program on your computer is. On Windows your device **must have been assigned a drive letter**, like K:.
* In calibre, go to Preferences->Plugins->Device Interface plugin and make sure the plugin for your device is enabled, the plugin icon next to it should be green when it is enabled.
* Ensure your operating system is seeing the device. That is, the device should show up in Windows Explorer (in Windows) or Finder (in OS X).
* In |app|, go to Preferences->Plugins->Device Interface plugin and make sure the plugin for your device is enabled, the plugin icon next to it should be green when it is enabled.
* If all the above steps fail, go to Preferences->Miscellaneous and click debug device detection with your device attached and post the output as a ticket on `the calibre bug tracker <http://bugs.calibre-ebook.com>`_.
My device is non-standard or unusual. What can I do to connect to it?
@ -285,20 +287,47 @@ This method only works on Windows XP and higher, and OS X 10.5 and higher. Linux
How do I use |app| with my Android phone/tablet?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There are two ways that you can connect your Android device to calibre. Using a USB cable-- or wirelessly, over the air.
**The USB cable method only works if your Android device can act as a USB disk, that means in windows it must have a drive letter, like K:**. Some devices may have a setting to put them in "disk mode" or "USB Transfer mode" that is needed before they act as USB disks.
There are two ways that you can connect your Android device to calibre. Using a USB cable -- or wirelessly, over the air.
The first step to using an Android device is installing an ebook reading
application on it. There are many free and paid ebook reading applications for
Android: Some examples (in no particular order):
`FBReader <https://play.google.com/store/apps/details?id=org.geometerplus.zlibrary.ui.android&hl=en>`_,
`Moon+ <https://play.google.com/store/apps/details?id=com.flyersoft.moonreader&hl=en>`_,
`Mantano <https://play.google.com/store/apps/details?id=com.mantano.reader.android.lite&hl=en>`_,
`Aldiko <https://play.google.com/store/apps/details?id=com.aldiko.android&hl=en>`_,
`Kindle <https://play.google.com/store/apps/details?id=com.amazon.kindle&feature=related_apps>`_.
Using a USB cable
^^^^^^^^^^^^^^^^^^^^
First install either the WordPlayer or Aldiko ebook reading apps from the Android Marketplace onto your phone. Then simply plug your phone into the computer with a USB cable. |app| should automatically detect the phone and then you can transfer books to it by clicking the Send to Device button. |app| does not have support for every single android device out there, so if your device is not automatically detected, follow the instructions at :ref:`devsupport` to get your device supported in |app|.
Simply plug your device into the computer with a USB cable. |app| should
automatically detect the device and then you can transfer books to it by
clicking the Send to Device button. |app| does not have support for every
single android device out there, so if your device is not automatically
detected, follow the instructions at :ref:`devsupport` to get your device
supported in |app|.
.. note:: With newer Android devices, the USB connection is only supported on
Windows Vista and newer and Linux. If you are on Windows XP or OS X,
you should use one of the wireless connection methods.
Over the air
^^^^^^^^^^^^^^
The easiest way to browse your |app| collection on your Android device is by using the calibre content server, which makes your collection available over the net. First perform the following steps in |app|
The easiest way to transfer books wirelessly to your Android device is to use
the `Calibre Companion <http://www.multipie.co.uk/calibre-companion/>`_
Android app. This app is maintained by a core calibre developer and allows
|app| to connect to your Android device wirelessly, just as though you
plugged in the device with a USB cable. You can browse files on the device
in |app| and use the :guilabel:`Send to device` button to transfer files to
your device wirelessly.
* Set the Preferred Output Format in |app| to EPUB (The output format can be set under :guilabel:`Preferences->Interface->Behavior`)
|app| also has a builtin web server, the :guilabel:`Content Server`.
You can browse your |app| collection on your Android device is by using the
calibre content server, which makes your collection available over the net.
First perform the following steps in |app|
* Set the :guilabel:`Preferred Output Format` in |app| to EPUB (The output format can be set under :guilabel:`Preferences->Interface->Behavior`)
* Set the output profile to Tablet (this will work for phones as well), under :guilabel:`Preferences->Conversion->Common Options->Page Setup`
* Convert the books you want to read on your device to EPUB format by selecting them and clicking the Convert button.
* Turn on the Content Server in |app|'s preferences and leave |app| running.
@ -307,11 +336,22 @@ Now on your Android device, open the browser and browse to
http://192.168.1.2:8080/
Replace ``192.168.1.2`` with the local IP address of the computer running |app|. If your local network supports the use of computer names, you can replace the IP address with the network name of the computer. If you have changed the port the |app| content server is running on, you will have to change ``8080`` as well to the new port.
Replace ``192.168.1.2`` with the local IP address of the computer running
|app|. If your local network supports the use of computer names, you can
replace the IP address with the network name of the computer. If you have
changed the port the |app| content server is running on, you will have to
change ``8080`` as well to the new port.
The local IP address is the IP address you computer is assigned on your home network. A quick Google search will tell you how to find out your local IP address. You can now browse your book collection and download books from |app| to your device to open with whatever ebook reading software you have on your android device.
The local IP address is the IP address you computer is assigned on your home
network. A quick Google search will tell you how to find out your local IP
address. You can now browse your book collection and download books from |app|
to your device to open with whatever ebook reading software you have on your
android device.
Some reading programs support browsing the Calibre library directly. For example, in Aldiko, click My Catalogs, then + to add a catalog, then give the catalog a title such as "Calibre" and provide the URL listed above. You can now browse the Calibre library and download directly into the reading software.
Some reading programs support browsing the Calibre library directly. For
example, in Aldiko, click My Catalogs, then + to add a catalog, then give the
catalog a title such as "Calibre" and provide the URL listed above. You can now
browse the Calibre library and download directly into the reading software.
Can I access my |app| books using the web browser in my Kindle or other reading device?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

View File

@ -240,9 +240,11 @@ The following functions are available in addition to those described in single-f
* ``and(value, value, ...)`` -- returns the string "1" if all values are not empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want.
* ``add(x, y)`` -- returns x + y. Throws an exception if either x or y are not numbers.
* ``assign(id, val)`` -- assigns val to id, then returns val. id must be an identifier, not an expression
* ``approximate_formats()`` -- return a comma-separated list of formats that at one point were associated with the book. There is no guarantee that the list is correct, although it probably is. This function can be called in template program mode using the template ``{:'approximate_formats()'}``. Note that format names are always uppercase, as in EPUB.
* ``booksize()`` -- returns the value of the |app| 'size' field. Returns '' if there are no formats.
* ``cmp(x, y, lt, eq, gt)`` -- compares x and y after converting both to numbers. Returns ``lt`` if x < y. Returns ``eq`` if x == y. Otherwise returns ``gt``.
* ``current_library_name() -- `` return the last name on the path to the current calibre library. This function can be called in template program mode using the template ``{:'current_library_name()'}``.
* ``current_library_path() -- `` eturn the path to the current calibre library. This function can be called in template program mode using the template ``{:'current_library_path()'}``..
* ``days_between(date1, date2)`` -- return the number of days between ``date1`` and ``date2``. The number is positive if ``date1`` is greater than ``date2``, otherwise negative. If either ``date1`` or ``date2`` are not dates, the function returns the empty string.
* ``divide(x, y)`` -- returns x / y. Throws an exception if either x or y are not numbers.
* ``eval(string)`` -- evaluates the string as a program, passing the local variables (those ``assign`` ed to). This permits using the template processor to construct complex results from local variables. Because the `{` and `}` characters are special, you must use `[[` for the `{` character and `]]` for the '}' character; they are converted automatically. Note also that prefixes and suffixes (the `|prefix|suffix` syntax) cannot be used in the argument to this function when using template program mode.
@ -284,6 +286,7 @@ The following functions are available in addition to those described in single-f
)
* ``formats_modtimes(date_format)`` -- return a comma-separated list of colon_separated items representing modification times for the formats of a book. The date_format parameter specifies how the date is to be formatted. See the date_format function for details. You can use the select function to get the mod time for a specific format. Note that format names are always uppercase, as in EPUB.
* ``formats_paths()`` -- return a comma-separated list of colon_separated items representing full path to the formats of a book. You can use the select function to get the path for a specific format. Note that format names are always uppercase, as in EPUB.
* ``formats_sizes()`` -- return a comma-separated list of colon_separated items representing sizes in bytes of the formats of a book. You can use the select function to get the size for a specific format. Note that format names are always uppercase, as in EPUB.
* ``has_cover()`` -- return ``Yes`` if the book has a cover, otherwise return the empty string
* ``not(value)`` -- returns the string "1" if the value is empty, otherwise returns the empty string. This function works well with test or first_non_empty. You can have as many values as you want.

View File

@ -12,25 +12,26 @@ class anan(BasicNewsRecipe):
title = 'Anandtech'
description = 'comprehensive Hardware Tests'
__author__ = 'Oliver Niesner'
__author__ = 'Oliver Niesner' # 2012-09-20 AGE: update
use_embedded_content = False
language = 'en'
timefmt = ' [%d %b %Y]'
oldest_article = 7 # 2012-09-20 AGE: update
max_articles_per_feed = 40
no_stylesheets = True
remove_javascript = True
encoding = 'utf-8'
remove_tags=[
dict(name='a', attrs={'style':'width:110px; margin-top:0px;text-align:center;'}),
dict(name='a', attrs={'style':'width:110px; margin-top:0px; margin-right:20px;text-align:center;'}),
{'attrs':{'class':['article_links', 'header', 'body_right']}},
{'id':['crumbs']},
]
cover_url = 'http://www.anandtech.com/content/images/globals/header_logo.png' # 2012-09-20 AGE: new
masthead_url = 'http://www.anandtech.com/content/images/globals/printheader.png' # 2012-09-20 AGE: update
remove_tags=[
dict(name='a', attrs={'class': 'bluebutton noprint'}),
dict(name='img', attrs={'alt': 'header'}),
] # 2012-09-20 AGE: update
feeds = [ ('Anandtech', 'http://www.anandtech.com/rss/')]
def print_version(self,url):
return url.replace('/show/', '/print/')
return url.replace('0Cshow0C', '0Cprint0C') # 2012-09-20 AGE: update

View File

@ -1,105 +0,0 @@
__license__ = 'GPL v3'
__copyright__ = '2008 Kovid Goyal kovid@kovidgoyal.net, 2010 Darko Miletic <darko.miletic at gmail.com>'
'''
www.businessweek.com
'''
from calibre.web.feeds.news import BasicNewsRecipe
class BusinessWeek(BasicNewsRecipe):
title = 'Business Week'
__author__ = 'Kovid Goyal and Darko Miletic'
description = 'Read the latest international business news & stock market news. Get updated company profiles, financial advice, global economy and technology news.'
publisher = 'Bloomberg L.P.'
category = 'Business, business news, stock market, stock market news, financial advice, company profiles, financial advice, global economy, technology news'
oldest_article = 7
max_articles_per_feed = 200
no_stylesheets = True
encoding = 'utf8'
use_embedded_content = False
language = 'en'
remove_empty_feeds = True
publication_type = 'magazine'
cover_url = 'http://images.businessweek.com/mz/covers/current_120x160.jpg'
masthead_url = 'http://assets.businessweek.com/images/bw-logo.png'
extra_css = """
body{font-family: Helvetica,Arial,sans-serif }
img{margin-bottom: 0.4em; display:block}
.tagline{color: gray; font-style: italic}
.photoCredit{font-size: small; color: gray}
"""
conversion_options = {
'comment' : description
, 'tags' : category
, 'publisher' : publisher
, 'language' : language
}
remove_tags = [
dict(attrs={'class':'inStory'})
,dict(name=['meta','link','iframe','base','embed','object','table','th','tr','td'])
,dict(attrs={'id':['inset','videoDisplay']})
]
keep_only_tags = [dict(name='div', attrs={'id':['story-body','storyBody','article_body','articleBody']})]
remove_attributes = ['lang']
match_regexps = [r'http://www.businessweek.com/.*_page_[1-9].*']
feeds = [
(u'Top Stories', u'http://www.businessweek.com/topStories/rss/topStories.rss'),
(u'Top News' , u'http://www.businessweek.com/rss/bwdaily.rss' ),
(u'Asia', u'http://www.businessweek.com/rss/asia.rss'),
(u'Autos', u'http://www.businessweek.com/rss/autos/index.rss'),
(u'Classic Cars', u'http://rss.businessweek.com/bw_rss/classiccars'),
(u'Hybrids', u'http://rss.businessweek.com/bw_rss/hybrids'),
(u'Europe', u'http://www.businessweek.com/rss/europe.rss'),
(u'Auto Reviews', u'http://rss.businessweek.com/bw_rss/autoreviews'),
(u'Innovation & Design', u'http://www.businessweek.com/rss/innovate.rss'),
(u'Architecture', u'http://www.businessweek.com/rss/architecture.rss'),
(u'Brand Equity', u'http://www.businessweek.com/rss/brandequity.rss'),
(u'Auto Design', u'http://www.businessweek.com/rss/carbuff.rss'),
(u'Game Room', u'http://rss.businessweek.com/bw_rss/gameroom'),
(u'Technology', u'http://www.businessweek.com/rss/technology.rss'),
(u'Investing', u'http://rss.businessweek.com/bw_rss/investor'),
(u'Small Business', u'http://www.businessweek.com/rss/smallbiz.rss'),
(u'Careers', u'http://rss.businessweek.com/bw_rss/careers'),
(u'B-Schools', u'http://www.businessweek.com/rss/bschools.rss'),
(u'Magazine Selections', u'http://www.businessweek.com/rss/magazine.rss'),
(u'CEO Guide to Tech', u'http://www.businessweek.com/rss/ceo_guide_tech.rss'),
]
def get_article_url(self, article):
url = article.get('guid', None)
if 'podcasts' in url:
return None
if 'surveys' in url:
return None
if 'images' in url:
return None
if 'feedroom' in url:
return None
if '/magazine/toc/' in url:
return None
rurl, sep, rest = url.rpartition('?')
if rurl:
return rurl
return rest
def print_version(self, url):
if '/news/' in url or '/blog/' in url:
return url
if '/magazine' in url:
rurl = url.replace('http://www.businessweek.com/','http://www.businessweek.com/printer/')
else:
rurl = url.replace('http://www.businessweek.com/','http://www.businessweek.com/print/')
return rurl.replace('/investing/','/investor/')
def preprocess_html(self, soup):
for item in soup.findAll(style=True):
del item['style']
for alink in soup.findAll('a'):
if alink.string is not None:
tstr = alink.string
alink.replaceWith(tstr)
return soup

View File

@ -0,0 +1,52 @@
__license__ = 'GPL v3'
__copyright__ = '2010-2012, NiLuJe <niluje at ak-team.com>'
'''
Fetch DoghouseDiaries.
'''
import re
from calibre.web.feeds.news import BasicNewsRecipe
class DoghouseDiaries(BasicNewsRecipe):
title = 'Doghouse Diaries'
description = 'A webcomic.'
__author__ = 'NiLuJe'
language = 'en'
use_embedded_content = False
# 14 comics per fetch (not really days... but we can't easily get the date of individual comics, short of parsing each one...)
oldest_article = 14
cover_url = 'http://www.thedoghousediaries.com/logos/logo3.png'
masthead_url = 'http://www.thedoghousediaries.com/logos/logo3.png'
keep_only_tags = [dict(name='img', attrs={'class': re.compile("comic-item*")}), dict(name='h1'), dict(name='div', attrs={'class':'entry'}), dict(name='p', id='alttext')]
remove_tags = [dict(name='div', attrs={'class':'pin-it-btn-wrapper'}), dict(name='span'), dict(name='div', id='wp_fb_like_button')]
remove_attributes = ['width', 'height']
no_stylesheets = True
# Turn image bubblehelp into a paragraph (NOTE: We run before the remove_tags cleanup, so we need to make sure we only parse the comic-item img, not the pinterest one pulled by the entry div)
preprocess_regexps = [
(re.compile(r'(<img.*src="http://thedoghousediaries.com/comics/.*title=")([^"]+)(".*>)'),
lambda m: '%s%s<p id="alttext"><strong>%s</strong></p>' % (m.group(1), m.group(3), m.group(2)))
]
def parse_index(self):
INDEX = 'http://www.thedoghousediaries.com/'
soup = self.index_to_soup(INDEX)
articles = []
# Since the feed sucks, and there's no real archive, we use the 'Quick Archive' thingie, but we can't get the date from here, so stop after 14 comics...
for item in soup.findAll('option', {}, True, None, self.oldest_article+1):
# Skip the quick archive itself
if ( item['value'] != '0' ):
articles.append({
'title': self.tag_to_string(item).encode('UTF-8'),
'url': item['value'],
'description': '',
'content': '',
})
return [('Doghouse Diaries', articles)]

19
recipes/fc_knudde.recipe Normal file
View File

@ -0,0 +1,19 @@
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1347706704(BasicNewsRecipe):
title = u'FC Knudde'
__author__ = u'DrMerry'
description = u'FC Knudde de populaire sport strip van Toon van Driel (http://www.toonvandriel.nl)'
language = u'nl'
oldest_article = 7
max_articles_per_feed = 100
auto_cleanup = False
cover_url = 'http://a1.mzstatic.com/us/r1000/035/Purple/be/33/70/mzl.qkvshinq.320x480-75.jpg'
no_stylesheets = True
remove_javascript = True
remove_empty_feeds = True
remove_tags_before = dict(id='title')
remove_tags_after = dict(attrs={'class':'entry-content rich-content'})
use_embedded_content = True
feeds = [(u'FC Knudde', u'http://www.nusport.nl/feeds/rss/fc-knudde.rss')]

BIN
recipes/icons/fc_knudde.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

BIN
recipes/icons/nsfw_corp.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 977 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 639 B

View File

@ -1,21 +1,24 @@
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from calibre.web.feeds.news import BasicNewsRecipe
class Index(BasicNewsRecipe):
title = u'INDEX.HU'
oldest_article = 3
max_articles_per_feed = 50
class AdvancedUserRecipe1348151548(BasicNewsRecipe):
title = u'Index.hu'
__author__ = 'laca'
oldest_article = 2
language = 'hu'
masthead_url = 'http://index.hu/assets/images/index_logo.gif'
auto_cleanup = True
__author__ = 'Ezmegaz'
feeds = [(u'ALL', u'http://index.hu/24ora/rss/'),
(u'BELF\xd6LD', u'http://index.hu/belfold/rss/default/'),
(u'K\xdcLF\xd6LD', u'http://index.hu/kulfold/rss/default/'),
(u'BULV\xc1R', u'http://index.hu/bulvar/rss/default/'),
(u'GAZDAS\xc1G', u'http://index.hu/gazdasag/rss/default/'),
(u'TECH', u'http://index.hu/tech/rss/main/'),
(u'KULT\xdaRA', u'http://index.hu/kultur/rss/main/'),
(u'TUDOM\xc1NY', u'http://index.hu/tudomany/rss/main/'),
(u'V\xc9LEM\xc9NY', u'http://index.hu/velemeny/rss/default/')]
simultaneous_downloads= 1
max_articles_per_feed = 50
feeds = [(u'Belföld', u'http://index.hu/belfold/rss/'),
(u'Külföld', u'http://index.hu/kulfold/rss/'),
(u'Gazdaság', u'http://index.hu/gazdasag/rss/'),
(u'Tech', u'http://index.hu/tech/rss/'),
(u'Tudomány', u'http://index.hu/tudomany/rss/'),
(u'Kultúr', u'http://index.hu/kultur/rss/'),
(u'Sport Géza', u'http://sportgeza.hu/24ora/rss/'),
(u'Vélemény', u'http://index.hu/velemeny/rss/'),
(u'Velvet', u'http://velvet.hu/24ora/rss/'),
(u'Totalcar', u'http://totalcar.hu/24ora/rss/'),
(u'Dívány', u'http://divany.hu/24ora/rss/')]

View File

@ -13,9 +13,13 @@ class IndianExpress(BasicNewsRecipe):
#remove_tags_after = dict(name='td', attrs={'class':'newptool1'})
remove_tags = [
dict(name='iframe'),
dict(name='div', attrs={'class':['bookmarks_div', 'comment_box', 'bookmarks_div_bot', 'box']}),
dict(name='div', attrs={'id':['footer', 'tab_innerhc', 'discussion', 'google_new']}),
dict(name='div', attrs={'class':['pagination_new', 'comments_desc',
'commenttext', 'postcomm', 'content_right', 'bookmarks_div',
'comment_box', 'bookmarks_div_bot', 'box']}),
dict(name='div', attrs={'id':['footer', 'tab_innerhc', 'discussion',
'google_new', 'header_new', 'slidebox']}),
dict(name='a', attrs={'class':'nobdr'}),
dict(name='h3', attrs={'class':['readcomm']}),
#dict(name='span', text=':'),
]

View File

@ -7,20 +7,29 @@ class LiveMint(BasicNewsRecipe):
#encoding = 'cp1252'
oldest_article = 1 #days
max_articles_per_feed = 25
use_embedded_content = True
use_embedded_content = False
no_stylesheets = True
auto_cleanup = True
feeds = [
('Latest News',
'http://www.livemint.com/StoryRss.aspx?LN=Latestnews'),
('Gallery',
'http://www.livemint.com/GalleryRssfeed.aspx'),
('Companies',
'http://www.livemint.com/rss/companies'),
('Consumer',
'http://www.livemint.com/rss/consumer'),
('Top Stories',
'http://www.livemint.com/StoryRss.aspx?ts=Topstories'),
('Banking',
'http://www.livemint.com/StoryRss.aspx?Id=104'),
'http://www.livemint.com/rss/homepage'),
('Opinion',
'http://www.livemint.com/rss/opinion'),
('Money',
'http://www.livemint.com/rss/money'),
('Industry',
'http://www.livemint.com/rss/industry'),
('Economy Politics',
'http://www.livemint.com/rss/economy_politics'),
('Lounge',
'http://www.livemint.com/rss/lounge'),
]

View File

@ -1,15 +1,15 @@
__license__ = 'GPL v3'
__copyright__ = '2010, Darko Miletic <darko.miletic at gmail.com>'
'''
lrb.co.uk
'''
import re
from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe
class LondonReviewOfBooksPayed(BasicNewsRecipe):
title = 'London Review of Books'
__author__ = 'Darko Miletic'
__author__ = 'Rich Shang, Darko Miletic'
description = 'Subscription content. Literary review publishing essay-length book reviews and topical articles on politics, literature, history, philosophy, science and the arts by leading writers and thinkers'
category = 'news, literature, UK'
publisher = 'LRB Ltd.'
@ -41,9 +41,12 @@ class LondonReviewOfBooksPayed(BasicNewsRecipe):
articles = []
soup = self.index_to_soup(self.INDEX)
cover_item = soup.find('p',attrs={'class':'cover'})
dates = str(soup.find('span', attrs={'class':'coverdate'}))
newdates = re.sub('\<.*\>','',re.split('<br />',dates)[1])
self.timefmt = ' [%s]'%newdates
lrbtitle = self.title
if cover_item:
self.cover_url = self.INDEX + cover_item.a.img['src']
self.cover_url = re.sub('/m/','/l/',cover_item.a.img['src'])
content = self.INDEX + cover_item.a['href']
soup2 = self.index_to_soup(content)
sitem = soup2.find(attrs={'class':'article-list'})
@ -54,13 +57,20 @@ class LondonReviewOfBooksPayed(BasicNewsRecipe):
feed_link = item
if feed_link.has_key('href'):
url = self.INDEX + feed_link['href']
title = title_prefix + self.tag_to_string(feed_link)
title_link = re.split('<br />',str(feed_link))
if len (title_link) > 1:
title = title_prefix + re.sub('\<.*\>','',title_link[0]) + ' - ' + re.sub('\<.*\>','',title_link[1])
else:
title = title_prefix + self.tag_to_string(feed_link)
desc = item.findNext('li')
if desc is not None and desc.find('cite') is not None and desc.find('ul') is None:
description=self.tag_to_string(desc)
date = strftime(self.timefmt)
articles.append({
'title' :title
,'date' :date
,'url' :url
,'description':description
'title' :title
,'date' :date
,'url' :url
,'description':description
})
return [(lrbtitle, articles)]

View File

@ -1,6 +1,6 @@
__license__ = 'GPL v3'
__copyright__ = '2008-2011, Darko Miletic <darko.miletic at gmail.com>'
__copyright__ = '2008-2012, Darko Miletic <darko.miletic at gmail.com>'
'''
www.nin.co.rs
'''
@ -15,11 +15,11 @@ class Nin(BasicNewsRecipe):
publisher = 'NIN d.o.o. - Ringier d.o.o.'
category = 'news, politics, Serbia'
no_stylesheets = True
delay = 1
oldest_article = 15
encoding = 'utf-8'
needs_subscription = True
remove_empty_feeds = True
auto_cleanup = False
PREFIX = 'http://www.nin.co.rs'
INDEX = PREFIX + '/?change_lang=ls'
use_embedded_content = False
@ -63,7 +63,11 @@ class Nin(BasicNewsRecipe):
keep_only_tags =[dict(name='td', attrs={'width':'520'})]
remove_tags_before =dict(name='span', attrs={'class':'izjava'})
remove_tags_after =dict(name='html')
remove_tags = [dict(name=['object','link','iframe','meta','base'])]
remove_tags = [
dict(name=['object','link','iframe','meta','base'])
,dict(attrs={'class':['fb-like','twitter-share-button']})
,dict(attrs={'rel':'nofollow'})
]
remove_attributes=['border','background','height','width','align','valign']
def get_cover_url(self):
@ -78,10 +82,6 @@ class Nin(BasicNewsRecipe):
feeds = [(u'NIN Online', u'http://www.nin.co.rs/misc/rss.php?feed=RSS2.0')]
def get_article_url(self, article):
url = BasicNewsRecipe.get_article_url(self, article)
return url.replace('.co.yu', '.co.rs')
def preprocess_html(self, soup):
for item in soup.findAll(style=True):
del item['style']
@ -99,4 +99,3 @@ class Nin(BasicNewsRecipe):
img.extract()
tbl.replaceWith(img)
return soup

94
recipes/nsfw_corp.recipe Normal file
View File

@ -0,0 +1,94 @@
__license__ = 'GPL v3'
__copyright__ = '2012, Darko Miletic <darko.miletic at gmail.com>'
'''
www.nsfwcorp.com
'''
import urllib
from calibre import strftime
from calibre.web.feeds.news import BasicNewsRecipe
class NotSafeForWork(BasicNewsRecipe):
title = 'Not Safe For Work Corporation'
__author__ = 'Darko Miletic'
description = 'Not Safe For Work Corporation'
publisher = 'Not Safe For Work Corporation'
category = 'news, politics, USA, World'
no_stylesheets = True
oldest_article = 15
encoding = 'utf-8'
needs_subscription = True
auto_cleanup = False
INDEX = 'https://www.nsfwcorp.com'
LOGIN = INDEX + '/login'
use_embedded_content = False
language = 'en'
publication_type = 'magazine'
masthead_url = 'http://assets.nsfwcorp.com/media/headers/nsfw_banner.jpg'
extra_css = """
body{font-family: Constantia,"Lucida Bright",Lucidabright,"Lucida Serif",Lucida,"DejaVu Serif","Bitstream Vera Serif","Liberation Serif",Georgia,serif}
img{margin-top:0.5em; margin-bottom: 0.7em; display: block}
.fontFace{font-family: 'LeagueGothicRegular',Arial,sans-serif;}
.dispatchTitle{text-transform: uppercase; font-size: x-large; font-weight: bold}
.dispatchSubtitle{font-size: x-large; font-weight: bold}
#fromLine{color: gray; text-align:right}
#toLine{color: gray}
#toLine a{color: red}
#fromLine a{color: red}
.row a{color: red}
"""
conversion_options = {
'comment' : description
, 'tags' : category
, 'publisher' : publisher
, 'language' : language
}
remove_tags_before = dict(attrs={'id':'fromToLine'})
remove_tags_after = dict(attrs={'id':'unlockButtonDiv'})
remove_tags=[
dict(name=['meta', 'link', 'iframe', 'embed', 'object'])
,dict(name='a', attrs={'class':'switchToDeskNotes'})
,dict(attrs={'id':'unlockButtonDiv'})
]
remove_attributes = ['lang']
def get_browser(self):
br = BasicNewsRecipe.get_browser()
br.open(self.LOGIN)
if self.username is not None and self.password is not None:
data = urllib.urlencode({ 'email':self.username
,'password':self.password
})
br.open(self.LOGIN, data)
return br
def parse_index(self):
articles = []
soup = self.index_to_soup(self.INDEX)
dispatches = soup.find(attrs={'id':'dispatches'})
if dispatches:
for item in dispatches.findAll('h3'):
description = u''
title_link = item.find('span', attrs={'class':'dispatchTitle'})
description_link = item.find('span', attrs={'class':'dispatchSubtitle'})
feed_link = item.find('a', href=True)
if feed_link:
url = self.INDEX + feed_link['href']
title = self.tag_to_string(title_link)
description = self.tag_to_string(description_link)
date = strftime(self.timefmt)
articles.append({
'title' :title
,'date' :date
,'url' :url
,'description':description
})
return [('Dispatches', articles)]
def preprocess_html(self, soup):
for item in soup.findAll(style=True):
del item['style']
return soup

29
recipes/origo_hu.recipe Normal file
View File

@ -0,0 +1,29 @@
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1348136299(BasicNewsRecipe):
title = u'[origo]'
oldest_article = 2
language = 'hu'
auto_cleanup = True
__author__ = 'laca'
simultaneous_downloads= 1
max_articles_per_feed = 50
feeds = [(u'Itthon', u'http://origo.hu/contentpartner/rss/itthon/origo.xml'),
(u'Nagyvilág', u'http://origo.hu/contentpartner/rss/nagyvilag/origo.xml'),
(u'Gazdaság', u'http://origo.hu/contentpartner/rss/uzletinegyed/origo.xml'),
(u'Egészség', u'http://static2.origos.hu/contentpartner/rss/egeszseg/origo.xml'),
(u'Tudomány', u'http://origo.hu/contentpartner/rss/tudomany/origo.xml'),
(u'Techbázis', u'http://origo.hu/contentpartner/rss/techbazis/origo.xml'),
(u'Szoftverbázis', u'http://www.szoftverbazis.hu/rss/index.xml'),
(u'Sport', u'http://origo.hu/contentpartner/rss/sport/origo.xml'),
(u'Szórakozás', u'http://origo.hu/contentpartner/rss/szorakozas/origo.xml'),
(u'Időjárás', u'http://static1.origos.hu/contentpartner/rss/idojaras/origo.xml'),
(u'Filmklub', u'http://origo.hu/contentpartner/rss/filmklub/origo.xml'),
(u'Utazás', u'http://origo.hu/contentpartner/rss/utazas/origo.xml'),
(u'Autó', u'http://origo.hu/contentpartner/rss/auto/origo.xml'),
(u'Komment.hu', u'http://static5.origos.hu/contentpartner/rss/velemeny/origo.xml'),
(u'365.hu', u'http://origo.hu/contentpartner/rss/365/origo.xml'),
(u'Quart', u'http://www.quart.hu/contentpartner/rss/quart/origo.xml'),
(u'Forma-1', u'http://www.f1hirek.hu/contentpartner/rss/f1hirek/f1hirek.xml')]

View File

@ -0,0 +1,25 @@
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1348063712(BasicNewsRecipe):
title = u'Portfolio.hu - English Edition'
__author__ = 'laca'
oldest_article = 7
language = 'en_HUN'
masthead_url = 'http://www.portfolio.hu/img/sit/angolfejlec2010.jpg'
use_embedded_content = False
auto_cleanup = True
encoding = 'cp1252'
author = 'laca'
simultaneous_downloads= 1
max_articles_per_feed = 50
no_stylesheets = True
feeds = [(u'Equity news', u'http://www.portfolio.hu/en/rss/cikk/equity.xml'),
(u'Economy news', u'http://www.portfolio.hu/en/rss/cikkek/economy.xml'),
(u'FX&Fixed Income news', u'http://www.portfolio.hu/en/rss/cikkek/fx.xml'),
(u'Tax news', u'http://www.portfolio.hu/en/rss/cikkek/tax.xml'),
(u'Energy news', u'http://www.portfolio.hu/en/rss/cikkek/energy.xml'),
(u'Corpfin news', u'http://www.portfolio.hu/en/rss/cikkek/corpfin.xml'),
(u'MNB news', u'http://www.portfolio.hu/en/rss/cikkek/mnb.xml')]

View File

@ -0,0 +1,23 @@
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:ai
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1348146838(BasicNewsRecipe):
title = u'Portfolio.hu'
__author__ = 'laca'
oldest_article = 2
language = 'hu'
masthead_url = 'http://www.portfolio.hu/img/logo2010.gif'
auto_cleanup = True
author = 'laca'
simultaneous_downloads= 1
max_articles_per_feed = 50
feeds = [(u'Makrogazdaság', u'http://www.portfolio.hu/rss/cikkek/makrogazdasag.xml'),
(u'Vállalatok', u'http://www.portfolio.hu/rss/cikkek/vallalatok.xml'),
(u'Tőzsdei hírek', u'http://www.portfolio.hu/rss/cikkek/tozsde.xml'),
(u'Deviza/kötvény', u'http://www.portfolio.hu/rss/cikkek/penzkotveny.xml'),
(u'Befektetési alapok', u'http://www.portfolio.hu/rss/cikkek/befalap.xml'),
(u'Ingatlan', u'http://www.portfolio.hu/rss/cikkek/ingatlan.xml'),
(u'Pénzcentrum', u'http://www.penzcentrum.hu/rss/all.xml')]

18
recipes/stamgasten.recipe Normal file
View File

@ -0,0 +1,18 @@
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1347706704(BasicNewsRecipe):
title = u'Stamgasten'
__author__ = u'DrMerry'
description = u'Stamgasten de populaire strip van Toon van Driel (http://www.toonvandriel.nl)'
language = u'nl'
oldest_article = 7
max_articles_per_feed = 100
auto_cleanup = False
cover_url = 'http://shop.toonvandriel.nl/productimg.php?type=canvas&id=15&size=large'
no_stylesheets = True
remove_javascript = True
remove_empty_feeds = True
remove_tags_before = dict(id='title')
remove_tags_after = dict(attrs={'class':'entry-content rich-content'})
feeds = [(u'Stamgasten', u'http://toonvandriel.nl/feed/')]

View File

@ -2,6 +2,8 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
'''
Changelog:
2012-04-06
Fixed empty articles, added masthead img (NiLuJe)
2011-09-24
Changed cover (drMerry)
'''
@ -13,7 +15,8 @@ import time, re
from calibre.web.feeds.news import BasicNewsRecipe
class XkcdCom(BasicNewsRecipe):
cover_url = 'http://imgs.xkcd.com/s/9be30a7.png'
cover_url = 'http://imgs.xkcd.com/static/terrible_small_logo.png'
masthead_url = 'http://imgs.xkcd.com/static/terrible_small_logo.png'
title = 'xkcd'
description = 'A webcomic of romance and math humor.'
__author__ = 'Martin Pitt updated by DrMerry.'
@ -21,13 +24,14 @@ class XkcdCom(BasicNewsRecipe):
use_embedded_content = False
oldest_article = 60
keep_only_tags = [dict(id='middleContainer')]
remove_tags = [dict(name='ul'), dict(name='h3'), dict(name='br')]
#keep_only_tags = [dict(id='middleContainer')]
#remove_tags = [dict(name='ul'), dict(name='h3'), dict(name='br')]
keep_only_tags = [dict(id='comic')]
no_stylesheets = True
# turn image bubblehelp into a paragraph
# turn image bubblehelp into a paragraph, and put alt in a heading
preprocess_regexps = [
(re.compile(r'(<img.*title=")([^"]+)(".*>)'),
lambda m: '%s%s<p>%s</p>' % (m.group(1), m.group(3), m.group(2)))
(re.compile(r'(<img.*title=")([^"]+)(".alt=")([^"]+)(".*>)'),
lambda m: '<h1>%s</h1>%s%s%s<p>%s</p>' % (m.group(4), m.group(1), m.group(3), m.group(5), m.group(2)))
]
def parse_index(self):

33
recipes/xpatloop.recipe Normal file
View File

@ -0,0 +1,33 @@
from calibre.web.feeds.news import BasicNewsRecipe
class AdvancedUserRecipe1347997197(BasicNewsRecipe):
title = u'XpatLoop.com'
__author__ = 'laca'
oldest_article = 7
language = 'en_HUN'
auto_cleanup = True
masthead_url = 'http://www.xpatloop.com/images/cms/xs_logo.gif'
use_embedded_content = False
author = 'laca'
simultaneous_downloads= 1
max_articles_per_feed = 50
no_stylesheets = True
feeds = [(u'Current Affairs', u'http://www.xpatloop.com/current_affairs.rss'),
(u'Community & Culture', u'http://www.xpatloop.com/community.rss'),
(u'Business & Finance', u'http://www.xpatloop.com/business.rss'),
(u'Entertainment', u'http://www.xpatloop.com/entertainment.rss'),
(u'Dining Guide', u'http://www.xpatloop.com/dining_guide.rss'),
(u'Getting Around', u'http://www.xpatloop.com/getting_around.rss'),
(u'Movies', u'http://www.xpatloop.com/movies.rss'),
(u'Shopping', u'http://www.xpatloop.com/shopping_channel.rss'),
(u'Travel', u'http://www.xpatloop.com/travel.rss'),
(u'Sport and Fitness', u'http://www.xpatloop.com/sport_and_fitness.rss'),
(u'Health and Wellness', u'http://www.xpatloop.com/health_and_wellness.rss'),
(u'Infotech & Telco', u'http://www.xpatloop.com/infotech_telco.rss'),
(u'Real Estate', u'http://www.xpatloop.com/property_real_estate.rss'),
(u'Specials', u'http://www.xpatloop.com/specials.rss'),
(u'Video Channel', u'http://www.xpatloop.com/video.rss'),
(u'Events', u'http://www.xpatloop.com/events.rss')]

Binary file not shown.

Before

Width:  |  Height:  |  Size: 101 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 29 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.6 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

File diff suppressed because it is too large Load Diff

View File

@ -14,6 +14,7 @@ let g:syntastic_cpp_include_dirs = [
let g:syntastic_c_include_dirs = g:syntastic_cpp_include_dirs
set wildignore+=resources/viewer/mathjax/**
set wildignore+=build/**
fun! CalibreLog()
" Setup buffers to edit the calibre changelog and version info prior to

View File

@ -141,7 +141,7 @@ class GoogleCode(Base):# {{{
# The pattern to match filenames for the files being uploaded and
# extract version information from them. Must have a named group
# named version
filename_pattern=r'{appname}-(?:portable-)?(?P<version>.+?)(?:-(?:i686|x86_64|32bit|64bit))?\.(?:zip|exe|msi|dmg|tar\.bz2|tar\.xz|txz|tbz2)'
filename_pattern=r'{appname}-(?:portable-installer-)?(?P<version>.+?)(?:-(?:i686|x86_64|32bit|64bit))?\.(?:zip|exe|msi|dmg|tar\.bz2|tar\.xz|txz|tbz2)'
):
self.username, self.password, = username, password
@ -164,7 +164,7 @@ class GoogleCode(Base):# {{{
typ = 'Type-' + ('Source' if fname.endswith('.xz') else 'Archive' if
fname.endswith('.zip') else 'Installer')
ext = os.path.splitext(fname)[1][1:]
op = 'OpSys-'+{'msi':'Windows','zip':'Windows',
op = 'OpSys-'+{'msi':'Windows','exe':'Windows',
'dmg':'OSX','bz2':'Linux','xz':'All'}[ext]
desc = self.files[fname]
start = time.time()

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,382 @@
// XUnzip.h Version 1.3
//
// Authors: Mark Adler et al. (see below)
//
// Modified by: Lucian Wischik
// lu@wischik.com
//
// Version 1.0 - Turned C files into just a single CPP file
// - Made them compile cleanly as C++ files
// - Gave them simpler APIs
// - Added the ability to zip/unzip directly in memory without
// any intermediate files
//
// Modified by: Hans Dietrich
// hdietrich@gmail.com
//
///////////////////////////////////////////////////////////////////////////////
//
// Lucian Wischik's comments:
// --------------------------
// THIS FILE is almost entirely based upon code by info-zip.
// It has been modified by Lucian Wischik.
// The original code may be found at http://www.info-zip.org
// The original copyright text follows.
//
///////////////////////////////////////////////////////////////////////////////
//
// Original authors' comments:
// ---------------------------
// This is version 2002-Feb-16 of the Info-ZIP copyright and license. The
// definitive version of this document should be available at
// ftp://ftp.info-zip.org/pub/infozip/license.html indefinitely.
//
// Copyright (c) 1990-2002 Info-ZIP. All rights reserved.
//
// For the purposes of this copyright and license, "Info-ZIP" is defined as
// the following set of individuals:
//
// Mark Adler, John Bush, Karl Davis, Harald Denker, Jean-Michel Dubois,
// Jean-loup Gailly, Hunter Goatley, Ian Gorman, Chris Herborth, Dirk Haase,
// Greg Hartwig, Robert Heath, Jonathan Hudson, Paul Kienitz,
// David Kirschbaum, Johnny Lee, Onno van der Linden, Igor Mandrichenko,
// Steve P. Miller, Sergio Monesi, Keith Owens, George Petrov, Greg Roelofs,
// Kai Uwe Rommel, Steve Salisbury, Dave Smith, Christian Spieler,
// Antoine Verheijen, Paul von Behren, Rich Wales, Mike White
//
// This software is provided "as is", without warranty of any kind, express
// or implied. In no event shall Info-ZIP or its contributors be held liable
// for any direct, indirect, incidental, special or consequential damages
// arising out of the use of or inability to use this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it
// freely, subject to the following restrictions:
//
// 1. Redistributions of source code must retain the above copyright notice,
// definition, disclaimer, and this list of conditions.
//
// 2. Redistributions in binary form (compiled executables) must reproduce
// the above copyright notice, definition, disclaimer, and this list of
// conditions in documentation and/or other materials provided with the
// distribution. The sole exception to this condition is redistribution
// of a standard UnZipSFX binary as part of a self-extracting archive;
// that is permitted without inclusion of this license, as long as the
// normal UnZipSFX banner has not been removed from the binary or disabled.
//
// 3. Altered versions--including, but not limited to, ports to new
// operating systems, existing ports with new graphical interfaces, and
// dynamic, shared, or static library versions--must be plainly marked
// as such and must not be misrepresented as being the original source.
// Such altered versions also must not be misrepresented as being
// Info-ZIP releases--including, but not limited to, labeling of the
// altered versions with the names "Info-ZIP" (or any variation thereof,
// including, but not limited to, different capitalizations),
// "Pocket UnZip", "WiZ" or "MacZip" without the explicit permission of
// Info-ZIP. Such altered versions are further prohibited from
// misrepresentative use of the Zip-Bugs or Info-ZIP e-mail addresses or
// of the Info-ZIP URL(s).
//
// 4. Info-ZIP retains the right to use the names "Info-ZIP", "Zip", "UnZip",
// "UnZipSFX", "WiZ", "Pocket UnZip", "Pocket Zip", and "MacZip" for its
// own source and binary releases.
//
///////////////////////////////////////////////////////////////////////////////
#ifndef XUNZIP_H
#define XUNZIP_H
#ifndef XZIP_H
DECLARE_HANDLE(HZIP); // An HZIP identifies a zip file that has been opened
#endif
typedef DWORD ZRESULT;
// return codes from any of the zip functions. Listed later.
#define ZIP_HANDLE 1
#define ZIP_FILENAME 2
#define ZIP_MEMORY 3
typedef struct
{ int index; // index of this file within the zip
char name[MAX_PATH]; // filename within the zip
DWORD attr; // attributes, as in GetFileAttributes.
FILETIME atime,ctime,mtime;// access, create, modify filetimes
long comp_size; // sizes of item, compressed and uncompressed. These
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
} ZIPENTRY;
typedef struct
{ int index; // index of this file within the zip
TCHAR name[MAX_PATH]; // filename within the zip
DWORD attr; // attributes, as in GetFileAttributes.
FILETIME atime,ctime,mtime;// access, create, modify filetimes
long comp_size; // sizes of item, compressed and uncompressed. These
long unc_size; // may be -1 if not yet known (e.g. being streamed in)
} ZIPENTRYW;
///////////////////////////////////////////////////////////////////////////////
//
// OpenZip()
//
// Purpose: Open an existing zip archive file
//
// Parameters: z - archive file name if flags is ZIP_FILENAME; for other
// uses see below
// len - for memory (ZIP_MEMORY) should be the buffer size;
// for other uses, should be 0
// flags - indicates usage, see below; for files, this will be
// ZIP_FILENAME
//
// Returns: HZIP - non-zero if zip archive opened ok, otherwise 0
//
HZIP OpenZip(void *z, unsigned int len, DWORD flags);
// OpenZip - opens a zip file and returns a handle with which you can
// subsequently examine its contents. You can open a zip file from:
// from a pipe: OpenZip(hpipe_read,0, ZIP_HANDLE);
// from a file (by handle): OpenZip(hfile,0, ZIP_HANDLE);
// from a file (by name): OpenZip("c:\\test.zip",0, ZIP_FILENAME);
// from a memory block: OpenZip(bufstart, buflen, ZIP_MEMORY);
// If the file is opened through a pipe, then items may only be
// accessed in increasing order, and an item may only be unzipped once,
// although GetZipItem can be called immediately before and after unzipping
// it. If it's opened i n any other way, then full random access is possible.
// Note: pipe input is not yet implemented.
///////////////////////////////////////////////////////////////////////////////
//
// GetZipItem()
//
// Purpose: Get information about an item in an open zip archive
//
// Parameters: hz - handle of open zip archive
// index - index number (0 based) of item in zip
// ze - pointer to a ZIPENTRY (if ANSI) or ZIPENTRYW struct
// (if Unicode)
//
// Returns: ZRESULT - ZR_OK if success, otherwise some other value
//
#ifdef _UNICODE
#define GetZipItem GetZipItemW
#else
#define GetZipItem GetZipItemA
#endif
ZRESULT GetZipItemA(HZIP hz, int index, ZIPENTRY *ze);
ZRESULT GetZipItemW(HZIP hz, int index, ZIPENTRYW *ze);
// GetZipItem - call this to get information about an item in the zip.
// If index is -1 and the file wasn't opened through a pipe,
// then it returns information about the whole zipfile
// (and in particular ze.index returns the number of index items).
// Note: the item might be a directory (ze.attr & FILE_ATTRIBUTE_DIRECTORY)
// See below for notes on what happens when you unzip such an item.
// Note: if you are opening the zip through a pipe, then random access
// is not possible and GetZipItem(-1) fails and you can't discover the number
// of items except by calling GetZipItem on each one of them in turn,
// starting at 0, until eventually the call fails. Also, in the event that
// you are opening through a pipe and the zip was itself created into a pipe,
// then then comp_size and sometimes unc_size as well may not be known until
// after the item has been unzipped.
///////////////////////////////////////////////////////////////////////////////
//
// FindZipItem()
//
// Purpose: Find item by name and return information about it
//
// Parameters: hz - handle of open zip archive
// name - name of file to look for inside zip archive
// ic - TRUE = case insensitive
// index - pointer to index number returned, or -1
// ze - pointer to a ZIPENTRY (if ANSI) or ZIPENTRYW struct
// (if Unicode)
//
// Returns: ZRESULT - ZR_OK if success, otherwise some other value
//
#ifdef _UNICODE
#define FindZipItem FindZipItemW
#else
#define FindZipItem FindZipItemA
#endif
ZRESULT FindZipItemA(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRY *ze);
ZRESULT FindZipItemW(HZIP hz, const TCHAR *name, bool ic, int *index, ZIPENTRYW *ze);
// FindZipItem - finds an item by name. ic means 'insensitive to case'.
// It returns the index of the item, and returns information about it.
// If nothing was found, then index is set to -1 and the function returns
// an error code.
///////////////////////////////////////////////////////////////////////////////
//
// UnzipItem()
//
// Purpose: Find item by index and unzip it
//
// Parameters: hz - handle of open zip archive
// index - index number of file to unzip
// dst - target file name of unzipped file
// len - for memory (ZIP_MEMORY. length of buffer;
// otherwise 0
// flags - indicates usage, see below; for files, this will be
// ZIP_FILENAME
//
// Returns: ZRESULT - ZR_OK if success, otherwise some other value
//
ZRESULT UnzipItem(HZIP hz, int index, void *dst, unsigned int len, DWORD flags);
// UnzipItem - given an index to an item, unzips it. You can unzip to:
// to a pipe: UnzipItem(hz,i, hpipe_write,0,ZIP_HANDLE);
// to a file (by handle): UnzipItem(hz,i, hfile,0,ZIP_HANDLE);
// to a file (by name): UnzipItem(hz,i, ze.name,0,ZIP_FILENAME);
// to a memory block: UnzipItem(hz,i, buf,buflen,ZIP_MEMORY);
// In the final case, if the buffer isn't large enough to hold it all,
// then the return code indicates that more is yet to come. If it was
// large enough, and you want to know precisely how big, GetZipItem.
// Note: zip files are normally stored with relative pathnames. If you
// unzip with ZIP_FILENAME a relative pathname then the item gets created
// relative to the current directory - it first ensures that all necessary
// subdirectories have been created. Also, the item may itself be a directory.
// If you unzip a directory with ZIP_FILENAME, then the directory gets created.
// If you unzip it to a handle or a memory block, then nothing gets created
// and it emits 0 bytes.
///////////////////////////////////////////////////////////////////////////////
//
// CloseZip()
//
// Purpose: Close an open zip archive
//
// Parameters: hz - handle to an open zip archive
//
// Returns: ZRESULT - ZR_OK if success, otherwise some other value
//
ZRESULT CloseZip(HZIP hz);
// CloseZip - the zip handle must be closed with this function.
unsigned int FormatZipMessage(ZRESULT code, char *buf,unsigned int len);
// FormatZipMessage - given an error code, formats it as a string.
// It returns the length of the error message. If buf/len points
// to a real buffer, then it also writes as much as possible into there.
// These are the result codes:
#define ZR_OK 0x00000000 // nb. the pseudo-code zr-recent is never returned,
#define ZR_RECENT 0x00000001 // but can be passed to FormatZipMessage.
// The following come from general system stuff (e.g. files not openable)
#define ZR_GENMASK 0x0000FF00
#define ZR_NODUPH 0x00000100 // couldn't duplicate the handle
#define ZR_NOFILE 0x00000200 // couldn't create/open the file
#define ZR_NOALLOC 0x00000300 // failed to allocate some resource
#define ZR_WRITE 0x00000400 // a general error writing to the file
#define ZR_NOTFOUND 0x00000500 // couldn't find that file in the zip
#define ZR_MORE 0x00000600 // there's still more data to be unzipped
#define ZR_CORRUPT 0x00000700 // the zipfile is corrupt or not a zipfile
#define ZR_READ 0x00000800 // a general error reading the file
// The following come from mistakes on the part of the caller
#define ZR_CALLERMASK 0x00FF0000
#define ZR_ARGS 0x00010000 // general mistake with the arguments
#define ZR_NOTMMAP 0x00020000 // tried to ZipGetMemory, but that only works on mmap zipfiles, which yours wasn't
#define ZR_MEMSIZE 0x00030000 // the memory size is too small
#define ZR_FAILED 0x00040000 // the thing was already failed when you called this function
#define ZR_ENDED 0x00050000 // the zip creation has already been closed
#define ZR_MISSIZE 0x00060000 // the indicated input file size turned out mistaken
#define ZR_PARTIALUNZ 0x00070000 // the file had already been partially unzipped
#define ZR_ZMODE 0x00080000 // tried to mix creating/opening a zip
// The following come from bugs within the zip library itself
#define ZR_BUGMASK 0xFF000000
#define ZR_NOTINITED 0x01000000 // initialisation didn't work
#define ZR_SEEK 0x02000000 // trying to seek in an unseekable file
#define ZR_NOCHANGE 0x04000000 // changed its mind on storage, but not allowed
#define ZR_FLATE 0x05000000 // an internal error in the de/inflation code
// e.g.
//
// SetCurrentDirectory("c:\\docs\\stuff");
// HZIP hz = OpenZip("c:\\stuff.zip",0,ZIP_FILENAME);
// ZIPENTRY ze; GetZipItem(hz,-1,&ze); int numitems=ze.index;
// for (int i=0; i<numitems; i++)
// { GetZipItem(hz,i,&ze);
// UnzipItem(hz,i,ze.name,0,ZIP_FILENAME);
// }
// CloseZip(hz);
//
//
// HRSRC hrsrc = FindResource(hInstance,MAKEINTRESOURCE(1),RT_RCDATA);
// HANDLE hglob = LoadResource(hInstance,hrsrc);
// void *zipbuf=LockResource(hglob);
// unsigned int ziplen=SizeofResource(hInstance,hrsrc);
// HZIP hz = OpenZip(zipbuf, ziplen, ZIP_MEMORY);
// - unzip to a membuffer -
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",&i,&ze);
// char *ibuf = new char[ze.unc_size];
// UnzipItem(hz,i, ibuf, ze.unc_size,ZIP_MEMORY);
// delete[] buf;
// - unzip to a fixed membuff -
// ZIPENTRY ze; int i; FindZipItem(hz,"file.dat",&i,&ze);
// char ibuf[1024]; ZIPRESULT zr=ZR_MORE; unsigned long totsize=0;
// while (zr==ZR_MORE)
// { zr = UnzipItem(hz,i, ibuf,1024,ZIP_MEMORY);
// unsigned long bufsize=1024; if (zr==ZR_OK) bufsize=ze.unc_size-totsize;
// totsize+=bufsize;
// }
// - unzip to a pipe -
// HANDLE hthread=CreateWavReaderThread(&hread,&hwrite);
// FindZipItem(hz,"sound.wav",&i,&ze);
// UnzipItem(hz,i, hwrite,0,ZIP_HANDLE);
// CloseHandle(hwrite);
// WaitForSingleObject(hthread,INFINITE);
// CloseHandle(hread); CloseHandle(hthread);
// - finished -
// CloseZip(hz);
// // note: no need to free resources obtained through Find/Load/LockResource
//
//
// SetCurrentDirectory("c:\\docs\\pipedzipstuff");
// HANDLE hread,hwrite; CreatePipe(&hread,&hwrite);
// CreateZipWriterThread(hwrite);
// HZIP hz = OpenZip(hread,0,ZIP_HANDLE);
// for (int i=0; ; i++)
// { ZIPENTRY ze; ZRESULT res = GetZipItem(hz,i,&ze);
// if (res!=ZE_OK) break; // no more
// UnzipItem(hz,i, ze.name,0,ZIP_FILENAME);
// }
// CloseZip(hz);
//
// Now we indulge in a little skullduggery so that the code works whether
// the user has included just zip or both zip and unzip.
// Idea: if header files for both zip and unzip are present, then presumably
// the cpp files for zip and unzip are both present, so we will call
// one or the other of them based on a dynamic choice. If the header file
// for only one is present, then we will bind to that particular one.
HZIP OpenZipU(void *z,unsigned int len,DWORD flags);
ZRESULT CloseZipU(HZIP hz);
unsigned int FormatZipMessageU(ZRESULT code, char *buf,unsigned int len);
bool IsZipHandleU(HZIP hz);
#define OpenZip OpenZipU
#ifdef XZIP_H
#undef CloseZip
#define CloseZip(hz) (IsZipHandleU(hz)?CloseZipU(hz):CloseZipZ(hz))
#else
#define CloseZip CloseZipU
#define FormatZipMessage FormatZipMessageU
#endif
#endif //XUNZIP_H

View File

@ -37,7 +37,7 @@ class Win32(VMInstaller):
SHUTDOWN_CMD = ['shutdown.exe', '-s', '-f', '-t', '0']
def sign_msi(self):
print ('Signing .msi ...')
print ('Signing installers ...')
raw = open(self.VM).read()
vmx = re.search(r'''launch_vmware\(['"](.+?)['"]''', raw).group(1)
subprocess.check_call(['vmrun', '-T', 'ws', '-gu', 'kovid', '-gp',
@ -56,7 +56,7 @@ class Win32(VMInstaller):
self.warn('Failed to freeze')
raise SystemExit(1)
installer = 'dist/%s-portable-%s.zip'%(__appname__, __version__)
installer = 'dist/%s-portable-installer-%s.exe'%(__appname__, __version__)
subprocess.check_call(('scp',
'xp_build:build/%s/%s'%(__appname__, installer), 'dist'))
if not os.path.exists(installer):

View File

@ -23,6 +23,7 @@ SW = r'C:\cygwin\home\kovid\sw'
IMAGEMAGICK = os.path.join(SW, 'build', 'ImageMagick-6.7.6',
'VisualMagick', 'bin')
CRT = r'C:\Microsoft.VC90.CRT'
LZMA = r'Q:\easylzma\build\easylzma-0.0.8'
VERSION = re.sub('[a-z]\d+', '', __version__)
WINVER = VERSION+'.0'
@ -89,6 +90,7 @@ class Win32Freeze(Command, WixMixIn):
self.remove_CRT_from_manifests()
self.create_installer()
self.build_portable()
self.build_portable_installer()
def remove_CRT_from_manifests(self):
'''
@ -311,7 +313,8 @@ class Win32Freeze(Command, WixMixIn):
subprocess.check_call([r'C:\Program Files\7-Zip\7z.exe', 'a', '-r',
'-scsUTF-8', '-sfx', 'winfrozen', 'winfrozen'], cwd=self.base)
def embed_resources(self, module, desc=None):
def embed_resources(self, module, desc=None, extra_data=None,
product_description=None):
icon_base = self.j(self.src_root, 'icons')
icon_map = {'calibre':'library', 'ebook-viewer':'viewer',
'lrfviewer':'viewer', 'calibre-portable':'library'}
@ -320,6 +323,8 @@ class Win32Freeze(Command, WixMixIn):
bname = self.b(module)
internal_name = os.path.splitext(bname)[0]
icon = icon_map.get(internal_name, 'command-prompt')
if internal_name.startswith('calibre-portable-'):
icon = 'install'
icon = self.j(icon_base, icon+'.ico')
if desc is None:
defdesc = 'A dynamic link library' if file_type == 'DLL' else \
@ -327,6 +332,8 @@ class Win32Freeze(Command, WixMixIn):
desc = DESCRIPTIONS.get(internal_name, defdesc)
license = 'GNU GPL v3.0'
def e(val): return val.replace('"', r'\"')
if product_description is None:
product_description = __appname__ + ' - E-book management'
rc = template.format(
icon=icon,
file_type=e(file_type),
@ -338,11 +345,13 @@ class Win32Freeze(Command, WixMixIn):
product_version=e(WINVER.replace('.', ',')),
product_version_str=e(__version__),
product_name=e(__appname__),
product_description=e(__appname__+' - E-book management'),
product_description=e(product_description),
legal_copyright=e(license),
legal_trademarks=e(__appname__ + \
' is a registered U.S. trademark number 3,666,525')
)
if extra_data:
rc += '\nextra extra "%s"'%extra_data
tdir = self.obj_dir
rcf = self.j(tdir, bname+'.rc')
with open(rcf, 'wb') as f:
@ -371,6 +380,44 @@ class Win32Freeze(Command, WixMixIn):
self.info(p.stderr.read())
sys.exit(1)
def build_portable_installer(self):
zf = self.a(self.j('dist', 'calibre-portable-%s.zip.lz'%VERSION))
usz = os.path.getsize(zf)
def cc(src, obj):
cflags = '/c /EHsc /MT /W4 /Ox /nologo /D_UNICODE /DUNICODE /DPSAPI_VERSION=1'.split()
cflags.append(r'/I%s\include'%LZMA)
cflags.append('/DUNCOMPRESSED_SIZE=%d'%usz)
if self.newer(obj, [src]):
self.info('Compiling', obj)
cmd = [msvc.cc] + cflags + ['/Fo'+obj, src]
self.run_builder(cmd)
src = self.j(self.src_root, 'setup', 'installer', 'windows',
'portable-installer.cpp')
obj = self.j(self.obj_dir, self.b(src)+'.obj')
xsrc = self.j(self.src_root, 'setup', 'installer', 'windows',
'XUnzip.cpp')
xobj = self.j(self.obj_dir, self.b(xsrc)+'.obj')
cc(src, obj)
cc(xsrc, xobj)
exe = self.j('dist', 'calibre-portable-installer-%s.exe'%VERSION)
if self.newer(exe, [obj, xobj]):
self.info('Linking', exe)
cmd = [msvc.linker] + ['/INCREMENTAL:NO', '/MACHINE:X86',
'/LIBPATH:'+self.obj_dir, '/SUBSYSTEM:WINDOWS',
'/LIBPATH:'+(LZMA+r'\lib\Release'),
'/RELEASE',
'/ENTRY:wWinMainCRTStartup',
'/OUT:'+exe, self.embed_resources(exe,
desc='Calibre Portable Installer', extra_data=zf,
product_description='Calibre Portable Installer'),
xobj, obj, 'User32.lib', 'Shell32.lib', 'easylzma_s.lib',
'Ole32.lib', 'Shlwapi.lib', 'Kernel32.lib', 'Psapi.lib']
self.run_builder(cmd)
os.remove(zf)
def build_portable(self):
base = self.portable_base
if os.path.exists(base):
@ -403,9 +450,12 @@ class Win32Freeze(Command, WixMixIn):
os.mkdir(self.j(base, 'Calibre Settings'))
name = '%s-portable-%s.zip'%(__appname__, __version__)
with zipfile.ZipFile(self.j('dist', name), 'w', zipfile.ZIP_DEFLATED) as zf:
name = self.j('dist', name)
with zipfile.ZipFile(name, 'w', zipfile.ZIP_STORED) as zf:
self.add_dir_to_zip(zf, base, 'Calibre Portable')
subprocess.check_call([LZMA + r'\bin\elzma.exe', '-9', '--lzip', name])
def add_dir_to_zip(self, zf, path, prefix=''):
'''
Add a directory recursively to the zip file with an optional prefix.

View File

@ -11,7 +11,6 @@ wWinMain(HINSTANCE Inst, HINSTANCE PrevInst,
wchar_t *CmdLine, int CmdShow) {
wchar_t *stdout_redirect, *stderr_redirect, basename[50];
int ret = 0;
set_gui_app((char)1);
@ -20,7 +19,7 @@ wWinMain(HINSTANCE Inst, HINSTANCE PrevInst,
stdout_redirect = redirect_out_stream(basename, (char)1);
stderr_redirect = redirect_out_stream(basename, (char)0);
ret = execute_python_entrypoint(BASENAME, MODULE, FUNCTION,
execute_python_entrypoint(BASENAME, MODULE, FUNCTION,
stdout_redirect, stderr_redirect);
if (stdout != NULL) fclose(stdout);
@ -29,7 +28,7 @@ wWinMain(HINSTANCE Inst, HINSTANCE PrevInst,
DeleteFile(stdout_redirect);
DeleteFile(stderr_redirect);
return ret;
return 0; // This should really be returning the value set in the WM_QUIT message, but I cannot be bothered figuring out how to get that.
}
#else

View File

@ -370,6 +370,14 @@ Run
Python setup.py build
cp -r build/lib.win32-*/* /cygdrive/c/Python27/Lib/site-packages/
easylzma
----------
Get it from http://lloyd.github.com/easylzma/ (use the trunk version)
Run cmake and build the Visual Studio solution (generates CLI tools and dll and
static lib automatically)
calibre
---------

View File

@ -0,0 +1,585 @@
#ifndef UNICODE
#define UNICODE
#endif
#ifndef _UNICODE
#define _UNICODE
#endif
#include <Windows.h>
#include <Shlobj.h>
#include <Shlwapi.h>
#include <Shellapi.h>
#include <Psapi.h>
#include <wchar.h>
#include <stdio.h>
#include <io.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <easylzma/decompress.h>
#include "XUnzip.h"
#define BUFSIZE 4096
// Error handling {{{
static void show_error(LPCWSTR msg) {
MessageBeep(MB_ICONERROR);
MessageBox(NULL, msg, L"Error", MB_OK|MB_ICONERROR);
}
static void show_detailed_error(LPCWSTR preamble, LPCWSTR msg, int code) {
LPWSTR buf;
buf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, sizeof(WCHAR)*
(wcslen(msg) + wcslen(preamble) + 80));
_snwprintf_s(buf,
LocalSize(buf) / sizeof(WCHAR), _TRUNCATE,
L"%s\r\n %s (Error Code: %d)\r\n",
preamble, msg, code);
show_error(buf);
LocalFree(buf);
}
static void show_zip_error(LPCWSTR preamble, LPCWSTR msg, ZRESULT code) {
LPWSTR buf;
buf = (LPWSTR)LocalAlloc(LMEM_ZEROINIT, sizeof(WCHAR)*
(wcslen(preamble) + wcslen(msg) + 80));
_snwprintf_s(buf,
LocalSize(buf) / sizeof(WCHAR), _TRUNCATE,
L"%s\r\n %s %s (Error Code: %X)\r\n",
preamble, msg, code);
show_error(buf);
LocalFree(buf);
}
static void show_last_error_crt(LPCWSTR preamble) {
WCHAR buf[BUFSIZE];
int err = 0;
_get_errno(&err);
_wcserror_s(buf, BUFSIZE, err);
show_detailed_error(preamble, buf, err);
}
static void show_last_error(LPCWSTR preamble) {
WCHAR *msg = NULL;
DWORD dw = GetLastError();
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
dw,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPWSTR)&msg,
0, NULL );
show_detailed_error(preamble, msg, (int)dw);
}
// }}}
// Load, decompress and extract data {{{
static BOOL load_data(LPVOID *data, DWORD *sz) {
HRSRC rsrc;
HGLOBAL h;
rsrc = FindResourceW(NULL, L"extra", L"extra");
if (rsrc == NULL) { show_last_error(L"Failed to find portable data in exe"); return false; }
h = LoadResource(NULL, rsrc);
if (h == NULL) { show_last_error(L"Failed to load portable data from exe"); return false; }
*data = LockResource(h);
if (*data == NULL) { show_last_error(L"Failed to lock portable data in exe"); return false; }
*sz = SizeofResource(NULL, rsrc);
if (sz == 0) { show_last_error(L"Failed to get size of portable data in exe"); return false; }
return true;
}
static BOOL unzip(HZIP zipf, int nitems, IProgressDialog *pd) {
int i = 0;
ZRESULT res;
ZIPENTRYW ze;
for (i = 0; i < nitems; i++) {
res = GetZipItem(zipf, i, &ze);
if (res != ZR_OK) { show_zip_error(L"Failed to get zip item", L"", res); return false;}
res = UnzipItem(zipf, i, ze.name, 0, ZIP_FILENAME);
if (res != ZR_OK) { show_zip_error(L"Failed to extract zip item:", ze.name, res); return false;}
pd->SetLine(2, ze.name, true, NULL);
pd->SetProgress(i, nitems);
}
CloseZip(zipf);
return true;
}
static HANDLE temp_file(LPWSTR name) {
UINT res;
HANDLE h;
res = GetTempFileNameW(L".", L"portable_data", 0, name);
if (res == 0) { show_last_error(L"Failed to create temporary file to decompress portable data"); return INVALID_HANDLE_VALUE; }
h = CreateFile(name, GENERIC_READ | GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (h == INVALID_HANDLE_VALUE) { show_last_error(L"Failed to open temp file t decomress portable data"); }
return h;
}
struct DataStream
{
const unsigned char *in_data;
size_t in_len;
HANDLE out;
IProgressDialog *pd;
};
static int
input_callback(void *ctx, void *buf, size_t * size)
{
size_t rd = 0;
struct DataStream * ds = (struct DataStream *) ctx;
rd = (ds->in_len < *size) ? ds->in_len : *size;
if (rd > 0) {
memcpy(buf, (void*) ds->in_data, rd);
ds->in_data += rd;
ds->in_len -= rd;
}
*size = rd;
return 0;
}
static size_t
output_callback(void *ctx, const void *buf, size_t size)
{
struct DataStream * ds = (struct DataStream *) ctx;
DWORD written = 0;
if (size > 0) {
if (!WriteFile(ds->out, buf, size, &written, NULL)) {
show_last_error(L"Failed to write uncompressed data to temp file");
return 0;
}
written = SetFilePointer(ds->out, 0, NULL, FILE_CURRENT);
ds->pd->SetProgress(written, UNCOMPRESSED_SIZE);
}
return size;
}
static BOOL decompress(LPVOID src, DWORD src_sz, HANDLE out, IProgressDialog *pd) {
elzma_decompress_handle h;
struct DataStream ds;
int rc;
h = elzma_decompress_alloc();
if (h == NULL) { show_error(L"Out of memory"); return false; }
ds.in_data = (unsigned char*)src;
ds.in_len = src_sz;
ds.out = out;
ds.pd = pd;
rc = elzma_decompress_run(h, input_callback, (void *) &ds, output_callback,
(void *) &ds, ELZMA_lzip);
if (rc != ELZMA_E_OK) {
elzma_decompress_free(&h);
show_zip_error(L"Failed to decompress portable data", L"", rc);
return false;
}
elzma_decompress_free(&h);
return true;
}
static BOOL extract(LPVOID cdata, DWORD csz) {
HANDLE h;
WCHAR tempnam[MAX_PATH+1] = {0};
BOOL ret = true;
HZIP zipf;
ZIPENTRYW ze;
ZRESULT res;
int nitems;
HRESULT hr;
IProgressDialog *pd = NULL;
hr = CoCreateInstance(CLSID_ProgressDialog, NULL,
CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pd));
if (FAILED(hr)) { show_error(L"Failed to create progress dialog"); return false; }
pd->SetTitle(L"Extracting Calibre Portable");
pd->SetLine(1, L"Decompressing data...", true, NULL);
h = temp_file(tempnam);
if (h == INVALID_HANDLE_VALUE) return false;
pd->StartProgressDialog(NULL, NULL, PROGDLG_NORMAL | PROGDLG_AUTOTIME | PROGDLG_NOCANCEL, NULL);
if (!decompress(cdata, csz, h, pd)) { ret = false; goto end; }
SetFilePointer(h, 0, NULL, FILE_BEGIN);
zipf = OpenZip(h, 0, ZIP_HANDLE);
if (zipf == 0) { show_last_error(L"Failed to open zipped portable data"); ret = false; goto end; }
res = GetZipItem(zipf, -1, &ze);
if (res != ZR_OK) { show_zip_error(L"Failed to get count of items in portable data", L"", res); ret = false; goto end;}
nitems = ze.index;
pd->SetLine(1, L"Copying files...", true, NULL);
if (!unzip(zipf, nitems, pd)) { ret = false; goto end; }
end:
pd->StopProgressDialog();
pd->Release();
CloseHandle(h);
DeleteFile(tempnam);
return ret;
}
// }}}
// Find calibre portable directory and install/upgrade into it {{{
static BOOL directory_exists( LPCWSTR path )
{
if( _waccess_s( path, 0 ) == 0 )
{
struct _stat status;
_wstat( path, &status );
return (status.st_mode & S_IFDIR) != 0;
}
return FALSE;
}
static BOOL file_exists( LPCWSTR path )
{
if( _waccess_s( path, 0 ) == 0 )
{
struct _stat status;
_wstat( path, &status );
return (status.st_mode & S_IFREG) != 0;
}
return FALSE;
}
static LPWSTR get_directory_from_user() {
WCHAR name[MAX_PATH+1] = {0};
LPWSTR path = NULL;
PIDLIST_ABSOLUTE ret;
path = (LPWSTR)calloc(2*MAX_PATH, sizeof(WCHAR));
if (path == NULL) { show_error(L"Out of memory"); return NULL; }
int image = 0;
BROWSEINFO bi = { NULL, NULL, name,
L"Select the folder where you want to install or update Calibre Portable",
BIF_RETURNONLYFSDIRS | BIF_DONTGOBELOWDOMAIN | BIF_USENEWUI,
NULL, NULL, image };
ret = SHBrowseForFolder(&bi);
if (ret == NULL) {
return NULL;
}
if (!SHGetPathFromIDList(ret, path)) {
show_detailed_error(L"The selected folder is not valid: ", name, 0);
return NULL;
}
return path;
}
static bool is_dots(LPCWSTR name) {
return wcscmp(name, L".") == 0 || wcscmp(name, L"..") == 0;
}
static bool rmtree(LPCWSTR path) {
SHFILEOPSTRUCTW op;
WCHAR buf[4*MAX_PATH + 2] = {0};
if (GetFullPathName(path, 4*MAX_PATH, buf, NULL) == 0) return false;
op.hwnd = NULL;
op.wFunc = FO_DELETE;
op.pFrom = buf;
op.pTo = NULL;
op.fFlags = FOF_NOCONFIRMATION | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMMKDIR;
op.fAnyOperationsAborted = false;
op.hNameMappings = NULL;
op.lpszProgressTitle = NULL;
return SHFileOperationW(&op) == 0;
}
static BOOL find_portable_dir(LPCWSTR base, LPWSTR *result, BOOL *existing) {
WCHAR buf[4*MAX_PATH] = {0};
_snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\calibre-portable.exe", base);
*existing = true;
if (file_exists(buf)) {
*result = _wcsdup(base);
if (*result == NULL) { show_error(L"Out of memory"); return false; }
return true;
}
WIN32_FIND_DATA fdFile;
HANDLE hFind = NULL;
_snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\*", base);
if((hFind = FindFirstFileEx(buf, FindExInfoStandard, &fdFile, FindExSearchLimitToDirectories, NULL, 0)) != INVALID_HANDLE_VALUE) {
do {
if(is_dots(fdFile.cFileName)) continue;
if(fdFile.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
_snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\%s\\calibre-portable.exe", base, fdFile.cFileName);
if (file_exists(buf)) {
*result = _wcsdup(buf);
if (*result == NULL) { show_error(L"Out of memory"); return false; }
PathRemoveFileSpec(*result);
FindClose(hFind);
return true;
}
}
} while(FindNextFile(hFind, &fdFile));
FindClose(hFind);
}
*existing = false;
_snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE, L"%s\\Calibre Portable", base);
if (!CreateDirectory(buf, NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
show_last_error(L"Failed to create Calibre Portable folder");
return false;
}
*result = _wcsdup(buf);
if (*result == NULL) { show_error(L"Out of memory"); return false; }
return true;
}
static LPWSTR make_unpack_dir() {
WCHAR buf[4*MAX_PATH] = {0};
LPWSTR ans = NULL;
if (directory_exists(L"_unpack_calibre_portable"))
rmtree(L"_unpack_calibre_portable");
if (!CreateDirectory(L"_unpack_calibre_portable", NULL) && GetLastError() != ERROR_ALREADY_EXISTS) {
show_last_error(L"Failed to create temporary folder to unpack into");
return ans;
}
if (!GetFullPathName(L"_unpack_calibre_portable", 4*MAX_PATH, buf, NULL)) {
show_last_error(L"Failed to resolve path");
return NULL;
}
ans = _wcsdup(buf);
if (ans == NULL) show_error(L"Out of memory");
return ans;
}
static BOOL move_program() {
if (MoveFileEx(L"Calibre Portable\\calibre-portable.exe",
L"..\\calibre-portable.exe", MOVEFILE_REPLACE_EXISTING) == 0) {
show_last_error(L"Failed to move calibre-portable.exe, make sure calibre is not running");
return false;
}
if (directory_exists(L"..\\Calibre")) {
if (!rmtree(L"..\\Calibre")) {
show_error(L"Failed to delete the Calibre program folder. Make sure calibre is not running.");
return false;
}
}
if (MoveFileEx(L"Calibre Portable\\Calibre", L"..\\Calibre", 0) == 0) {
show_last_error(L"Failed to move calibre program folder");
return false;
}
if (!directory_exists(L"..\\Calibre Library")) {
MoveFileEx(L"Calibre Portable\\Calibre Library", L"..\\Calibre Library", 0);
}
if (!directory_exists(L"..\\Calibre Settings")) {
MoveFileEx(L"Calibre Portable\\Calibre Settings", L"..\\Calibre Settings", 0);
}
return true;
}
// }}}
static BOOL ensure_not_running(LPCWSTR dest) {
DWORD processes[4096], needed, num;
unsigned int i;
WCHAR name[4*MAX_PATH] = L"<unknown>";
HANDLE h;
DWORD len;
LPWSTR fname = NULL;
if ( !EnumProcesses( processes, sizeof(processes), &needed ) ) {
return true;
}
num = needed / sizeof(DWORD);
for (i = 0; i < num; i++) {
if (processes[i] == 0) continue;
h = OpenProcess( PROCESS_QUERY_INFORMATION, FALSE, processes[i] );
if (h != NULL) {
len = GetProcessImageFileNameW(h, name, 4*MAX_PATH);
CloseHandle(h);
if (len != 0) {
name[len] = 0;
fname = PathFindFileName(name);
if (wcscmp(fname, L"calibre.exe") == 0) {
show_error(L"Calibre appears to be running on your computer. Please quit it before trying to install Calibre Portable.");
return false;
}
}
}
}
return true;
}
static void launch_calibre() {
STARTUPINFO si;
PROCESS_INFORMATION pi;
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
if (CreateProcess(_wcsdup(L"calibre-portable.exe"), NULL,
NULL, NULL, FALSE, CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_PROCESS_GROUP,
NULL, NULL, &si, &pi)
== 0) {
show_last_error(L"Failed to launch calibre portable");
}
// Close process and thread handles.
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
LPVOID cdata = NULL;
DWORD csz = 0;
int ret = 0, argc;
HRESULT hr;
LPWSTR tgt = NULL, dest = NULL, *argv, unpack_dir = NULL;
BOOL existing = false, launch = false;
WCHAR buf[4*MAX_PATH] = {0}, mb_msg[4*MAX_PATH] = {0}, fdest[4*MAX_PATH] = {0};
if (!load_data(&cdata, &csz)) return 0;
hr = CoInitialize(NULL);
if (FAILED(hr)) { show_error(L"Failed to initialize COM"); return 0; }
// Get the target directory for installation
argv = CommandLineToArgvW(GetCommandLine(), &argc);
if (argv == NULL) { show_last_error(L"Failed to get command line"); return 0; }
if (argc > 1) {
tgt = argv[1];
} else {
tgt = get_directory_from_user();
if (tgt == NULL) goto end;
}
if (!directory_exists(tgt)) {
show_detailed_error(L"The specified directory does not exist: ",
tgt, 1);
goto end;
}
// Ensure the path to Calibre Portable is not too long
do {
if (!find_portable_dir(tgt, &dest, &existing)) goto end;
if (GetFullPathName(dest, MAX_PATH*4, fdest, NULL) == 0) {
show_last_error(L"Failed to resolve target folder");
goto end;
}
free(dest); dest = NULL;
if (wcslen(fdest) > 58) {
_snwprintf_s(buf, 4*MAX_PATH, _TRUNCATE,
L"Path to Calibre Portable (%s) too long. Must be less than 59 characters.", fdest);
if (!existing) RemoveDirectory(fdest);
show_error(buf);
tgt = get_directory_from_user();
if (tgt == NULL) goto end;
}
} while (wcslen(fdest) > 58);
// Confirm the user wants to upgrade
if (existing) {
_snwprintf_s(mb_msg, 4*MAX_PATH, _TRUNCATE,
L"An existing install of Calibre Portable was found at %s. Do you want to upgrade it?",
fdest);
if (MessageBox(NULL, mb_msg,
L"Upgrade Calibre Portable?", MB_ICONEXCLAMATION | MB_YESNO | MB_TOPMOST) != IDYES)
goto end;
}
if (existing) {
if (!ensure_not_running(fdest)) goto end;
}
// Make a temp dir to unpack into
if (!SetCurrentDirectoryW(fdest)) { show_detailed_error(L"Failed to change to unzip directory: ", fdest, 0); goto end; }
if ( (unpack_dir = make_unpack_dir()) == NULL ) goto end;
if (!SetCurrentDirectoryW(unpack_dir)) { show_detailed_error(L"Failed to change to unpack directory: ", fdest, 0); goto end; }
// Extract files
if (!extract(cdata, csz)) goto end;
// Move files from temp dir to the install dir
if (!move_program()) goto end;
SetCurrentDirectoryW(L"..");
_snwprintf_s(mb_msg, 4*MAX_PATH, _TRUNCATE,
L"Calibre Portable successfully installed to %s. Launch calibre?",
fdest);
launch = MessageBox(NULL, mb_msg,
L"Success", MB_ICONINFORMATION | MB_YESNO | MB_TOPMOST) == IDYES;
end:
if (unpack_dir != NULL) { rmtree(unpack_dir); free(unpack_dir); }
CoUninitialize();
if (launch) launch_calibre();
return 0;
}

View File

@ -89,7 +89,7 @@ LPTSTR get_app_dir() {
return buf3;
}
void launch_calibre(LPCTSTR exe, LPCTSTR config_dir, LPCTSTR library_dir) {
void launch_calibre(LPCTSTR exe, LPCTSTR config_dir) {
DWORD dwFlags=0;
STARTUPINFO si;
PROCESS_INFORMATION pi;
@ -107,13 +107,12 @@ void launch_calibre(LPCTSTR exe, LPCTSTR config_dir, LPCTSTR library_dir) {
}
dwFlags = CREATE_UNICODE_ENVIRONMENT | CREATE_NEW_PROCESS_GROUP;
_sntprintf_s(cmdline, BUFSIZE, _TRUNCATE, _T(" \"--with-library=%s\""), library_dir);
ZeroMemory( &si, sizeof(si) );
si.cb = sizeof(si);
ZeroMemory( &pi, sizeof(pi) );
fSuccess = CreateProcess(exe, cmdline,
fSuccess = CreateProcess(exe, NULL,
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
@ -134,30 +133,21 @@ void launch_calibre(LPCTSTR exe, LPCTSTR config_dir, LPCTSTR library_dir) {
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
{
LPTSTR app_dir, config_dir, exe, library_dir, too_long;
app_dir = get_app_dir();
config_dir = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR));
library_dir = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR));
exe = (LPTSTR)calloc(BUFSIZE, sizeof(TCHAR));
_sntprintf_s(config_dir, BUFSIZE, _TRUNCATE, _T("%sCalibre Settings"), app_dir);
_sntprintf_s(exe, BUFSIZE, _TRUNCATE, _T("%sCalibre\\calibre.exe"), app_dir);
_sntprintf_s(library_dir, BUFSIZE, _TRUNCATE, _T("%sCalibre Library"), app_dir);
if ( _tcscnlen(library_dir, BUFSIZE) <= 74 ) {
launch_calibre(exe, config_dir, library_dir);
} else {
too_long = (LPTSTR)calloc(BUFSIZE+300, sizeof(TCHAR));
_sntprintf_s(too_long, BUFSIZE+300, _TRUNCATE,
_T("Path to Calibre Portable (%s) too long. Must be less than 59 characters."), app_dir);
launch_calibre(exe, config_dir);
show_error(too_long);
}
free(app_dir); free(config_dir); free(exe); free(library_dir);
free(app_dir); free(config_dir); free(exe);
return 0;
}

View File

@ -30,7 +30,7 @@ def installers():
installers = list(map(installer_name, ('dmg', 'msi', 'tar.bz2')))
installers.append(installer_name('tar.bz2', is64bit=True))
installers.insert(0, 'dist/%s-%s.tar.xz'%(__appname__, __version__))
installers.append('dist/%s-portable-%s.zip'%(__appname__, __version__))
installers.append('dist/%s-portable-installer-%s.exe'%(__appname__, __version__))
return installers
def installer_description(fname):
@ -43,7 +43,7 @@ def installer_description(fname):
return 'Windows installer'
if fname.endswith('.dmg'):
return 'OS X dmg'
if fname.endswith('.zip'):
if fname.endswith('.exe'):
return 'Calibre Portable'
return 'Unknown file'

View File

@ -4,7 +4,7 @@ __license__ = 'GPL v3'
__copyright__ = '2008, Kovid Goyal kovid@kovidgoyal.net'
__docformat__ = 'restructuredtext en'
__appname__ = u'calibre'
numeric_version = (0, 8, 69)
numeric_version = (0, 8, 70)
__version__ = u'.'.join(map(unicode, numeric_version))
__author__ = u"Kovid Goyal <kovid@kovidgoyal.net>"
@ -177,6 +177,11 @@ def get_version():
v += '*'
return v
def get_portable_base():
'Return path to the directory that contains calibre-portable.exe or None'
if isportable:
return os.path.dirname(os.path.dirname(os.environ['CALIBRE_PORTABLE_BUILD']))
def get_unicode_windows_env_var(name):
import ctypes
name = unicode(name)

View File

@ -674,6 +674,7 @@ from calibre.devices.kobo.driver import KOBO
from calibre.devices.bambook.driver import BAMBOOK
from calibre.devices.boeye.driver import BOEYE_BEX, BOEYE_BDX
from calibre.devices.smart_device_app.driver import SMART_DEVICE_APP
from calibre.devices.mtp.driver import MTP_DEVICE
# Order here matters. The first matched device is the one used.
plugins += [
@ -745,14 +746,11 @@ plugins += [
ITUNES,
BOEYE_BEX,
BOEYE_BDX,
MTP_DEVICE,
SMART_DEVICE_APP,
USER_DEFINED,
]
from calibre.utils.config_base import tweaks
if tweaks.get('test_mtp_driver', False):
from calibre.devices.mtp.driver import MTP_DEVICE
plugins.append(MTP_DEVICE)
# }}}
@ -1121,6 +1119,19 @@ class MetadataSources(PreferencesPlugin):
config_widget = 'calibre.gui2.preferences.metadata_sources'
description = _('Control how calibre downloads ebook metadata from the net')
class IgnoredDevices(PreferencesPlugin):
name = 'Ignored Devices'
icon = I('reader.png')
gui_name = _('Ignored devices')
category = 'Sharing'
gui_category = _('Sharing')
category_order = 4
name_order = 4
config_widget = 'calibre.gui2.preferences.ignored_devices'
description = _('Control which devices calibre will ignore when they are connected '
'to the computer.')
class Plugins(PreferencesPlugin):
name = 'Plugins'
icon = I('plugins.png')
@ -1169,7 +1180,7 @@ class Misc(PreferencesPlugin):
plugins += [LookAndFeel, Behavior, Columns, Toolbar, Search, InputOptions,
CommonOptions, OutputOptions, Adding, Saving, Sending, Plugboard,
Email, Server, Plugins, Tweaks, Misc, TemplateFunctions,
MetadataSources, Keyboard]
MetadataSources, Keyboard, IgnoredDevices]
#}}}
@ -1269,17 +1280,6 @@ class StoreBNStore(StoreBase):
headquarters = 'US'
formats = ['NOOK']
class StoreBeamEBooksDEStore(StoreBase):
name = 'Beam EBooks DE'
author = 'Charles Haley'
description = u'Bei uns finden Sie: Tausende deutschsprachige eBooks; Alle eBooks ohne hartes DRM; PDF, ePub und Mobipocket Format; Sofortige Verfügbarkeit - 24 Stunden am Tag; Günstige Preise; eBooks für viele Lesegeräte, PC,Mac und Smartphones; Viele Gratis eBooks'
actual_plugin = 'calibre.gui2.store.stores.beam_ebooks_de_plugin:BeamEBooksDEStore'
drm_free_only = True
headquarters = 'DE'
formats = ['EPUB', 'MOBI', 'PDF']
affiliate = True
class StoreBeWriteStore(StoreBase):
name = 'BeWrite Books'
description = u'Publishers of fine books. Highly selective and editorially driven. Does not offer: books for children or exclusively YA, erotica, swords-and-sorcery fantasy and space-opera-style science fiction. All other genres are represented.'
@ -1650,7 +1650,6 @@ plugins += [
StoreAmazonUKKindleStore,
StoreBaenWebScriptionStore,
StoreBNStore, StoreSonyStore,
StoreBeamEBooksDEStore,
StoreBeWriteStore,
StoreBiblioStore,
StoreBookotekaStore,

View File

@ -6,7 +6,7 @@ __copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
Embedded console for debugging.
'''
import sys, os
import sys, os, functools
from calibre.utils.config import OptionParser
from calibre.constants import iswindows
from calibre import prints
@ -160,26 +160,32 @@ def add_simple_plugin(path_to_plugin):
os.chdir(odir)
shutil.rmtree(tdir)
def run_debug_gui(logpath):
import time, platform
time.sleep(3) # Give previous GUI time to shutdown fully and release locks
from calibre.constants import __appname__, __version__, isosx
print __appname__, _('Debug log')
print __appname__, __version__
print platform.platform()
print platform.system()
print platform.system_alias(platform.system(), platform.release(),
platform.version())
print 'Python', platform.python_version()
def print_basic_debug_info(out=None):
if out is None: out = sys.stdout
out = functools.partial(prints, file=out)
import platform
from calibre.constants import __appname__, get_version, isportable, isosx
out(__appname__, get_version(), 'Portable' if isportable else '')
out(platform.platform(), platform.system())
out(platform.system_alias(platform.system(), platform.release(),
platform.version()))
out('Python', platform.python_version())
try:
if iswindows:
print 'Windows:', platform.win32_ver()
out('Windows:', platform.win32_ver())
elif isosx:
print 'OSX:', platform.mac_ver()
out('OSX:', platform.mac_ver())
else:
print 'Linux:', platform.linux_distribution()
out('Linux:', platform.linux_distribution())
except:
pass
def run_debug_gui(logpath):
import time
time.sleep(3) # Give previous GUI time to shutdown fully and release locks
from calibre.constants import __appname__
prints(__appname__, _('Debug log'))
print_basic_debug_info()
from calibre.gui2.main import main
main(['__CALIBRE_GUI_DEBUG__', logpath])
@ -206,6 +212,7 @@ def main(args=sys.argv):
opts, args = option_parser().parse_args(args)
if opts.gui:
from calibre.gui2.main import main
print_basic_debug_info()
main(['calibre'])
elif opts.gui_debug is not None:
run_debug_gui(opts.gui_debug)

View File

@ -64,8 +64,9 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None):
'''
import textwrap
from calibre.customize.ui import device_plugins
from calibre.debug import print_basic_debug_info
from calibre.devices.scanner import DeviceScanner, win_pnp_drives
from calibre.constants import iswindows, isosx, __version__
from calibre.constants import iswindows, isosx
from calibre import prints
oldo, olde = sys.stdout, sys.stderr
@ -85,7 +86,7 @@ def debug(ioreg_to_tmp=False, buf=None, plugins=None):
out('Startup failed for device plugin: %s'%d)
try:
out('Version:', __version__)
print_basic_debug_info(out=buf)
s = DeviceScanner()
s.scan()
devices = (s.devices)

View File

@ -45,6 +45,7 @@ class ANDROID(USBMS):
0xce5 : HTC_BCDS,
0xcec : HTC_BCDS,
0x2910 : HTC_BCDS,
0xe77 : HTC_BCDS,
0xff9 : HTC_BCDS,
},

View File

@ -99,6 +99,14 @@ class DevicePlugin(Plugin):
#: after the books lists have been loaded to get the driveinfo.
SLOW_DRIVEINFO = False
#: If set to True, calibre will ask the user if they want to manage the
#: device with calibre, the first time it is detected. If you set this to
#: True you must implement :meth:`get_device_uid()` and
#: :meth:`ignore_connected_device()` and
#: :meth:`get_user_blacklisted_devices` and
#: :meth:`set_user_blacklisted_devices`
ASK_TO_ALLOW_CONNECT = False
@classmethod
def get_gui_name(cls):
if hasattr(cls, 'gui_name'):
@ -587,6 +595,37 @@ class DevicePlugin(Plugin):
'''
pass
def get_device_uid(self):
'''
Must return a unique id for the currently connected device (this is
called immediately after a successful call to open()). You must
implement this method if you set ASK_TO_ALLOW_CONNECT = True
'''
raise NotImplementedError()
def ignore_connected_device(self, uid):
'''
Should ignore the device identified by uid (the result of a call to
get_device_uid()) in the future. You must implement this method if you
set ASK_TO_ALLOW_CONNECT = True. Note that this function is called
immediately after open(), so if open() caches some state, the driver
should reset that state.
'''
raise NotImplementedError()
def get_user_blacklisted_devices(self):
'''
Return map of device uid to friendly name for all devices that the user
has asked to be ignored.
'''
return {}
def set_user_blacklisted_devices(self, devices):
'''
Set the list of device uids that should be ignored by this driver.
'''
pass
# Dynamic control interface.
# The following methods are probably called on the GUI thread. Any driver
# that implements these methods must take pains to be thread safe, because

View File

@ -12,7 +12,10 @@ import struct
from calibre.ebooks.mobi.reader.mobi6 import MobiReader
from calibre.ebooks.pdb.header import PdbHeaderReader
from calibre.ebooks.mobi.reader.headers import MetadataHeader
from calibre.utils.logging import default_log
from calibre import prints
from calibre.constants import DEBUG
class APNXBuilder(object):
'''
@ -25,11 +28,32 @@ class APNXBuilder(object):
pass in a value to page_count, otherwise a count will be estimated
using either the fast or accurate algorithm.
'''
# Check that this is really a MOBI file.
import uuid
apnx_meta = { 'guid': str(uuid.uuid4()).replace('-', '')[:8], 'asin':
'', 'cdetype': 'EBOK', 'format': 'MOBI_7', 'acr': '' }
with open(mobi_file_path, 'rb') as mf:
ident = PdbHeaderReader(mf).identity()
if ident != 'BOOKMOBI':
raise Exception(_('Not a valid MOBI file. Reports identity of %s') % ident)
if ident != 'BOOKMOBI':
# Check that this is really a MOBI file.
raise Exception(_('Not a valid MOBI file. Reports identity of %s') % ident)
apnx_meta['acr'] = str(PdbHeaderReader(mf).name())
# We'll need the PDB name, the MOBI version, and some metadata to make FW 3.4 happy with KF8 files...
with open(mobi_file_path, 'rb') as mf:
mh = MetadataHeader(mf, default_log)
if mh.mobi_version == 8:
apnx_meta['format'] = 'MOBI_8'
else:
apnx_meta['format'] = 'MOBI_7'
if mh.exth is None or not mh.exth.cdetype:
apnx_meta['cdetype'] = 'EBOK'
else:
apnx_meta['cdetype'] = str(mh.exth.cdetype)
if mh.exth is None or not mh.exth.uuid:
apnx_meta['asin'] = ''
else:
apnx_meta['asin'] = str(mh.exth.uuid)
# Get the pages depending on the chosen parser
pages = []
@ -51,23 +75,32 @@ class APNXBuilder(object):
raise Exception(_('Could not generate page mapping.'))
# Generate the APNX file from the page mapping.
apnx = self.generate_apnx(pages)
apnx = self.generate_apnx(pages, apnx_meta)
# Write the APNX.
with open(apnx_path, 'wb') as apnxf:
apnxf.write(apnx)
def generate_apnx(self, pages):
import uuid
def generate_apnx(self, pages, apnx_meta):
apnx = ''
content_vals = {
'guid': str(uuid.uuid4()).replace('-', '')[:8],
'isbn': '',
}
if DEBUG:
prints('APNX META: guid:', apnx_meta['guid'])
prints('APNX META: ASIN:', apnx_meta['asin'])
prints('APNX META: CDE:', apnx_meta['cdetype'])
prints('APNX META: format:', apnx_meta['format'])
prints('APNX META: Name:', apnx_meta['acr'])
content_header = '{"contentGuid":"%(guid)s","asin":"%(isbn)s","cdeType":"EBOK","fileRevisionId":"1"}' % content_vals
page_header = '{"asin":"%(isbn)s","pageMap":"(1,a,1)"}' % content_vals
# Updated header if we have a KF8 file...
if apnx_meta['format'] == 'MOBI_8':
content_header = '{"contentGuid":"%(guid)s","asin":"%(asin)s","cdeType":"%(cdetype)s","format":"%(format)s","fileRevisionId":"1","acr":"%(acr)s"}' % apnx_meta
else:
# My 5.1.x Touch & 3.4 K3 seem to handle the 'extended' header fine for legacy mobi files, too. But, since they still handle this one too, let's try not to break old devices, and keep using the simple header ;).
content_header = '{"contentGuid":"%(guid)s","asin":"%(asin)s","cdeType":"%(cdetype)s","fileRevisionId":"1"}' % apnx_meta
page_header = '{"asin":"%(asin)s","pageMap":"(1,a,1)"}' % apnx_meta
if DEBUG:
prints('APNX Content Header:', content_header)
apnx += struct.pack('>I', 65537)
apnx += struct.pack('>I', 12 + len(content_header))

View File

@ -289,7 +289,8 @@ class KINDLE2(KINDLE):
description = _('Communicate with the Kindle 2/3/4/Touch eBook reader.')
FORMATS = ['azw3'] + KINDLE.FORMATS + ['pdf', 'azw4', 'pobi']
DELETE_EXTS = KINDLE.DELETE_EXTS + ['.mbp1', '.mbs', '.sdr']
DELETE_EXTS = KINDLE.DELETE_EXTS + ['.mbp1', '.mbs', '.sdr', '.han']
# On the Touch, there's also .asc files, but not using the same basename (for X-Ray & End Actions), azw3f & azw3r files, but all of them are in the .sdr sidecar folder
PRODUCT_ID = [0x0002, 0x0004]
BCD = [0x0100]

View File

@ -226,6 +226,7 @@ class TREKSTOR(USBMS):
VENDOR_ID = [0x1e68]
PRODUCT_ID = [0x0041, 0x0042, 0x0052, 0x004e, 0x0056,
0x003e, # This is for the EBOOK_PLAYER_5M https://bugs.launchpad.net/bugs/792091
0x5cL, # This is for the 4ink http://www.mobileread.com/forums/showthread.php?t=191318
]
BCD = [0x0002, 0x100]

View File

@ -27,7 +27,7 @@ def synchronous(func):
class MTPDeviceBase(DevicePlugin):
name = 'MTP Device Interface'
gui_name = _('MTP Device')
icon = I('devices/galaxy_s3.png')
icon = I('devices/tablet.png')
description = _('Communicate with MTP devices')
author = 'Kovid Goyal'
version = (1, 0, 0)

View File

@ -0,0 +1,54 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import traceback, re
from calibre.constants import iswindows
class DeviceDefaults(object):
def __init__(self):
self.rules = (
# Amazon devices
({'vendor':0x1949}, {
'format_map': ['azw3', 'mobi', 'azw',
'azw1', 'azw4', 'pdf'],
'send_to': ['documents', 'books', 'kindle'],
}
),
)
def __call__(self, device, driver):
if iswindows:
vid = pid = 0xffff
m = re.search(r'(?i)vid_([0-9a-fA-F]+)&pid_([0-9a-fA-F]+)', device)
if m is not None:
try:
vid, pid = int(m.group(1), 16), int(m.group(2), 16)
except:
traceback.print_exc()
else:
vid, pid = device.vendor_id, device.product_id
for rule in self.rules:
tests = rule[0]
matches = True
for k, v in tests.iteritems():
if k == 'vendor' and v != vid:
matches = False
break
if k == 'product' and v != pid:
matches = False
break
if matches:
return rule[1]
return {}

View File

@ -14,9 +14,11 @@ from itertools import izip
from calibre import prints
from calibre.constants import iswindows, numeric_version
from calibre.devices.mtp.base import debug
from calibre.devices.mtp.defaults import DeviceDefaults
from calibre.ptempfile import SpooledTemporaryFile, PersistentTemporaryDirectory
from calibre.utils.config import from_json, to_json, JSONConfig
from calibre.utils.date import now, isoformat, utcnow
from calibre.utils.filenames import shorten_components_to
BASE = importlib.import_module('calibre.devices.mtp.%s.driver'%(
'windows' if iswindows else 'unix')).MTP_DEVICE
@ -36,22 +38,24 @@ class MTP_DEVICE(BASE):
FORMATS = ['epub', 'azw3', 'mobi', 'pdf']
DEVICE_PLUGBOARD_NAME = 'MTP_DEVICE'
SLOW_DRIVEINFO = True
ASK_TO_ALLOW_CONNECT = True
def __init__(self, *args, **kwargs):
BASE.__init__(self, *args, **kwargs)
self.plugboards = self.plugboard_func = None
self._prefs = None
self.device_defaults = DeviceDefaults()
self.current_device_defaults = {}
@property
def prefs(self):
if self._prefs is None:
from calibre.library.save_to_disk import config
self._prefs = p = JSONConfig('mtp_devices')
p.defaults['format_map'] = self.FORMATS
p.defaults['send_to'] = ['Calibre_Companion', 'Books',
'eBooks/import', 'eBooks', 'wordplayer/calibretransfer',
'sdcard/ebooks', 'kindle']
p.defaults['send_template'] = config().parse().send_template
p.defaults['send_template'] = '{title} - {authors}'
p.defaults['blacklist'] = []
p.defaults['history'] = {}
p.defaults['rules'] = []
@ -74,17 +78,30 @@ class MTP_DEVICE(BASE):
for x in ('format_map', 'send_template', 'send_to'):
del self.prefs[x]
def open(self, devices, library_uuid):
def open(self, device, library_uuid):
self.current_library_uuid = library_uuid
self.location_paths = None
self.driveinfo = {}
BASE.open(self, devices, library_uuid)
BASE.open(self, device, library_uuid)
h = self.prefs['history']
if self.current_serial_num:
h[self.current_serial_num] = (self.current_friendly_name,
isoformat(utcnow()))
self.prefs['history'] = h
self.current_device_defaults = self.device_defaults(device, self)
def get_device_uid(self):
return self.current_serial_num
def ignore_connected_device(self, uid):
bl = self.prefs['blacklist']
if uid not in bl:
bl.append(uid)
self.prefs['blacklist'] = bl
if self.is_mtp_device_connected:
self.eject()
# Device information {{{
def _update_drive_info(self, storage, location_code, name=None):
import uuid
@ -265,7 +282,11 @@ class MTP_DEVICE(BASE):
continue
base = os.path.join(tdir, '%s'%f.object_id)
os.mkdir(base)
with open(os.path.join(base, f.name), 'wb') as out:
name = f.name
if iswindows:
plen = len(base)
name = ''.join(shorten_components_to(245-plen, [name]))
with open(os.path.join(base, name), 'wb') as out:
try:
self.get_mtp_file(f, out)
except Exception as e:
@ -291,7 +312,7 @@ class MTP_DEVICE(BASE):
prefix_path=path,
path_type=posixpath,
maxlen=self.MAX_PATH_LEN,
use_subdirs=True,
use_subdirs='/' in self.save_template,
news_in_folder=self.NEWS_IN_FOLDER,
)
return tuple(x for x in filepath.split('/'))
@ -435,8 +456,13 @@ class MTP_DEVICE(BASE):
# Settings {{{
def get_pref(self, key):
return self.prefs.get('device-%s'%self.current_serial_num, {}).get(key,
self.prefs[key])
''' Get the setting named key. First looks for a device specific setting.
If that is not found looks for a device default and if that is not
found uses the global default.'''
dd = self.current_device_defaults if self.is_mtp_device_connected else {}
dev_settings = self.prefs.get('device-%s'%self.current_serial_num, {})
default_value = dd.get(key, self.prefs[key])
return dev_settings.get(key, default_value)
def config_widget(self):
from calibre.gui2.device_drivers.mtp_config import MTPConfig
@ -453,10 +479,23 @@ class MTP_DEVICE(BASE):
@property
def save_template(self):
return self.prefs['send_template']
return self.get_pref('send_template')
def get_user_blacklisted_devices(self):
bl = frozenset(self.prefs['blacklist'])
ans = {}
for dev, x in self.prefs['history'].iteritems():
name = x[0]
if dev in bl:
ans[dev] = name
return ans
def set_user_blacklisted_devices(self, devs):
self.prefs['blacklist'] = list(devs)
# }}}
if __name__ == '__main__':
dev = MTP_DEVICE(None)
dev.startup()

View File

@ -18,7 +18,7 @@ from calibre.utils.date import local_tz, as_utc
from calibre.utils.icu import sort_key, lower
from calibre.ebooks import BOOK_EXTENSIONS
bexts = frozenset(BOOK_EXTENSIONS)
bexts = frozenset(BOOK_EXTENSIONS) - {'mbp', 'tan', 'rar', 'zip', 'xml'}
class FileOrFolder(object):
@ -204,7 +204,7 @@ class FilesystemCache(object):
except KeyError:
# Parent does not exist, set the parent to be the storage
# object
sid = p.storage_id
sid = item.storage_id
if sid not in all_storage_ids:
sid = all_storage_ids[0]
item.parent_id = sid

View File

@ -11,6 +11,9 @@
const calibre_device_entry_t calibre_mtp_device_table[] = {
#include "upstream/music-players.h"
, { NULL, 0xffff, NULL, 0xffff, DEVICE_FLAG_NONE }
// Amazon Kindle Fire HD
, { "Amazon", 0x1949, "Fire HD", 0x0007, DEVICE_FLAGS_ANDROID_BUGS}
, { NULL, 0xffff, NULL, 0xffff, DEVICE_FLAG_NONE }
};

View File

@ -137,6 +137,10 @@ class MTP_DEVICE(MTPDeviceBase):
self.currently_connected_dev = None
self.current_serial_num = None
@property
def is_mtp_device_connected(self):
return self.currently_connected_dev is not None
@synchronous
def startup(self):
p = plugins['libmtp']
@ -189,6 +193,7 @@ class MTP_DEVICE(MTPDeviceBase):
if not self.current_friendly_name:
self.current_friendly_name = self.dev.model_name or _('Unknown MTP device')
self.current_serial_num = snum
self.currently_connected_dev = connected_device
@property
def filesystem_cache(self):
@ -297,14 +302,16 @@ class MTP_DEVICE(MTPDeviceBase):
def get_mtp_file(self, f, stream=None, callback=None):
if f.is_folder:
raise ValueError('%s if a folder'%(f.full_path,))
set_name = stream is None
if stream is None:
stream = SpooledTemporaryFile(5*1024*1024, '_wpd_receive_file.dat')
stream.name = f.name
ok, errs = self.dev.get_file(f.object_id, stream, callback)
if not ok:
raise DeviceError('Failed to get file: %s with errors: %s'%(
f.full_path, self.format_errorstack(errs)))
stream.seek(0)
if set_name:
stream.name = f.name
return stream
@synchronous

View File

@ -6,6 +6,7 @@
* Copyright (C) 2005-2012 Linus Walleij <triad@df.lth.se>
* Copyright (C) 2006-2007 Marcus Meissner
* Copyright (C) 2007 Ted Bullock
* Copyright (C) 2012 Sony Mobile Communications AB
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@ -1357,6 +1358,9 @@
// Reported by Toni Burgarello
{ "Sony", 0x054c, "Walkman NWZ-S754", 0x04cc,
DEVICE_FLAGS_SONY_NWZ_BUGS },
// Reported by Hideki Yamane <henrich@debian.org>
{ "Sony", 0x054c, "Sony Tablet P1", 0x04d1,
DEVICE_FLAGS_ANDROID_BUGS },
// Reported by dmiceman
{ "Sony", 0x054c, "NWZ-B163F", 0x059a,
DEVICE_FLAGS_SONY_NWZ_BUGS },
@ -1463,10 +1467,11 @@
* 0x6nnn = UMS + ADB
* 0x7nnn = MTP + CDC
* 0x8nnn = MTP + CDC + ADB
* 0xannn = MTP + UMS + ?
* 0xannn = MTP + UMS (MTP for eMMC and UMS for external SD card)
* 0xbnnn = MTP + UMS + ADB
* 0xennn = UMS only
*
* The SonyEricsson and SONY devices have (at least)two deployed MTP
* The SonyEricsson and SONY devices have (at least) two deployed MTP
* stacks: Aricent and Android. These have different bug flags, and
* sometimes the same device has firmware upgrades moving it from
* the Aricent to Android MTP stack without changing the device
@ -1476,6 +1481,7 @@
* That is why DEVICE_FLAG_NONE is used for these devices.
*
* Devices reported by:
* Sony Mobile Communications (via Toby Collett)
* Jonas Salling
* Eamonn Webster <eweb@users.sourceforge.net>
* Alejandro DC <Alejandro_DC@users.sourceforge.ne>
@ -1491,87 +1497,161 @@
* Eduard Bloch <blade@debian.org>
* Ah Hong <hongster@users.sourceforge.net>
*/
{ "SonyEricsson", 0x0fce, "LT15i (Xperia arc S)", 0x014f,
{ "SonyEricsson", 0x0fce, "LT15i Xperia arc S MTP", 0x014f,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "MT11i Xperia Neo", 0x0156,
{ "SonyEricsson", 0x0fce, "MT11i Xperia Neo MTP", 0x0156,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "MK16i Xperia", 0x015a,
{ "SonyEricsson", 0x0fce, "MK16i Xperia MTP", 0x015a,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "ST18a Xperia Ray", 0x0161,
{ "SonyEricsson", 0x0fce, "ST18a Xperia Ray MTP", 0x0161,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "SK17i Xperia Mini Pro", 0x0166,
{ "SonyEricsson", 0x0fce, "SK17i Xperia Mini Pro MTP", 0x0166,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "ST15i Xperia Mini", 0x0167,
{ "SonyEricsson", 0x0fce, "ST15i Xperia Mini MTP", 0x0167,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "ST17i Xperia Active", 0x0168,
{ "SonyEricsson", 0x0fce, "ST17i Xperia Active MTP", 0x0168,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26i Xperia S", 0x0169,
{ "SONY", 0x0fce, "LT26i Xperia S MTP", 0x0169,
DEVICE_FLAG_NO_ZERO_READS },
{ "SONY", 0x0fce, "WT19i Live Walkman", 0x016d,
{ "SONY", 0x0fce, "WT19i Live Walkman MTP", 0x016d,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST21i Xperia Tipo", 0x0170,
{ "SONY", 0x0fce, "ST21i Xperia Tipo MTP", 0x0170,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST15i Xperia U", 0x0171,
{ "SONY", 0x0fce, "ST15i Xperia U MTP", 0x0171,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT22i Xperia P", 0x0172,
{ "SONY", 0x0fce, "LT22i Xperia P MTP", 0x0172,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro S", 0x0176,
{ "SONY", 0x0fce, "MT27i Xperia Sola MTP", 0x0173,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro HD IS12S MTP", 0x0175,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro HD SO-03D MTP", 0x0176,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT28at Xperia Ion MTP", 0x0177,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT29i Xperia GX MTP", 0x0178,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST27i/ST27a Xperia go MTP", 0x017e,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "SO-05D Xperia SX MTP", 0x0181,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT30p Xperia T MTP", 0x0182,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT25i Xperia V MTP", 0x0186,
DEVICE_FLAG_NONE },
/*
* MTP+UMS personalities of MTP devices (see above)
*/
{ "SonyEricsson", 0x0fce, "ST17i Xperia Active (MTP+UMS mode)", 0x4168,
{ "SonyEricsson", 0x0fce, "ST17i Xperia Active MTP+CDROM", 0x4168,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26i Xperia S (MTP+UMS mode)", 0x4169,
{ "SONY", 0x0fce, "LT26i Xperia S MTP+CDROM", 0x4169,
DEVICE_FLAG_NO_ZERO_READS },
{ "SONY", 0x0fce, "ST21i Xperia Tipo (MTP+UMS mode)", 0x4170,
{ "SONY", 0x0fce, "ST21i Xperia Tipo MTP+CDROM", 0x4170,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST25i Xperia U (MTP+UMS mode)", 0x4171,
{ "SONY", 0x0fce, "ST25i Xperia U MTP+CDROM", 0x4171,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT22i Xperia P (MTP+UMS mode)", 0x4172,
{ "SONY", 0x0fce, "LT22i Xperia P MTP+CDROM", 0x4172,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro S (MTP+UMS mode)", 0x4176,
{ "SONY", 0x0fce, "MT27i Xperia Sola MTP+CDROM", 0x4173,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro HD IS12S MTP+CDROM", 0x4175,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro HD SO-03D MTP+CDROM", 0x4176,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT28at Xperia Ion MTP+CDROM", 0x4177,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT29i Xperia GX MTP+CDROM", 0x4178,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST27i/ST27a Xperia go MTP+CDROM", 0x417e,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "SO-05D Xperia SX MTP+CDROM", 0x4181,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT30p Xperia T MTP+CDROM", 0x4182,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT25i Xperia V MTP+CDROM", 0x4186,
DEVICE_FLAG_NONE },
/*
* MTP+ADB personalities of MTP devices (see above)
*/
{ "SonyEricsson", 0x0fce, "LT15i Xperia Arc (MTP+ADB mode)", 0x514f,
{ "SonyEricsson", 0x0fce, "LT15i Xperia Arc MTP+ADB", 0x514f,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "MT11i Xperia Neo (MTP+ADB mode)", 0x5156,
{ "SonyEricsson", 0x0fce, "MT11i Xperia Neo MTP+ADB", 0x5156,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "ST17i Xperia Active (MTP+ADB mode)", 0x5168,
{ "SonyEricsson", 0x0fce, "ST17i Xperia Active MTP+ADB", 0x5168,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26i Xperia S (MTP+ADB mode)", 0x5169,
{ "SONY", 0x0fce, "LT26i Xperia S MTP+ADB", 0x5169,
DEVICE_FLAG_NO_ZERO_READS },
{ "SonyEricsson", 0x0fce, "MK16i Xperia (MTP+ADB mode)", 0x515a,
{ "SonyEricsson", 0x0fce, "MK16i Xperia MTP+ADB", 0x515a,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "ST18i Xperia Ray (MTP+ADB mode)", 0x5161,
{ "SonyEricsson", 0x0fce, "ST18i Xperia Ray MTP+ADB", 0x5161,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "SK17i Xperia Mini Pro (MTP+ADB mode)", 0x5166,
{ "SonyEricsson", 0x0fce, "SK17i Xperia Mini Pro MTP+ADB", 0x5166,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "ST15i Xperia Mini (MTP+ADB mode)", 0x5167,
{ "SonyEricsson", 0x0fce, "ST15i Xperia Mini MTP+ADB", 0x5167,
DEVICE_FLAG_NONE },
{ "SonyEricsson", 0x0fce, "SK17i Xperia Mini Pro (MTP+ADB mode)", 0x516d,
{ "SonyEricsson", 0x0fce, "LT26i Xperia S MTP+ADB", 0x5169,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST21i Xperia Tipo (MTP+ADB mode)", 0x5170,
{ "SonyEricsson", 0x0fce, "SK17i Xperia Mini Pro MTP+ADB", 0x516d,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST25i Xperia U (MTP+ADB mode)", 0x5171,
{ "SONY", 0x0fce, "ST21i Xperia Tipo MTP+ADB", 0x5170,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT22i Xperia P (MTP+ADB mode)", 0x5172,
{ "SONY", 0x0fce, "ST25i Xperia U MTP+ADB", 0x5171,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT26w Xperia Acro S (MTP+ADB mode)", 0x5176,
{ "SONY", 0x0fce, "LT22i Xperia P MTP+ADB", 0x5172,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "MT27i Xperia Sola MTP+ADB", 0x5173,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "IS12S Xperia Acro HD MTP+ADB", 0x5175,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "SO-03D Xperia Acro HD MTP+ADB", 0x5176,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT28at Xperia Ion MTP+ADB", 0x5177,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT29i Xperia GX MTP+ADB", 0x5178,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST27i/ST27a Xperia go MTP+ADB", 0x517e,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "SO-05D Xperia SX MTP+ADB", 0x5181,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT30p Xperia T MTP+ADB", 0x5182,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT25i Xperia V MTP+ADB", 0x5186,
DEVICE_FLAG_NONE },
/*
* MTP+UMS+? modes
* No reports on other personalities on these devices.
* MTP+UMS modes
* This mode is for using MTP on the internal storage (eMMC)
* and using UMS (Mass Storage Device Class) on the external
* SD card
*/
{ "SONY", 0x0fce, "MT27i Xperia Sola (MTP+UMS+? mode)", 0xa173,
{ "SONY", 0x0fce, "MT27i Xperia Sola MTP+UMS", 0xa173,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST27i Xperia Go (MTP+UMS+? mode)", 0xa17e,
{ "SONY", 0x0fce, "IS12S Xperia Acro HD MTP+UMS", 0xa175,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "SO-03D Xperia Acro HD MTP+UMS", 0xa176,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT28at Xperia Ion MTP+UMS", 0xa177,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST27i/ST27a Xperia go MTP+UMS", 0xa17e,
DEVICE_FLAG_NONE },
/*
* MTP+UMS+ADB modes
* Like the above, but also ADB
*/
{ "SONY", 0x0fce, "MT27i Xperia Sola MTP+UMS+ADB", 0xb173,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "IS12S Xperia Acro MTP+UMS+ADB", 0xb175,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "SO-03D Xperia Acro MTP+UMS+ADB", 0xb176,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "LT28at Xperia Ion MTP+UMS+ADB", 0xb177,
DEVICE_FLAG_NONE },
{ "SONY", 0x0fce, "ST27i/ST27a Xperia go MTP+UMS+ADB", 0xb17e,
DEVICE_FLAG_NONE },
/*
* Motorola

View File

@ -146,6 +146,13 @@ class MTP_DEVICE(MTPDeviceBase):
p(traceback.format_exc())
return False
if not pnp_ids:
p('The Windows WPD service says there are no portable devices connected')
return False
p('List of WPD PNP ids:')
p(pprint.pformat(list(pnp_ids)))
for pnp_id in pnp_ids:
try:
data = self.wpd.device_info(pnp_id)
@ -239,6 +246,10 @@ class MTP_DEVICE(MTPDeviceBase):
self.dev = self._filesystem_cache = None
self.current_serial_num = None
@property
def is_mtp_device_connected(self):
return self.currently_connected_pnp_id is not None
def eject(self):
if self.currently_connected_pnp_id is None: return
self.eject_dev_on_next_scan = True
@ -314,9 +325,9 @@ class MTP_DEVICE(MTPDeviceBase):
def get_mtp_file(self, f, stream=None, callback=None):
if f.is_folder:
raise ValueError('%s if a folder'%(f.full_path,))
set_name = stream is None
if stream is None:
stream = SpooledTemporaryFile(5*1024*1024, '_wpd_receive_file.dat')
stream.name = f.name
try:
try:
self.dev.get_file(f.object_id, stream, callback)
@ -325,8 +336,10 @@ class MTP_DEVICE(MTPDeviceBase):
self.dev.get_file(f.object_id, stream, callback)
except Exception as e:
raise DeviceError('Failed to fetch the file %s with error: %s'%
f.full_path, as_unicode(e))
(f.full_path, as_unicode(e)))
stream.seek(0)
if set_name:
stream.name = f.name
return stream
@same_thread

View File

@ -10,9 +10,12 @@ Created on 29 Jun 2012
import socket, select, json, inspect, os, traceback, time, sys, random
import posixpath
import hashlib, threading
import Queue
from base64 import b64encode, b64decode
from functools import wraps
from errno import EAGAIN, EINTR
from threading import Thread
from calibre import prints
from calibre.constants import numeric_version, DEBUG
@ -28,6 +31,7 @@ from calibre.ebooks.metadata import title_sort
from calibre.ebooks.metadata.book.base import Metadata
from calibre.ebooks.metadata.book.json_codec import JsonCodec
from calibre.library import current_library_name
from calibre.library.server import server_config as content_server_config
from calibre.ptempfile import PersistentTemporaryFile
from calibre.utils.ipc import eintr_retry_call
from calibre.utils.config import from_json, tweaks
@ -48,6 +52,117 @@ def synchronous(tlockname):
return _synched
class ConnectionListener (Thread):
def __init__(self, driver):
Thread.__init__(self)
self.daemon = True
self.driver = driver
self.keep_running = True
def stop(self):
self.keep_running = False
def run(self):
queue_not_serviced_count = 0
device_socket = None
while self.keep_running:
try:
time.sleep(1)
except:
# Happens during interpreter shutdown
break
if not self.keep_running:
break
if not self.driver.connection_queue.empty():
queue_not_serviced_count += 1
if queue_not_serviced_count >= 3:
self.driver._debug('queue not serviced')
try:
sock = self.driver.connection_queue.get_nowait()
s = self.driver._json_encode(
self.driver.opcodes['CALIBRE_BUSY'], {})
self.driver._send_byte_string(device_socket, (b'%d' % len(s)) + s)
sock.close()
except Queue.Empty:
pass
queue_not_serviced_count = 0
else:
queue_not_serviced_count = 0
if getattr(self.driver, 'broadcast_socket', None) is not None:
while True:
ans = select.select((self.driver.broadcast_socket,), (), (), 0)
if len(ans[0]) > 0:
try:
packet = self.driver.broadcast_socket.recvfrom(100)
remote = packet[1]
content_server_port = b'';
try :
content_server_port = \
str(content_server_config().parse().port)
except:
pass
message = str(self.driver.ZEROCONF_CLIENT_STRING + b' (on ' +
str(socket.gethostname().partition('.')[0]) +
b');' + content_server_port +
b',' + str(self.driver.port))
self.driver._debug('received broadcast', packet, message)
self.driver.broadcast_socket.sendto(message, remote)
except:
pass
else:
break
if self.driver.connection_queue.empty() and \
getattr(self.driver, 'listen_socket', None) is not None:
ans = select.select((self.driver.listen_socket,), (), (), 0)
if len(ans[0]) > 0:
# timeout in 10 ms to detect rare case where the socket went
# way between the select and the accept
try:
self.driver._debug('attempt to open device socket')
device_socket = None
self.driver.listen_socket.settimeout(0.010)
device_socket, ign = eintr_retry_call(
self.driver.listen_socket.accept)
self.driver.listen_socket.settimeout(None)
device_socket.settimeout(None)
try:
peer = self.driver.device_socket.getpeername()[0]
attempts = self.drjver.connection_attempts.get(peer, 0)
if attempts >= self.MAX_UNSUCCESSFUL_CONNECTS:
self.driver._debug('too many connection attempts from', peer)
device_socket.close()
device_socket = None
# raise InitialConnectionError(_('Too many connection attempts from %s') % peer)
else:
self.driver.connection_attempts[peer] = attempts + 1
except InitialConnectionError:
raise
except:
pass
try:
self.driver.connection_queue.put_nowait(device_socket)
except Queue.Full:
device_socket.close()
device_socket = None
self.driver._debug('driver is not answering')
except socket.timeout:
pass
except socket.error:
x = sys.exc_info()[1]
self.driver._debug('unexpected socket exception', x.args[0])
device_socket.close()
device_socket = None
# raise
class SDBook(Book):
def __init__(self, prefix, lpath, size=None, other=None):
Book.__init__(self, prefix, lpath, size=size, other=other)
@ -56,8 +171,10 @@ class SDBook(Book):
class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
name = 'SmartDevice App Interface'
gui_name = _('SmartDevice')
icon = I('devices/galaxy_s3.png')
gui_name = _('Wireless Device')
gui_name_template = '%s: %s'
icon = I('devices/tablet.png')
description = _('Communicate with Smart Device apps')
supported_platforms = ['windows', 'osx', 'linux']
author = 'Charles Haley'
@ -80,8 +197,20 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
NEWS_IN_FOLDER = True
SUPPORTS_USE_AUTHOR_SORT = False
WANTS_UPDATED_THUMBNAILS = True
# Guess about the max length on windows. This number will be reduced by
# the length of the path on the client, and by the fudge factor below. We
# use this on all platforms because the device might be connected to windows
# in the future.
MAX_PATH_LEN = 250
# guess of length of MTP name. The length of the full path to the folder
# on the device is added to this. That path includes the device's mount point
# making this number effectively around 10 to 15 larger.
PATH_FUDGE_FACTOR = 40
THUMBNAIL_HEIGHT = 160
DEFAULT_THUMBNAIL_HEIGHT = 160
PREFIX = ''
BACKLOADING_ERROR_MESSAGE = None
@ -112,6 +241,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
'OK' : 0,
'BOOK_DATA' : 10,
'BOOK_DONE' : 11,
'CALIBRE_BUSY' : 18,
'DELETE_BOOK' : 13,
'DISPLAY_MESSAGE' : 17,
'FREE_SPACE' : 5,
@ -201,28 +331,30 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self.client_can_stream_metadata = False
def _debug(self, *args):
if not DEBUG:
return
total_elapsed = time.time() - self.debug_start_time
elapsed = time.time() - self.debug_time
print('SMART_DEV (%7.2f:%7.3f) %s'%(total_elapsed, elapsed,
inspect.stack()[1][3]), end='')
for a in args:
try:
if isinstance(a, dict):
printable = {}
for k,v in a.iteritems():
if isinstance(v, (str, unicode)) and len(v) > 50:
printable[k] = 'too long'
else:
printable[k] = v
prints('', printable, end='')
else:
prints('', a, end='')
except:
prints('', 'value too long', end='')
print()
self.debug_time = time.time()
# manual synchronization so we don't lose the calling method name
with self.sync_lock:
if not DEBUG:
return
total_elapsed = time.time() - self.debug_start_time
elapsed = time.time() - self.debug_time
print('SMART_DEV (%7.2f:%7.3f) %s'%(total_elapsed, elapsed,
inspect.stack()[1][3]), end='')
for a in args:
try:
if isinstance(a, dict):
printable = {}
for k,v in a.iteritems():
if isinstance(v, (str, unicode)) and len(v) > 50:
printable[k] = 'too long'
else:
printable[k] = v
prints('', printable, end='')
else:
prints('', a, end='')
except:
prints('', 'value too long', end='')
print()
self.debug_time = time.time()
# local utilities
@ -248,7 +380,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
# remove the 'path' argument and all its uses. Also removed the calls to
# filename_callback and sanitize_path_components
def _create_upload_path(self, mdata, fname, create_dirs=True):
maxlen = self.MAX_PATH_LEN
fname = sanitize(fname)
ext = os.path.splitext(fname)[1]
maxlen = (self.MAX_PATH_LEN - (self.PATH_FUDGE_FACTOR +
self.exts_path_lengths.get(ext, self.PATH_FUDGE_FACTOR)))
special_tag = None
if mdata.tags:
@ -269,9 +405,6 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
template = "{title}_%d-%d-%d" % date
use_subdirs = self.SUPPORTS_SUB_DIRS and settings.use_subdirs
fname = sanitize(fname)
ext = os.path.splitext(fname)[1]
from calibre.library.save_to_disk import get_components
from calibre.library.save_to_disk import config
opts = config().parse()
@ -346,6 +479,13 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
return json.dumps([op, res], encoding='utf-8')
# Network functions
def _read_binary_from_net(self, length):
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
v = self.device_socket.recv(length)
self.device_socket.settimeout(None)
return v
def _read_string_from_net(self):
data = bytes(0)
while True:
@ -354,9 +494,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
break
# recv seems to return a pointer into some internal buffer.
# Things get trashed if we don't make a copy of the data.
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
v = self.device_socket.recv(2)
self.device_socket.settimeout(None)
v = self._read_binary_from_net(2)
if len(v) == 0:
return '' # documentation says the socket is broken permanently.
data += v
@ -364,16 +502,14 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
data = data[dex:]
pos = len(data)
while pos < total_len:
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
v = self.device_socket.recv(total_len - pos)
self.device_socket.settimeout(None)
v = self._read_binary_from_net(total_len - pos)
if len(v) == 0:
return '' # documentation says the socket is broken permanently.
data += v
pos += len(v)
return data
def _send_byte_string(self, s):
def _send_byte_string(self, sock, s):
if not isinstance(s, bytes):
self._debug('given a non-byte string!')
raise PacketError("Internal error: found a string that isn't bytes")
@ -382,11 +518,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
while sent_len < total_len:
try:
if sent_len == 0:
amt_sent = self.device_socket.send(s)
amt_sent = sock.send(s)
else:
amt_sent = self.device_socket.send(s[sent_len:])
amt_sent = sock.send(s[sent_len:])
if amt_sent <= 0:
raise IOError('Bad write on device socket')
raise IOError('Bad write on socket')
sent_len += amt_sent
except socket.error as e:
self._debug('socket error', e, e.errno)
@ -410,7 +546,7 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
if print_debug_info and extra_debug:
self._debug('send string', s)
self.device_socket.settimeout(self.MAX_CLIENT_COMM_TIMEOUT)
self._send_byte_string((b'%d' % len(s)) + s)
self._send_byte_string(self.device_socket, (b'%d' % len(s)) + s)
if not wait_for_response:
return None, None
return self._receive_from_client(print_debug_info=print_debug_info)
@ -466,11 +602,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
length = infile.tell()
book_metadata.size = length
infile.seek(0)
self._debug(lpath, length)
opcode, result = self._call_client('SEND_BOOK', {'lpath': lpath, 'length': length,
'metadata': book_metadata, 'thisBook': this_book,
'totalBooks': total_books,
'willStreamBooks': self.client_can_stream_books},
'willStreamBooks': self.client_can_stream_books,
'willStreamBinary' : self.client_can_receive_book_binary},
print_debug_info=False,
wait_for_response=(not self.client_can_stream_books))
@ -483,17 +620,21 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
blen = len(b)
if not b:
break
b = b64encode(b)
opcode, result = self._call_client('BOOK_DATA',
{'lpath': lpath, 'position': pos, 'data': b},
print_debug_info=False,
wait_for_response=(not self.client_can_stream_books))
if self.client_can_stream_books and self.client_can_receive_book_binary:
self._send_byte_string(self.device_socket, b)
else:
b = b64encode(b)
opcode, result = self._call_client('BOOK_DATA',
{'lpath': lpath, 'position': pos, 'data': b},
print_debug_info=False,
wait_for_response=(not self.client_can_stream_books))
pos += blen
if not self.client_can_stream_books and opcode != 'OK':
self._debug('protocol error', opcode)
failed = True
break
self._call_client('BOOK_DONE', {'lpath': lpath})
if not (self.client_can_stream_books and self.client_can_receive_book_binary):
self._call_client('BOOK_DONE', {'lpath': lpath})
self.time = None
if close_:
infile.close()
@ -517,7 +658,8 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
v = self.known_metadata.get(book.lpath, None)
if v is not None:
return (v.get('uuid', None) == book.get('uuid', None) and
v.get('last_modified', None) == book.get('last_modified', None))
v.get('last_modified', None) == book.get('last_modified', None) and
v.get('thumbnail', None) == book.get('thumbnail', None))
return False
def _set_known_metadata(self, book, remove=False):
@ -620,39 +762,26 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
break
if getattr(self, 'listen_socket', None) is not None:
ans = select.select((self.listen_socket,), (), (), 0)
if len(ans[0]) > 0:
# timeout in 10 ms to detect rare case where the socket went
# way between the select and the accept
try:
ans = self.connection_queue.get_nowait()
self.device_socket = ans
self.is_connected = True
try:
self.device_socket = None
self.listen_socket.settimeout(0.010)
self.device_socket, ign = eintr_retry_call(
self.listen_socket.accept)
self.listen_socket.settimeout(None)
self.device_socket.settimeout(None)
self.is_connected = True
try:
peer = self.device_socket.getpeername()[0]
attempts = self.connection_attempts.get(peer, 0)
if attempts >= self.MAX_UNSUCCESSFUL_CONNECTS:
self._debug('too many connection attempts from', peer)
self._close_device_socket()
raise InitialConnectionError(_('Too many connection attempts from %s') % peer)
else:
self.connection_attempts[peer] = attempts + 1
except InitialConnectionError:
raise
except:
pass
except socket.timeout:
self._close_device_socket()
except socket.error:
x = sys.exc_info()[1]
self._debug('unexpected socket exception', x.args[0])
self._close_device_socket()
peer = self.device_socket.getpeername()[0]
attempts = self.connection_attempts.get(peer, 0)
if attempts >= self.MAX_UNSUCCESSFUL_CONNECTS:
self._debug('too many connection attempts from', peer)
self._close_device_socket()
raise InitialConnectionError(_('Too many connection attempts from %s') % peer)
else:
self.connection_attempts[peer] = attempts + 1
except InitialConnectionError:
raise
return (self.is_connected, self)
except:
pass
except Queue.Empty:
self.is_connected = False
return (self.is_connected, self)
return (False, None)
@synchronous('sync_lock')
@ -705,17 +834,37 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self._debug('Device can stream books', self.client_can_stream_books)
self.client_can_stream_metadata = result.get('canStreamMetadata', False)
self._debug('Device can stream metadata', self.client_can_stream_metadata)
self.client_can_receive_book_binary = result.get('canReceiveBookBinary', False)
self._debug('Device can receive book binary', self.client_can_stream_metadata)
self.client_device_kind = result.get('deviceKind', '')
self._debug('Client device kind', self.client_device_kind)
self.max_book_packet_len = result.get('maxBookContentPacketLen',
self.BASE_PACKET_LEN)
self._debug('max_book_packet_len', self.max_book_packet_len)
exts = result.get('acceptedExtensions', None)
if exts is None or not isinstance(exts, list) or len(exts) == 0:
self._debug('Protocol error - bogus accepted extensions')
self._close_device_socket()
return False
config = self._configProxy()
config['format_map'] = exts
self._debug('selected formats', config['format_map'])
self.exts_path_lengths = result.get('extensionPathLengths', {})
self._debug('extension path lengths', self.exts_path_lengths)
self.THUMBNAIL_HEIGHT = result.get('coverHeight', self.DEFAULT_THUMBNAIL_HEIGHT)
if 'coverWidth' in result:
# Setting this field forces the aspect ratio
self.THUMBNAIL_WIDTH = result.get('coverWidth',
(self.DEFAULT_THUMBNAIL_HEIGHT/3) * 4)
elif hasattr(self, 'THUMBNAIL_WIDTH'):
delattr(self, 'THUMBNAIL_WIDTH')
if password:
returned_hash = result.get('passwordHash', None)
if result.get('passwordHash', None) is None:
@ -752,6 +901,12 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
raise
return False
def get_gui_name(self):
if self.client_device_kind:
return self.gui_name_template%(self.gui_name, self.client_device_kind)
return self.gui_name
@synchronous('sync_lock')
def get_device_information(self, end_session=True):
self._debug()
@ -909,7 +1064,10 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
@synchronous('sync_lock')
def upload_books(self, files, names, on_card=None, end_session=True,
metadata=None):
self._debug(names)
if self.settings().extra_customization[self.OPT_EXTRA_DEBUG]:
self._debug(names)
else:
self._debug()
paths = []
names = iter(names)
@ -956,7 +1114,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
@synchronous('sync_lock')
def delete_books(self, paths, end_session=True):
self._debug(paths)
if self.settings().extra_customization[self.OPT_EXTRA_DEBUG]:
self._debug(paths)
else:
self._debug()
for path in paths:
# the path has the prefix on it (I think)
path = self._strip_prefix(path)
@ -968,7 +1130,11 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
@synchronous('sync_lock')
def remove_books_from_metadata(self, paths, booklists):
self._debug(paths)
if self.settings().extra_customization[self.OPT_EXTRA_DEBUG]:
self._debug(paths)
else:
self._debug()
for i, path in enumerate(paths):
path = self._strip_prefix(path)
self.report_progress((i + 1) / float(len(paths)), _('Removing books from device metadata listing...'))
@ -983,29 +1149,45 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
@synchronous('sync_lock')
def get_file(self, path, outfile, end_session=True, this_book=None, total_books=None):
self._debug(path)
if self.settings().extra_customization[self.OPT_EXTRA_DEBUG]:
self._debug(path)
else:
self._debug()
eof = False
position = 0
while not eof:
opcode, result = self._call_client('GET_BOOK_FILE_SEGMENT',
{'lpath' : path, 'position': position,
'thisBook': this_book, 'totalBooks': total_books,
'canStream':True},
'canStream':True, 'canStreamBinary': True},
print_debug_info=False)
if opcode == 'OK':
client_will_stream = 'willStream' in result
while not eof:
if not result['eof']:
data = b64decode(result['data'])
if len(data) != result['next_position'] - position:
self._debug('position mismatch', result['next_position'], position)
position = result['next_position']
outfile.write(data)
opcode, result = self._receive_from_client(print_debug_info=True)
else:
eof = True
if not client_will_stream:
break
client_will_stream_binary = 'willStreamBinary' in result
if (client_will_stream_binary):
length = result.get('fileLength')
remaining = length
while remaining > 0:
v = self._read_binary_from_net(min(remaining, self.max_book_packet_len))
outfile.write(v)
remaining -= len(v)
eof = True
else:
while not eof:
if not result['eof']:
data = b64decode(result['data'])
if len(data) != result['next_position'] - position:
self._debug('position mismatch', result['next_position'], position)
position = result['next_position']
outfile.write(data)
opcode, result = self._receive_from_client(print_debug_info=True)
else:
eof = True
if not client_will_stream:
break
else:
raise ControlError(desc='request for book data failed')
@ -1127,17 +1309,22 @@ class SMART_DEVICE_APP(DeviceConfig, DevicePlugin):
self._debug('broadcast socket listening on port', port)
break
message = None
if port == 0:
self.broadcast_socket.close()
self.broadcast_socket = None
message = 'attaching port to broadcast socket failed. This is not fatal.'
self._debug(message)
return message
self.connection_queue = Queue.Queue(1)
self.connection_listener = ConnectionListener(self)
self.connection_listener.start()
return message
@synchronous('sync_lock')
def shutdown(self):
if getattr(self, 'listen_socket', None) is not None:
self.connection_listener.stop()
unpublish_zeroconf('calibre smart device client',
'_calibresmartdeviceapp._tcp', self.port, {})
self._close_listen_socket()

View File

@ -163,7 +163,7 @@ def render_html(path_to_html, width=590, height=750, as_xhtml=True):
def check_ebook_format(stream, current_guess):
ans = current_guess
if current_guess.lower() in ('prc', 'mobi', 'azw', 'azw1'):
if current_guess.lower() in ('prc', 'mobi', 'azw', 'azw1', 'azw3'):
stream.seek(0)
if stream.read(3) == 'TPZ':
ans = 'tpz'

View File

@ -70,7 +70,7 @@ class ArchiveExtract(FileTypePlugin):
fname = fnames[0]
ext = os.path.splitext(fname)[1][1:]
if ext.lower() not in ('lit', 'epub', 'mobi', 'prc', 'rtf', 'pdf',
'mp3', 'pdb', 'azw', 'azw1', 'fb2'):
'mp3', 'pdb', 'azw', 'azw1', 'azw3', 'fb2'):
return archive
of = self.temporary_file('_archive_extract.'+ext)

View File

@ -15,7 +15,7 @@ _METADATA_PRIORITIES = [
'html', 'htm', 'xhtml', 'xhtm',
'rtf', 'fb2', 'pdf', 'prc', 'odt',
'epub', 'lit', 'lrx', 'lrf', 'mobi',
'rb', 'imp', 'azw', 'snb'
'azw', 'azw3', 'azw1', 'rb', 'imp', 'snb'
]
# The priorities for loading metadata from different file types

View File

@ -341,11 +341,14 @@ class MetadataUpdater(object):
kindle_pdoc = None
share_not_sync = False
if mi.author_sort and pas:
authors = mi.author_sort
update_exth_record((100, normalize(authors).encode(self.codec, 'replace')))
# We want an EXTH field per author...
authors = mi.author_sort.split(' & ')
for author in authors:
update_exth_record((100, normalize(author).encode(self.codec, 'replace')))
elif mi.authors:
authors = ';'.join(mi.authors)
update_exth_record((100, normalize(authors).encode(self.codec, 'replace')))
authors = mi.authors
for author in authors:
update_exth_record((100, normalize(author).encode(self.codec, 'replace')))
if mi.publisher:
update_exth_record((101, normalize(mi.publisher).encode(self.codec, 'replace')))
if mi.comments:
@ -360,6 +363,7 @@ class MetadataUpdater(object):
if mi.isbn:
update_exth_record((104, mi.isbn.encode(self.codec, 'replace')))
if mi.tags:
# FIXME: Keep a single subject per EXTH field?
subjects = '; '.join(mi.tags)
update_exth_record((105, normalize(subjects).encode(self.codec, 'replace')))

View File

@ -1359,7 +1359,10 @@ class OPFCreator(Metadata):
guide = E.guide()
if self.guide is not None:
for ref in self.guide:
item = E.reference(type=ref.type, href=ref.href())
href = ref.href()
if isinstance(href, bytes):
href = href.decode('utf-8')
item = E.reference(type=ref.type, href=href)
if ref.title:
item.set('title', ref.title)
guide.append(item)

View File

@ -32,7 +32,7 @@ def get_metadata(stream):
if stream_type:
stream_type = stream_type[1:]
if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub',
'rb', 'imp', 'pdf', 'lrf', 'azw'):
'rb', 'imp', 'pdf', 'lrf', 'azw', 'azw1', 'azw3'):
with TemporaryDirectory() as tdir:
with CurrentDir(tdir):
stream = extract_member(path, match=None, name=f,

View File

@ -23,7 +23,7 @@ def get_metadata(stream):
if stream_type:
stream_type = stream_type[1:]
if stream_type in ('lit', 'opf', 'prc', 'mobi', 'fb2', 'epub',
'rb', 'imp', 'pdf', 'lrf', 'azw'):
'rb', 'imp', 'pdf', 'lrf', 'azw', 'azw1', 'azw3'):
with TemporaryDirectory() as tdir:
with CurrentDir(tdir):
path = zf.extract(f)

View File

@ -116,61 +116,83 @@ class Record(object): # {{{
# EXTH {{{
class EXTHRecord(object):
def __init__(self, type_, data):
def __init__(self, type_, data, length):
self.type = type_
self.data = data
self.length = length
self.name = {
1 : 'DRM Server id',
2 : 'DRM Commerce id',
3 : 'DRM ebookbase book id',
100 : 'author',
101 : 'publisher',
102 : 'imprint',
103 : 'description',
104 : 'isbn',
105 : 'subject',
106 : 'publishingdate',
107 : 'review',
108 : 'contributor',
109 : 'rights',
110 : 'subjectcode',
111 : 'type',
112 : 'source',
113 : 'asin',
114 : 'versionnumber',
1 : 'Drm Server Id',
2 : 'Drm Commerce Id',
3 : 'Drm Ebookbase Book Id',
100 : 'Creator',
101 : 'Publisher',
102 : 'Imprint',
103 : 'Description',
104 : 'ISBN',
105 : 'Subject',
106 : 'Published',
107 : 'Review',
108 : 'Contributor',
109 : 'Rights',
110 : 'SubjectCode',
111 : 'Type',
112 : 'Source',
113 : 'ASIN',
114 : 'versionNumber',
115 : 'sample',
116 : 'startreading',
117 : 'adult',
118 : 'retailprice',
119 : 'retailpricecurrency',
121 : 'KF8 header section index',
125 : 'KF8 resources (images/fonts) count',
129 : 'KF8 cover URI',
131 : 'KF8 unknown count',
201 : 'coveroffset',
202 : 'thumboffset',
203 : 'hasfakecover',
116 : 'StartOffset',
117 : 'Adult',
118 : 'Price',
119 : 'Currency',
121 : 'KF8_Boundary_Section',
122 : 'fixed-layout',
123 : 'book-type',
124 : 'orientation-lock',
125 : 'KF8_Count_of_Resources_Fonts_Images',
126 : 'original-resolution',
127 : 'zero-gutter',
128 : 'zero-margin',
129 : 'KF8_Masthead/Cover_Image',
131 : 'KF8_Unidentified_Count',
132 : 'RegionMagnification',
200 : 'DictShortName',
201 : 'CoverOffset',
202 : 'ThumbOffset',
203 : 'Fake Cover',
204 : 'Creator Software',
205 : 'Creator Major Version', # '>I'
206 : 'Creator Minor Version', # '>I'
207 : 'Creator Build Number', # '>I'
208 : 'watermark',
209 : 'tamper_proof_keys',
300 : 'fontsignature',
301 : 'clippinglimit', # percentage '>B'
402 : 'publisherlimit',
404 : 'TTS flag', # '>B' 1 - TTS disabled 0 - TTS enabled
501 : 'cdetype', # 4 chars (PDOC or EBOK)
502 : 'lastupdatetime',
503 : 'updatedtitle',
524 : 'language',
208 : 'Watermark',
209 : 'Tamper Proof Keys [hex]',
300 : 'Font Signature [hex]',
301 : 'Clipping Limit [3xx]', # percentage '>B'
401 : 'Clipping Limit', # percentage '>B'
402 : 'Publisher Limit',
404 : 'Text to Speech Disabled', # '>B' 1 - TTS disabled 0 - TTS enabled
501 : 'CDE Type', # 4 chars (PDOC, EBOK, MAGZ, ...)
502 : 'last_update_time',
503 : 'Updated Title',
504 : 'ASIN [5xx]',
524 : 'Language',
525 : 'TextDirection',
528 : 'Unknown_Logical_Value',
535 : 'Kindlegen Build-Rev Number',
}.get(self.type, repr(self.type))
if (self.name in {'coveroffset', 'thumboffset', 'hasfakecover',
'Creator Major Version', 'Creator Minor Version',
'Creator Build Number', 'Creator Software', 'startreading'} or
if (self.name in {'sample', 'StartOffset', 'CoverOffset', 'ThumbOffset', 'Fake Cover',
'Creator Software', 'Creator Major Version', 'Creator Minor Version',
'Creator Build Number', 'Clipping Limit (3xx)', 'Clipping Limit',
'Publisher Limit', 'Text to Speech Disabled'} or
self.type in {121, 125, 131}):
self.data, = struct.unpack(b'>I', self.data)
if self.length == 9:
self.data, = struct.unpack(b'>B', self.data)
elif self.length == 10:
self.data, = struct.unpack(b'>H', self.data)
else:
self.data, = struct.unpack(b'>L', self.data)
elif self.type in {209, 300}:
self.data = bytes(self.data.encode('hex'))
def __str__(self):
return '%s (%d): %r'%(self.name, self.type, self.data)
@ -181,8 +203,8 @@ class EXTHHeader(object):
self.raw = raw
if not self.raw.startswith(b'EXTH'):
raise ValueError('EXTH header does not start with EXTH')
self.length, = struct.unpack(b'>I', self.raw[4:8])
self.count, = struct.unpack(b'>I', self.raw[8:12])
self.length, = struct.unpack(b'>L', self.raw[4:8])
self.count, = struct.unpack(b'>L', self.raw[8:12])
pos = 12
self.records = []
@ -199,9 +221,9 @@ class EXTHHeader(object):
return getattr(ans, 'data', default)
def read_record(self, pos):
type_, length = struct.unpack(b'>II', self.raw[pos:pos+8])
type_, length = struct.unpack(b'>LL', self.raw[pos:pos+8])
data = self.raw[(pos+8):(pos+length)]
self.records.append(EXTHRecord(type_, data))
self.records.append(EXTHRecord(type_, data, length))
return pos + length
@property

View File

@ -802,7 +802,7 @@ def inspect_mobi(mobi_file, ddir):
alltext += rec.raw
of.seek(0)
root = html.fromstring(alltext.decode('utf-8'))
root = html.fromstring(alltext.decode(f.mobi_header.encoding))
with open(os.path.join(ddir, 'pretty.html'), 'wb') as of:
of.write(html.tostring(root, pretty_print=True, encoding='utf-8',
include_meta_content_type=True))

View File

@ -88,7 +88,7 @@ class EXTHHeader(object): # {{{
self.mi.authors = []
au = content.decode(codec, 'ignore').strip()
self.mi.authors.append(au)
if re.match(r'\S+?\s*,\s+\S+', au.strip()):
if self.mi.is_null('author_sort') and re.match(r'\S+?\s*,\s+\S+', au.strip()):
self.mi.author_sort = au.strip()
elif idx == 101:
self.mi.publisher = content.decode(codec, 'ignore').strip()

View File

@ -481,7 +481,7 @@ def write_font_record(data, obfuscate=True, compress=True):
if compress:
flags |= 0b1
data = zlib.compress(data, 9)
if obfuscate:
if obfuscate and len(data) >= 1040:
flags |= 0b10
xor_key = os.urandom(key_len)
key = bytearray(xor_key)

View File

@ -11,8 +11,9 @@ import re
from struct import pack
from io import BytesIO
from calibre.ebooks.mobi.utils import utf8_text
from calibre.ebooks.mobi.utils import (utf8_text, to_base)
from calibre.utils.localization import lang_as_iso639_1
from calibre.ebooks.metadata import authors_to_sort_string
EXTH_CODES = {
'creator': 100,
@ -30,6 +31,7 @@ EXTH_CODES = {
'startreading': 116,
'kf8_header_index': 121,
'num_of_resources': 125,
'kf8_thumbnail_uri': 129,
'kf8_unknown_count': 131,
'coveroffset': 201,
'thumboffset': 202,
@ -54,8 +56,8 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
items = metadata[term]
if term == 'creator':
if prefer_author_sort:
creators = [unicode(c.file_as or c) for c in
items][:1]
creators = [authors_to_sort_string([unicode(c)]) for c in
items]
else:
creators = [unicode(c) for c in items]
items = creators
@ -159,7 +161,10 @@ def build_exth(metadata, prefer_author_sort=False, is_periodical=False,
if thumbnail_offset is not None:
exth.write(pack(b'>III', EXTH_CODES['thumboffset'], 12,
thumbnail_offset))
nrecs += 1
thumbnail_uri_str = bytes('kindle:embed:%s' %(to_base(thumbnail_offset, base=32, min_num_digits=4)))
exth.write(pack(b'>II', EXTH_CODES['kf8_thumbnail_uri'], len(thumbnail_uri_str) + 8))
exth.write(thumbnail_uri_str)
nrecs += 2
if start_offset is not None:
try:

View File

@ -8,6 +8,7 @@ __copyright__ = '2008, Marshall T. Vandegrift <llasram@gmail.com>'
import re, operator, math
from collections import defaultdict
from xml.dom import SyntaxErr
from lxml import etree
import cssutils
@ -279,7 +280,7 @@ class CSSFlattener(object):
if 'color' in node.attrib:
try:
cssdict['color'] = Property('color', node.attrib['color']).value
except ValueError:
except (ValueError, SyntaxErr):
pass
del node.attrib['color']
if 'bgcolor' in node.attrib:

View File

@ -96,7 +96,7 @@ class SVGRasterizer(object):
def dataize_manifest(self):
for item in self.oeb.manifest.values():
if item.media_type == SVG_MIME:
if item.media_type == SVG_MIME and item.data is not None:
self.dataize_svg(item)
def dataize_svg(self, item, svg=None):

View File

@ -13,7 +13,7 @@ from PyQt4.Qt import (QVariant, QFileInfo, QObject, SIGNAL, QBuffer, Qt,
ORG_NAME = 'KovidsBrain'
APP_UID = 'libprs500'
from calibre.constants import (islinux, iswindows, isbsd, isfrozen, isosx,
config_dir, filesystem_encoding)
plugins, config_dir, filesystem_encoding, DEBUG)
from calibre.utils.config import Config, ConfigProxy, dynamic, JSONConfig
from calibre.ebooks.metadata import MetaInformation
from calibre.utils.date import UNDEFINED_DATE
@ -294,7 +294,9 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=False,
# Set skip_dialog_name to a unique name for this dialog
# Set skip_dialog_msg to a message displayed to the user
skip_dialog_name=None, skip_dialog_msg=_('Show this confirmation again'),
skip_dialog_skipped_value=True, skip_dialog_skip_precheck=True):
skip_dialog_skipped_value=True, skip_dialog_skip_precheck=True,
# Override icon (QIcon to be used as the icon for this dialog)
override_icon=None):
from calibre.gui2.dialogs.message_box import MessageBox
auto_skip = set(gprefs.get('questions_to_auto_skip', []))
@ -302,7 +304,8 @@ def question_dialog(parent, title, msg, det_msg='', show_copy_button=False,
return bool(skip_dialog_skipped_value)
d = MessageBox(MessageBox.QUESTION, title, msg, det_msg, parent=parent,
show_copy_button=show_copy_button, default_yes=default_yes)
show_copy_button=show_copy_button, default_yes=default_yes,
q_icon=override_icon)
if skip_dialog_name is not None and skip_dialog_msg:
tc = d.toggle_checkbox
@ -477,10 +480,13 @@ class FileIconProvider(QFileIconProvider):
'prc' : 'mobi',
'azw' : 'mobi',
'mobi' : 'mobi',
'pobi' : 'mobi',
'mbp' : 'zero',
'azw1' : 'mobi',
'azw1' : 'tpz',
'azw2' : 'azw2',
'azw3' : 'azw3',
'azw4' : 'pdf',
'tpz' : 'mobi',
'tpz' : 'tpz',
'tan' : 'zero',
'epub' : 'epub',
'fb2' : 'fb2',
@ -564,7 +570,8 @@ class FileDialog(QObject):
modal = True,
name = '',
mode = QFileDialog.ExistingFiles,
default_dir='~'
default_dir='~',
no_save_dir=False
):
QObject.__init__(self)
ftext = ''
@ -583,8 +590,11 @@ class FileDialog(QObject):
self.selected_files = None
self.fd = None
initial_dir = dynamic.get(self.dialog_name,
os.path.expanduser(default_dir))
if no_save_dir:
initial_dir = os.path.expanduser(default_dir)
else:
initial_dir = dynamic.get(self.dialog_name,
os.path.expanduser(default_dir))
if not isinstance(initial_dir, basestring):
initial_dir = os.path.expanduser(default_dir)
self.selected_files = []
@ -626,7 +636,8 @@ class FileDialog(QObject):
saved_loc = self.selected_files[0]
if os.path.isfile(saved_loc):
saved_loc = os.path.dirname(saved_loc)
dynamic[self.dialog_name] = saved_loc
if not no_save_dir:
dynamic[self.dialog_name] = saved_loc
self.accepted = bool(self.selected_files)
def get_files(self):
@ -635,10 +646,10 @@ class FileDialog(QObject):
return tuple(self.selected_files)
def choose_dir(window, name, title, default_dir='~'):
def choose_dir(window, name, title, default_dir='~', no_save_dir=False):
fd = FileDialog(title=title, filters=[], add_all_files_filter=False,
parent=window, name=name, mode=QFileDialog.Directory,
default_dir=default_dir)
default_dir=default_dir, no_save_dir=no_save_dir)
dir = fd.get_files()
fd.setParent(None)
if dir:
@ -756,6 +767,9 @@ class Application(QApplication):
if override_program_name:
args = [override_program_name] + args[1:]
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
self.pi = plugins['progress_indicator'][0]
if DEBUG:
self.redirect_notify = True
QApplication.__init__(self, qargs)
global gui_thread, qt_app
gui_thread = QThread.currentThread()
@ -766,15 +780,23 @@ class Application(QApplication):
self._file_open_lock = RLock()
self.setup_styles(force_calibre_style)
if DEBUG:
def notify(self, receiver, event):
if self.redirect_notify:
self.redirect_notify = False
return self.pi.do_notify(receiver, event)
else:
ret = QApplication.notify(self, receiver, event)
self.redirect_notify = True
return ret
def load_calibre_style(self):
# On OS X QtCurve resets the palette, so we preserve it explicitly
orig_pal = QPalette(self.palette())
from calibre.constants import plugins
pi = plugins['progress_indicator'][0]
path = os.path.join(sys.extensions_location, 'calibre_style.'+(
'pyd' if iswindows else 'so'))
pi.load_style(path, 'Calibre')
self.pi.load_style(path, 'Calibre')
# On OSX, on some machines, colors can be invalid. See https://bugs.launchpad.net/bugs/1014900
for role in (orig_pal.Button, orig_pal.Window):
c = orig_pal.brush(role).color()

View File

@ -30,7 +30,7 @@ def get_filters():
(_('LRF Books'), ['lrf']),
(_('HTML Books'), ['htm', 'html', 'xhtm', 'xhtml']),
(_('LIT Books'), ['lit']),
(_('MOBI Books'), ['mobi', 'prc', 'azw']),
(_('MOBI Books'), ['mobi', 'prc', 'azw', 'azw3']),
(_('Topaz books'), ['tpz','azw1']),
(_('Text books'), ['txt', 'text', 'rtf']),
(_('PDF Books'), ['pdf', 'azw4']),

View File

@ -5,7 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
import os
import os, posixpath
from functools import partial
from PyQt4.Qt import (QMenu, Qt, QInputDialog, QToolButton, QDialog,
@ -13,7 +13,8 @@ from PyQt4.Qt import (QMenu, Qt, QInputDialog, QToolButton, QDialog,
QCoreApplication, pyqtSignal)
from calibre import isbytestring, sanitize_file_name_unicode
from calibre.constants import filesystem_encoding, iswindows
from calibre.constants import (filesystem_encoding, iswindows,
get_portable_base)
from calibre.utils.config import prefs
from calibre.gui2 import (gprefs, warning_dialog, Dispatcher, error_dialog,
question_dialog, info_dialog, open_local_file, choose_dir)
@ -25,6 +26,17 @@ class LibraryUsageStats(object): # {{{
def __init__(self):
self.stats = {}
self.read_stats()
base = get_portable_base()
if base is not None:
lp = prefs['library_path']
if lp:
# Rename the current library. Renaming of other libraries is
# handled by the switch function
q = os.path.basename(lp)
for loc in list(self.stats.iterkeys()):
bn = posixpath.basename(loc)
if bn.lower() == q.lower():
self.rename(loc, lp)
def read_stats(self):
stats = gprefs.get('library_usage_stats', {})
@ -417,6 +429,18 @@ class ChooseLibraryAction(InterfaceAction):
finally:
self.gui.status_bar.clear_message()
def look_for_portable_lib(self, db, location):
base = get_portable_base()
if base is None:
return False, None
loc = location.replace('/', os.sep)
candidate = os.path.join(base, os.path.basename(loc))
if db.exists_at(candidate):
newloc = candidate.replace(os.sep, '/')
self.stats.rename(location, newloc)
return True, newloc
return False, None
def switch_requested(self, location):
if not self.change_library_allowed():
return
@ -425,6 +449,12 @@ class ChooseLibraryAction(InterfaceAction):
self.view_state_map[current_lib] = self.preserve_state_on_switch.state
loc = location.replace('/', os.sep)
exists = db.exists_at(loc)
if not exists:
exists, new_location = self.look_for_portable_lib(db, location)
if exists:
location = new_location
loc = location.replace('/', os.sep)
if not exists:
d = MovedDialog(self.stats, location, self.gui)
ret = d.exec_()

View File

@ -139,7 +139,7 @@ class ShareConnMenu(QMenu): # {{{
def setup_email(self, *args):
self.config_email.emit()
def set_state(self, device_connected):
def set_state(self, device_connected, device):
self.connect_to_folder_action.setEnabled(not device_connected)
self.connect_to_itunes_action.setEnabled(not device_connected)
self.connect_to_bambook_action.setEnabled(not device_connected)
@ -187,8 +187,8 @@ class ConnectShareAction(InterfaceAction):
enabled = loc == 'library'
self.qaction.setEnabled(enabled)
def set_state(self, device_connected):
self.share_conn_menu.set_state(device_connected)
def set_state(self, device_connected, device):
self.share_conn_menu.set_state(device_connected, device)
def build_email_entries(self):
m = self.gui.iactions['Send To Device'].qaction.menu()

View File

@ -17,7 +17,7 @@ class PluginWidget(Widget, Ui_Form):
TITLE = _('AZW3 Output')
HELP = _('Options specific to')+' AZW3 '+_('output')
COMMIT_NAME = 'azw3_output'
ICON = I('mimetypes/mobi.png')
ICON = I('mimetypes/azw3.png')
def __init__(self, parent, get_option, get_help, db=None, book_id=None):
Widget.__init__(self, parent,

View File

@ -20,7 +20,7 @@ from calibre.utils.ipc.job import BaseJob
from calibre.devices.scanner import DeviceScanner
from calibre.gui2 import (config, error_dialog, Dispatcher, dynamic,
warning_dialog, info_dialog, choose_dir, FunctionDispatcher,
show_restart_warning)
show_restart_warning, gprefs, question_dialog)
from calibre.ebooks.metadata import authors_to_string
from calibre import preferred_encoding, prints, force_unicode, as_unicode
from calibre.utils.filenames import ascii_filename
@ -122,7 +122,7 @@ def device_name_for_plugboards(device_class):
class DeviceManager(Thread): # {{{
def __init__(self, connected_slot, job_manager, open_feedback_slot,
open_feedback_msg, sleep_time=2):
open_feedback_msg, allow_connect_slot, sleep_time=2):
'''
:sleep_time: Time to sleep between device probes in secs
'''
@ -136,6 +136,7 @@ class DeviceManager(Thread): # {{{
x.MANAGES_DEVICE_PRESENCE]
self.sleep_time = sleep_time
self.connected_slot = connected_slot
self.allow_connect_slot = allow_connect_slot
self.jobs = Queue.Queue(0)
self.job_steps = Queue.Queue(0)
self.keep_going = True
@ -193,6 +194,21 @@ class DeviceManager(Thread): # {{{
return False
def after_device_connect(self, dev, device_kind):
allow_connect = True
try:
uid = dev.get_device_uid()
except NotImplementedError:
uid = None
asked = gprefs.get('ask_to_manage_device', [])
if (dev.ASK_TO_ALLOW_CONNECT and uid and uid not in asked):
if not self.allow_connect_slot(dev.get_gui_name(), dev.icon):
allow_connect = False
asked.append(uid)
gprefs.set('ask_to_manage_device', asked)
if not allow_connect:
dev.ignore_connected_device(uid)
return
self.connected_device = dev
self.connected_device_kind = device_kind
self.connected_slot(True, device_kind)
@ -829,12 +845,19 @@ class DeviceMixin(object): # {{{
self.device_error_dialog.setModal(Qt.NonModal)
self.device_manager = DeviceManager(FunctionDispatcher(self.device_detected),
self.job_manager, Dispatcher(self.status_bar.show_message),
Dispatcher(self.show_open_feedback))
Dispatcher(self.show_open_feedback),
FunctionDispatcher(self.allow_connect))
self.device_manager.start()
self.device_manager.devices_initialized.wait()
if tweaks['auto_connect_to_folder']:
self.connect_to_folder_named(tweaks['auto_connect_to_folder'])
def allow_connect(self, name, icon):
return question_dialog(self, _('Manage the %s?')%name,
_('Detected the <b>%s</b>. Do you want calibre to manage it?')%
name, show_copy_button=False,
override_icon=QIcon(icon))
def debug_detection(self, done):
self.debug_detection_callback = weakref.ref(done)
self.device_manager.debug_detection(FunctionDispatcher(self.debug_detection_done))
@ -929,7 +952,8 @@ class DeviceMixin(object): # {{{
self._sync_menu.fetch_annotations.connect(
self.iactions['Fetch Annotations'].fetch_annotations)
self._sync_menu.disconnect_mounted_device.connect(self.disconnect_mounted_device)
self.iactions['Connect Share'].set_state(self.device_connected)
self.iactions['Connect Share'].set_state(self.device_connected,
None)
if self.device_connected:
self._sync_menu.disconnect_mounted_device_action.setEnabled(True)
else:
@ -968,7 +992,8 @@ class DeviceMixin(object): # {{{
# Device connected {{{
def set_device_menu_items_state(self, connected):
self.iactions['Connect Share'].set_state(connected)
self.iactions['Connect Share'].set_state(connected,
self.device_manager.device)
if connected:
self._sync_menu.disconnect_mounted_device_action.setEnabled(True)
self._sync_menu.enable_device_actions(True,
@ -1671,11 +1696,7 @@ class DeviceMixin(object): # {{{
if update_metadata:
mi = db.get_metadata(id_, index_is_id=True,
get_cover=get_covers)
if book.get('last_modified', None) != mi.last_modified:
book.smart_update(db.get_metadata(id_,
index_is_id=True,
get_cover=get_covers),
replace_metadata=True)
book.smart_update(mi, replace_metadata=True)
book.in_library = 'UUID'
# ensure that the correct application_id is set
book.application_id = id_

View File

@ -163,7 +163,7 @@ class IgnoredDevices(QWidget): # {{{
self.l = l = QVBoxLayout()
self.setLayout(l)
self.la = la = QLabel('<p>'+_(
'''Select the devices to be <b>ignored</b>. calibre will not
'''Select the devices to be <b>ignored</b>. calibre <b>will not</b>
connect to devices with a checkmark next to their names.'''))
la.setWordWrap(True)
l.addWidget(la)
@ -208,11 +208,12 @@ class Rule(QWidget):
self.l = l = QHBoxLayout()
self.setLayout(l)
self.l1 = l1 = QLabel(_('Send the '))
p, s = _('Send the %s format to the folder:').partition('%s')[0::2]
self.l1 = l1 = QLabel(p)
l.addWidget(l1)
self.fmt = f = QComboBox(self)
l.addWidget(f)
self.l2 = l2 = QLabel(_(' format to the folder: '))
self.l2 = l2 = QLabel(s)
l.addWidget(l2)
self.folder = f = QLineEdit(self)
f.setPlaceholderText(_('Folder on the device'))
@ -385,7 +386,7 @@ class MTPConfig(QTabWidget):
self.device.prefs['blacklist'])
self.addTab(self.igntab, _('Ignored devices'))
self.setCurrentIndex(0)
self.setCurrentIndex(1 if msg else 0)
def ignore_device(self):
self.igntab.ignore_device(self.device.current_serial_num)
@ -399,7 +400,7 @@ class MTPConfig(QTabWidget):
p = self.device.prefs.get(self.current_device_key, {})
if not p:
self.device.prefs[self.current_device_key] = p
return p.get(key, self.device.prefs[key])
return self.device.get_pref(key)
@property
def device(self):
@ -414,6 +415,7 @@ class MTPConfig(QTabWidget):
return True
def commit(self):
self.device.prefs['blacklist'] = self.igntab.blacklist
p = self.device.prefs.get(self.current_device_key, {})
if hasattr(self, 'formats'):
@ -439,7 +441,6 @@ class MTPConfig(QTabWidget):
self.device.prefs[self.current_device_key] = p
self.device.prefs['blacklist'] = self.igntab.blacklist
if __name__ == '__main__':
from calibre.gui2 import Application

View File

@ -89,7 +89,7 @@ class Browser(QDialog):
self.setMinimumSize(QSize(500, 500))
self.folders.selected.connect(self.accept)
self.setWindowTitle(_('Choose folder on device'))
self.setWindowIcon(QIcon(I('devices/galaxy_s3.png')))
self.setWindowIcon(QIcon(I('devices/tablet.png')))
@property
def current_item(self):

View File

@ -11,8 +11,9 @@ from PyQt4.Qt import QDialog
from calibre.gui2.dialogs.choose_library_ui import Ui_Dialog
from calibre.gui2 import error_dialog, choose_dir
from calibre.constants import filesystem_encoding, iswindows
from calibre import isbytestring, patheq
from calibre.constants import (filesystem_encoding, iswindows,
get_portable_base)
from calibre import isbytestring, patheq, force_unicode
from calibre.gui2.wizard import move_library
from calibre.library.database2 import LibraryDatabase2
@ -39,18 +40,45 @@ class ChooseLibrary(QDialog, Ui_Dialog):
self.copy_structure.setEnabled(to_what)
def choose_loc(self, *args):
loc = choose_dir(self, 'choose library location',
_('Choose location for calibre library'))
base = get_portable_base()
if base is None:
loc = choose_dir(self, 'choose library location',
_('Choose location for calibre library'))
else:
name = force_unicode('choose library loc at' + base,
filesystem_encoding)
loc = choose_dir(self, name,
_('Choose location for calibre library'), default_dir=base,
no_save_dir=True)
if loc is not None:
self.location.setText(loc)
def check_action(self, ac, loc):
exists = self.db.exists_at(loc)
base = get_portable_base()
if patheq(loc, self.db.library_path):
error_dialog(self, _('Same as current'),
_('The location %s contains the current calibre'
' library')%loc, show=True)
return False
if base is not None and ac in ('new', 'move'):
abase = os.path.normcase(os.path.abspath(base))
cal = os.path.normcase(os.path.abspath(os.path.join(abase,
'Calibre')))
aloc = os.path.normcase(os.path.abspath(loc))
if (aloc.startswith(cal+os.sep) or aloc == cal):
error_dialog(self, _('Bad location'),
_('You should not create a library inside the Calibre'
' folder as this folder is automatically deleted during upgrades.'),
show=True)
return False
if aloc.startswith(abase) and os.path.dirname(aloc) != abase:
error_dialog(self, _('Bad location'),
_('You can only create libraries inside %s at the top '
'level, not in sub-folders')%base, show=True)
return False
empty = not os.listdir(loc)
if ac == 'existing' and not exists:
error_dialog(self, _('No existing library found'),

View File

@ -15,7 +15,7 @@
</property>
<property name="windowIcon">
<iconset resource="../../../../resources/images.qrc">
<normaloff>:/images/devices/galaxy_s3.png</normaloff>:/images/devices/galaxy_s3.png</iconset>
<normaloff>:/images/devices/tablet.png</normaloff>:/images/devices/tablet.png</iconset>
</property>
<layout class="QGridLayout">
<item row="0" column="0" colspan="3">

View File

@ -9,7 +9,7 @@ import sys
from PyQt4.Qt import (Qt, QApplication, QStyle, QIcon, QDoubleSpinBox,
QVariant, QSpinBox, QStyledItemDelegate, QComboBox, QTextDocument,
QAbstractTextDocumentLayout, QFont, QFontInfo)
QAbstractTextDocumentLayout, QFont, QFontInfo, QDate)
from calibre.gui2 import UNDEFINED_QDATETIME, error_dialog, rating_font
from calibre.constants import iswindows
@ -83,6 +83,7 @@ class DateDelegate(QStyledItemDelegate): # {{{
qde.setSpecialValueText(_('Undefined'))
qde.setCalendarPopup(True)
return qde
# }}}
class PubDateDelegate(QStyledItemDelegate): # {{{
@ -104,6 +105,12 @@ class PubDateDelegate(QStyledItemDelegate): # {{{
qde.setCalendarPopup(True)
return qde
def setEditorData(self, editor, index):
val = index.data(Qt.EditRole).toDate()
if val == UNDEFINED_QDATETIME.date():
val = QDate(2000, 1, 1)
editor.setDate(val)
# }}}
class TextDelegate(QStyledItemDelegate): # {{{

View File

@ -9,7 +9,7 @@ from PyQt4.Qt import (QCoreApplication, QIcon, QObject, QTimer,
from calibre import prints, plugins, force_unicode
from calibre.constants import (iswindows, __appname__, isosx, DEBUG, islinux,
filesystem_encoding)
filesystem_encoding, get_portable_base)
from calibre.utils.ipc import gui_socket_address, RC
from calibre.gui2 import (ORG_NAME, APP_UID, initialize_file_icon_provider,
Application, choose_dir, error_dialog, question_dialog, gprefs)
@ -21,6 +21,9 @@ from calibre.library.sqlite import sqlite, DatabaseException
if iswindows:
winutil = plugins['winutil'][0]
class AbortInit(Exception):
pass
def option_parser():
parser = _option_parser('''\
%prog [opts] [path_to_ebook]
@ -46,10 +49,43 @@ path_to_ebook to the database.
'will be silently aborted, so use with care.'))
return parser
def find_portable_library():
base = get_portable_base()
if base is None: return
import glob
candidates = [os.path.basename(os.path.dirname(x)) for x in glob.glob(
os.path.join(base, u'*%smetadata.db'%os.sep))]
if not candidates:
candidates = [u'Calibre Library']
lp = prefs['library_path']
if not lp:
lib = os.path.join(base, candidates[0])
else:
lib = None
q = os.path.basename(lp)
for c in candidates:
c = c
if c.lower() == q.lower():
lib = os.path.join(base, c)
break
if lib is None:
lib = os.path.join(base, candidates[0])
if len(lib) > 74:
error_dialog(None, _('Path too long'),
_("Path to Calibre Portable (%s) "
'too long. Must be less than 59 characters.')%base, show=True)
raise AbortInit()
prefs.set('library_path', lib)
if not os.path.exists(lib):
os.mkdir(lib)
def init_qt(args):
from calibre.gui2.ui import Main
parser = option_parser()
opts, args = parser.parse_args(args)
find_portable_library()
if opts.with_library is not None:
if not os.path.exists(opts.with_library):
os.makedirs(opts.with_library)
@ -360,7 +396,10 @@ def main(args=sys.argv):
gui_debug = args[1]
args = ['calibre']
app, opts, args, actions = init_qt(args)
try:
app, opts, args, actions = init_qt(args)
except AbortInit:
return 1
from calibre.utils.lock import singleinstance
from multiprocessing.connection import Listener
si = singleinstance('calibre GUI')

View File

@ -0,0 +1,72 @@
#!/usr/bin/env python
# vim:fileencoding=UTF-8:ts=4:sw=4:sta:et:sts=4:fdm=marker:ai
from __future__ import (unicode_literals, division, absolute_import,
print_function)
__license__ = 'GPL v3'
__copyright__ = '2012, Kovid Goyal <kovid at kovidgoyal.net>'
__docformat__ = 'restructuredtext en'
from PyQt4.Qt import (QLabel, QVBoxLayout, QListWidget, QListWidgetItem, Qt)
from calibre.gui2.preferences import ConfigWidgetBase, test_widget
class ConfigWidget(ConfigWidgetBase):
restart_critical = False
def genesis(self, gui):
self.gui = gui
self.l = l = QVBoxLayout()
self.setLayout(l)
self.la = la = QLabel(_(
'The list of devices that you have asked calibre to ignore. '
'Uncheck a device to have calibre stop ignoring it.'))
la.setWordWrap(True)
l.addWidget(la)
self.devices = f = QListWidget(self)
l.addWidget(f)
f.itemChanged.connect(self.changed_signal)
f.itemDoubleClicked.connect(self.toggle_item)
def toggle_item(self, item):
item.setCheckState(Qt.Checked if item.checkState() == Qt.Unchecked else
Qt.Unchecked)
def initialize(self):
self.devices.blockSignals(True)
self.devices.clear()
for dev in self.gui.device_manager.devices:
for d, name in dev.get_user_blacklisted_devices().iteritems():
item = QListWidgetItem('%s [%s]'%(name, d), self.devices)
item.setData(Qt.UserRole, (dev, d))
item.setFlags(Qt.ItemIsEnabled|Qt.ItemIsUserCheckable|Qt.ItemIsSelectable)
item.setCheckState(Qt.Checked)
self.devices.blockSignals(False)
def restore_defaults(self):
if self.devices.count() > 0:
self.devices.clear()
def commit(self):
devs = {}
for i in xrange(0, self.devices.count()):
e = self.devices.item(i)
dev, uid = e.data(Qt.UserRole).toPyObject()
if dev not in devs:
devs[dev] = []
if e.checkState() == Qt.Checked:
devs[dev].append(uid)
for dev, bl in devs.iteritems():
dev.set_user_blacklisted_devices(bl)
return True # Restart required
if __name__ == '__main__':
from PyQt4.Qt import QApplication
app = QApplication([])
test_widget('Sharing', 'Ignored Devices')

View File

@ -5,6 +5,7 @@
#include <QPluginLoader>
#include <QStyle>
#include <QApplication>
#include <QDebug>
QProgressIndicator::QProgressIndicator(QWidget* parent, int size)
: QWidget(parent),
@ -145,3 +146,16 @@ int load_style(QString &path, QString &name) {
}
return ret;
}
bool do_notify(QObject *receiver, QEvent *event) {
try {
return QApplication::instance()->notify(receiver, event);
} catch (std::exception& e) {
qCritical() << "C++ exception thrown in slot: " << e.what();
} catch (...) {
qCritical() << "Unknown C++ exception thrown in slot";
}
qCritical() << "Receiver name:" << receiver->objectName() << "Receiver class:" << receiver->metaObject()->className() << "Event type: " << event->type();
return false;
}

View File

@ -100,3 +100,5 @@ private:
*/
int load_style(QString &path, QString &name);
bool do_notify(QObject *receiver, QEvent *event);

View File

@ -8,6 +8,7 @@
%ModuleHeaderCode
int load_style(QString &path, QString &name);
bool do_notify(QObject *receiver, QEvent *event);
%End
class QProgressIndicator : QWidget {
@ -57,3 +58,5 @@ protected:
int load_style(QString &path, QString &name);
bool do_notify(QObject *receiver, QEvent *event);

View File

@ -1,92 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import (unicode_literals, division, absolute_import, print_function)
__license__ = 'GPL 3'
__copyright__ = '2011, John Schember <john@nachtimwald.com>'
__docformat__ = 'restructuredtext en'
import urllib2
from contextlib import closing
from lxml import html
from PyQt4.Qt import QUrl
from calibre import browser
from calibre.gui2 import open_url
from calibre.gui2.store import StorePlugin
from calibre.gui2.store.basic_config import BasicStoreConfig
from calibre.gui2.store.search_result import SearchResult
from calibre.gui2.store.web_store_dialog import WebStoreDialog
class BeamEBooksDEStore(BasicStoreConfig, StorePlugin):
def open(self, parent=None, detail_item=None, external=False):
url = 'http://klick.affiliwelt.net/klick.php?bannerid=10072&pid=32307&prid=908'
url_details = ('http://klick.affiliwelt.net/klick.php?'
'bannerid=10730&pid=32307&prid=908&prodid={0}')
if external or self.config.get('open_external', False):
if detail_item:
url = url_details.format(detail_item)
open_url(QUrl(url))
else:
detail_url = None
if detail_item:
detail_url = url_details.format(detail_item)
d = WebStoreDialog(self.gui, url, parent, detail_url)
d.setWindowTitle(self.name)
d.set_tags(self.config.get('tags', ''))
d.exec_()
def search(self, query, max_results=10, timeout=60):
url = 'http://www.beam-ebooks.de/suchergebnis.php?Type=&sw=' + urllib2.quote(query)
br = browser()
counter = max_results
with closing(br.open(url, timeout=timeout)) as f:
doc = html.fromstring(f.read())
for data in doc.xpath('//table[tr/td/div[@class="stil2"]]'):
if counter <= 0:
break
id = ''.join(data.xpath('./tr/td[1]/a/@href')).strip()
if not id:
continue
id = id[7:]
cover_url = ''.join(data.xpath('./tr/td[1]/a/img/@src'))
if cover_url:
cover_url = 'http://www.beam-ebooks.de' + cover_url
temp = ''.join(data.xpath('./tr/td[1]/a/img/@alt'))
colon = temp.find(':')
if not temp.startswith('eBook') or colon < 0:
continue
author = temp[5:colon]
title = temp[colon+1:]
price = ''.join(data.xpath('./tr/td[3]/text()'))
pdf = data.xpath(
'boolean(./tr/td[3]/a/img[contains(@alt, "PDF")]/@alt)')
epub = data.xpath(
'boolean(./tr/td[3]/a/img[contains(@alt, "ePub")]/@alt)')
mobi = data.xpath(
'boolean(./tr/td[3]/a/img[contains(@alt, "Mobipocket")]/@alt)')
counter -= 1
s = SearchResult()
s.cover_url = cover_url
s.title = title.strip()
s.author = author.strip()
s.price = price
s.drm = SearchResult.DRM_UNLOCKED
s.detail_item = id
formats = []
if epub:
formats.append('ePub')
if pdf:
formats.append('PDF')
if mobi:
formats.append('MOBI')
s.formats = ', '.join(formats)
yield s

View File

@ -234,6 +234,9 @@ class QueueBulk(QProgressDialog):
def fetch_scheduled_recipe(arg): # {{{
fmt = prefs['output_format'].lower()
# Never use AZW3 for periodicals...
if fmt == 'azw3':
fmt = 'mobi'
pt = PersistentTemporaryFile(suffix='_recipe_out.%s'%fmt.lower())
pt.close()
recs = []

View File

@ -61,13 +61,18 @@ def generate_test_db(library_path, # {{{
print 'Time per record:', t/float(num_of_records)
# }}}
def current_library_name():
def current_library_path():
from calibre.utils.config import prefs
import posixpath
path = prefs['library_path']
if path:
path = path.replace('\\', '/')
while path.endswith('/'):
path = path[:-1]
return path
def current_library_name():
import posixpath
path = current_library_path()
if path:
return posixpath.basename(path)

View File

@ -989,8 +989,8 @@ class CatalogBuilder(object):
file_fmts.add(fmt)
bookmark_extension = None
if file_fmts.intersection(han_formats):
book_extension = list(file_fmts.intersection(han_formats))[0]
if file_fmts.intersection(tan_formats):
book_extension = list(file_fmts.intersection(tan_formats))[0]
bookmark_extension = 'han'
elif file_fmts.intersection(mbp_formats):
book_extension = list(file_fmts.intersection(mbp_formats))[0]

View File

@ -1004,6 +1004,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
mi.format_metadata = FormatMetadata(self, idx, formats)
good_formats = FormatsList(formats, mi.format_metadata)
mi.formats = good_formats
mi.db_approx_formats = formats
tags = row[fm['tags']]
if tags:
mi.tags = [i.strip() for i in tags.split(',')]
@ -1262,6 +1263,7 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
ans = {}
if path is not None:
stat = os.stat(path)
ans['path'] = path
ans['size'] = stat.st_size
ans['mtime'] = utcfromtimestamp(stat.st_mtime)
self.format_metadata_cache[id_][fmt] = ans
@ -2563,6 +2565,11 @@ class LibraryDatabase2(LibraryDatabase, SchemaUpgrade, CustomColumns):
if notify:
self.notify('metadata', [id])
def get_id_from_uuid(self, uuid):
if uuid:
return self.conn.get('SELECT id FROM books WHERE uuid=?', (uuid,),
all=False)
# Convenience methods for tags_list_editor
# Note: we generally do not need to refresh_ids because library_view will
# refresh everything.

View File

@ -181,7 +181,7 @@ class AjaxServer(object):
return data, mi.last_modified
@Endpoint(set_last_modified=False)
def ajax_book(self, book_id, category_urls='true'):
def ajax_book(self, book_id, category_urls='true', id_is_uuid='false'):
'''
Return the metadata of the book as a JSON dictionary.
@ -192,7 +192,10 @@ class AjaxServer(object):
cherrypy.response.timeout = 3600
try:
book_id = int(book_id)
if id_is_uuid == 'true':
book_id = self.db.get_id_from_uuid(book_id)
else:
book_id = int(book_id)
data, last_modified = self.ajax_book_to_json(book_id,
get_category_urls=category_urls.lower()=='true')
except:
@ -204,7 +207,7 @@ class AjaxServer(object):
return data
@Endpoint(set_last_modified=False)
def ajax_books(self, ids=None, category_urls='true'):
def ajax_books(self, ids=None, category_urls='true', id_is_uuid='false'):
'''
Return the metadata for a list of books specified as a comma separated
list of ids. The metadata is returned as a dictionary mapping ids to
@ -218,7 +221,10 @@ class AjaxServer(object):
if ids is None:
raise cherrypy.HTTPError(404, 'Must specify some ids')
try:
ids = set(int(x.strip()) for x in ids.split(','))
if id_is_uuid == 'true':
ids = set(self.db.get_id_from_uuid(x) for x in ids.split(','))
else:
ids = set(int(x.strip()) for x in ids.split(','))
except:
raise cherrypy.HTTPError(404, 'ids must be a comma separated list'
' of integers')

Some files were not shown because too many files have changed in this diff Show More