mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 10:14:46 -04:00
Advertise the calibre Stanza server on Bonjour. Now accessing your calibre EPUB collection in Stanza should be automatic on your home network.
This commit is contained in:
parent
abc2b71f2f
commit
792e993222
@ -23,6 +23,8 @@ from calibre.resources import jquery, server_resources, build_time
|
|||||||
from calibre.library import server_config as config
|
from calibre.library import server_config as config
|
||||||
from calibre.library.database2 import LibraryDatabase2, FIELD_MAP
|
from calibre.library.database2 import LibraryDatabase2, FIELD_MAP
|
||||||
from calibre.utils.config import config_dir
|
from calibre.utils.config import config_dir
|
||||||
|
from calibre.utils.mdns import publish as publish_zeroconf, \
|
||||||
|
stop_server as stop_zeroconf
|
||||||
|
|
||||||
build_time = datetime.strptime(build_time, '%d %m %Y %H%M%S')
|
build_time = datetime.strptime(build_time, '%d %m %Y %H%M%S')
|
||||||
server_resources['jquery.js'] = jquery
|
server_resources['jquery.js'] = jquery
|
||||||
@ -171,17 +173,14 @@ class LibraryServer(object):
|
|||||||
try:
|
try:
|
||||||
cherrypy.engine.start()
|
cherrypy.engine.start()
|
||||||
self.is_running = True
|
self.is_running = True
|
||||||
try:
|
publish_zeroconf('Books in calibre', '_stanza._tcp',
|
||||||
subprocess.Popen(('dns-sd -R "calibre Books" '
|
self.opts.port, {'path':'/stanza'})
|
||||||
'_stanza._tcp local %d')%
|
|
||||||
self.opts.port, shell=True)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
cherrypy.engine.block()
|
cherrypy.engine.block()
|
||||||
except Exception, e:
|
except Exception, e:
|
||||||
self.exception = e
|
self.exception = e
|
||||||
finally:
|
finally:
|
||||||
self.is_running = False
|
self.is_running = False
|
||||||
|
stop_zeroconf()
|
||||||
|
|
||||||
def exit(self):
|
def exit(self):
|
||||||
cherrypy.engine.exit()
|
cherrypy.engine.exit()
|
||||||
@ -338,7 +337,11 @@ class LibraryServer(object):
|
|||||||
@expose
|
@expose
|
||||||
def index(self, **kwargs):
|
def index(self, **kwargs):
|
||||||
'The / URL'
|
'The / URL'
|
||||||
|
stanza = cherrypy.request.headers.get('Stanza-Device-Name', 919)
|
||||||
|
if stanza == 919:
|
||||||
return self.static('index.html')
|
return self.static('index.html')
|
||||||
|
return self.stanza()
|
||||||
|
|
||||||
|
|
||||||
@expose
|
@expose
|
||||||
def get(self, what, id):
|
def get(self, what, id):
|
||||||
|
@ -123,15 +123,15 @@ turned into a collection on the reader. Note that the PRS-500 does not support c
|
|||||||
How do I use |app| with my iPhone?
|
How do I use |app| with my iPhone?
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
First install the Stanza reader on your iPhone from http://www.lexcycle.com . Then,
|
First install the Stanza reader on your iPhone from http://www.lexcycle.com . Then,
|
||||||
* Set the output format for calibre to EPUB (this can be done in the configuration dialog accessed by the little hammer icon next to the search bar)
|
* Set the output format for calibre to EPUB (The output format can be set next to the big red heart)
|
||||||
* Convert the books you want to read on your iPhone to EPUB format by selecting them and clicking the Convert button.
|
* Convert the books you want to read on your iPhone to EPUB format by selecting them and clicking the Convert button.
|
||||||
* Turn on the Content Server in the configurations dialog and leave |app| running.
|
* Turn on the Content Server in |app|'s preferences and leave |app| running.
|
||||||
* In the Stanza reader on your iPhone, add a new catalog. The URL of the catalog is of the form
|
* Now you should be able to access your books on your iPhone. If not, try the following:
|
||||||
|
In the Stanza reader on your iPhone, add a new catalog. The URL of the catalog is of the form
|
||||||
``http://10.34.56.89:8080/stanza``, where you should replace the IP address ``10.34.56.89``
|
``http://10.34.56.89:8080/stanza``, where you should replace the IP address ``10.34.56.89``
|
||||||
with the IP address of your computer. Stanza will the use the |app| content server to access all the
|
with the IP address of your computer. Stanza will the use the |app| content server to access all the
|
||||||
EPUB books in your |app| database.
|
EPUB books in your |app| database.
|
||||||
|
|
||||||
A more detailed guide is available `here <http://www.mobileread.com/forums/showthread.php?p=391919#post391919>`_
|
|
||||||
|
|
||||||
Library Management
|
Library Management
|
||||||
------------------
|
------------------
|
||||||
|
1574
src/calibre/utils/Zeroconf.py
Executable file
1574
src/calibre/utils/Zeroconf.py
Executable file
File diff suppressed because it is too large
Load Diff
90
src/calibre/utils/mdns.py
Normal file
90
src/calibre/utils/mdns.py
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
from __future__ import with_statement
|
||||||
|
__license__ = 'GPL 3'
|
||||||
|
__copyright__ = '2009, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import socket
|
||||||
|
|
||||||
|
_server = None
|
||||||
|
|
||||||
|
def get_external_ip():
|
||||||
|
'Get IP address of interface used to connect to the outside world'
|
||||||
|
try:
|
||||||
|
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||||
|
s.connect(('google.com', 0))
|
||||||
|
return s.getsockname()[0]
|
||||||
|
except:
|
||||||
|
return '127.0.0.1'
|
||||||
|
|
||||||
|
def start_server():
|
||||||
|
global _server
|
||||||
|
if _server is None:
|
||||||
|
from calibre.utils.Zeroconf import Zeroconf
|
||||||
|
_server = Zeroconf()
|
||||||
|
return _server
|
||||||
|
|
||||||
|
def publish(desc, type, port, properties=None, add_hostname=True):
|
||||||
|
'''
|
||||||
|
Publish a service.
|
||||||
|
|
||||||
|
:param desc: Description of service
|
||||||
|
:param type: Name and type of service. For example _stanza._tcp
|
||||||
|
:param port: Port the service listens on
|
||||||
|
:param properties: An optional dictionary whose keys and values will be put
|
||||||
|
into the TXT record.
|
||||||
|
'''
|
||||||
|
server = start_server()
|
||||||
|
hostname = socket.gethostname()
|
||||||
|
if add_hostname:
|
||||||
|
desc += ' (on %s)'%hostname
|
||||||
|
local_ip = get_external_ip()
|
||||||
|
type = type+'.local.'
|
||||||
|
from calibre.utils.Zeroconf import ServiceInfo
|
||||||
|
service = ServiceInfo(type, desc+'.'+type,
|
||||||
|
address=socket.inet_aton(local_ip),
|
||||||
|
port=port,
|
||||||
|
properties=properties,
|
||||||
|
server=hostname+'.local.')
|
||||||
|
server.registerService(service)
|
||||||
|
|
||||||
|
def stop_server():
|
||||||
|
global _server
|
||||||
|
if _server is not None:
|
||||||
|
_server.close()
|
||||||
|
|
||||||
|
'''
|
||||||
|
class Publish(object):
|
||||||
|
|
||||||
|
def __init__(self, desc, name, port, txt=''):
|
||||||
|
self.desc = desc
|
||||||
|
self.name = name
|
||||||
|
self.port = port
|
||||||
|
self.txt = txt
|
||||||
|
|
||||||
|
def start(self):
|
||||||
|
if iswindows:
|
||||||
|
return
|
||||||
|
if isosx:
|
||||||
|
args = ['dns-sd', self.desc, self.name, '.', self.port]
|
||||||
|
else:
|
||||||
|
args = ['avahi-publish-service', self.desc, self.name, self.port]
|
||||||
|
if self.txt:
|
||||||
|
args.append(self.txt)
|
||||||
|
|
||||||
|
self.process = subprocess.Popen(args)
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
if iswindows:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
process = getattr(self, 'process', None)
|
||||||
|
if process is not None:
|
||||||
|
process.poll()
|
||||||
|
if process.returncode is not None:
|
||||||
|
process.terminate()
|
||||||
|
process.poll()
|
||||||
|
if process.returncode is not None:
|
||||||
|
process.kill()
|
||||||
|
|
||||||
|
def publish(desc, name, port, txt):
|
||||||
|
'''
|
Loading…
x
Reference in New Issue
Block a user