fnp
/
librarian.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ea9a4ee
)
fix video
xml2
author
Jan Szejko
<janek37@gmail.com>
Mon, 10 Dec 2018 08:31:05 +0000
(09:31 +0100)
committer
Jan Szejko
<janek37@gmail.com>
Mon, 10 Dec 2018 08:31:05 +0000
(09:31 +0100)
librarian/__init__.py
patch
|
blob
|
history
librarian/formats/epub/__init__.py
patch
|
blob
|
history
librarian/formats/html/__init__.py
patch
|
blob
|
history
librarian/formats/pdf/__init__.py
patch
|
blob
|
history
diff --git
a/librarian/__init__.py
b/librarian/__init__.py
index
c9db26f
..
ec1d688
100644
(file)
--- a/
librarian/__init__.py
+++ b/
librarian/__init__.py
@@
-20,6
+20,10
@@
VIDEO_PROVIDERS = {
}
}
+def get_provider(provider_id):
+ return VIDEO_PROVIDERS.get(provider_id, VIDEO_PROVIDERS['youtube'])
+
+
class UnicodeException(Exception):
def __str__(self):
""" Dirty workaround for Python Unicode handling problems. """
class UnicodeException(Exception):
def __str__(self):
""" Dirty workaround for Python Unicode handling problems. """
diff --git
a/librarian/formats/epub/__init__.py
b/librarian/formats/epub/__init__.py
index
4e2e6e5
..
3ff7015
100644
(file)
--- a/
librarian/formats/epub/__init__.py
+++ b/
librarian/formats/epub/__init__.py
@@
-13,7
+13,7
@@
import zipfile
from urllib2 import urlopen
from lxml import etree
from urllib2 import urlopen
from lxml import etree
-from librarian import OPFNS, NCXNS, XHTMLNS, DCNS, BuildError,
VIDEO_PROVIDERS
+from librarian import OPFNS, NCXNS, XHTMLNS, DCNS, BuildError,
get_provider
from librarian import core
from librarian.formats import Format
from librarian.formats.cover.evens import EvensCover
from librarian import core
from librarian.formats import Format
from librarian.formats.cover.evens import EvensCover
@@
-360,7
+360,7
@@
EpubFormat.renderers.register(core.Div, 'img', DivImageR('img'))
class DivVideoR(Silent):
def render(self, element, ctx):
class DivVideoR(Silent):
def render(self, element, ctx):
- src =
VIDEO_PROVIDERS[element.attrib.get('provider')]
['url'] % element.attrib.get('videoid', '')
+ src =
get_provider(element.attrib.get('provider'))
['url'] % element.attrib.get('videoid', '')
return super(DivVideoR, self).render(element, Context(ctx, src=src))
def container(self, ctx):
return super(DivVideoR, self).render(element, Context(ctx, src=src))
def container(self, ctx):
diff --git
a/librarian/formats/html/__init__.py
b/librarian/formats/html/__init__.py
index
064eba7
..
271fac9
100644
(file)
--- a/
librarian/formats/html/__init__.py
+++ b/
librarian/formats/html/__init__.py
@@
-9,7
+9,7
@@
from librarian.formats import Format
from librarian.output import OutputFile
from librarian.renderers import Register, TreeRenderer
from librarian.utils import Context, get_resource
from librarian.output import OutputFile
from librarian.renderers import Register, TreeRenderer
from librarian.utils import Context, get_resource
-from librarian import core,
VIDEO_PROVIDERS
+from librarian import core,
get_provider
class HtmlFormat(Format):
class HtmlFormat(Format):
@@
-191,12
+191,12
@@
HtmlFormat.renderers.register(core.Div, 'img', DivImage('img'))
class DivVideo(NaturalText):
def render(self, element, ctx):
output = super(DivVideo, self).render(element, ctx)
class DivVideo(NaturalText):
def render(self, element, ctx):
output = super(DivVideo, self).render(element, ctx)
- provider =
element.attrib.get('provider', ''
)
+ provider =
get_provider(element.attrib.get('provider')
)
video_id = element.attrib.get('videoid', '')
attribs = {
'width': '854',
'height': '480',
video_id = element.attrib.get('videoid', '')
attribs = {
'width': '854',
'height': '480',
- 'src':
VIDEO_PROVIDERS[provider]
['embed'] % video_id,
+ 'src':
provider
['embed'] % video_id,
'frameborder': '0',
'allowfullscreen': '',
}
'frameborder': '0',
'allowfullscreen': '',
}
diff --git
a/librarian/formats/pdf/__init__.py
b/librarian/formats/pdf/__init__.py
index
de45fb8
..
2fd744d
100644
(file)
--- a/
librarian/formats/pdf/__init__.py
+++ b/
librarian/formats/pdf/__init__.py
@@
-11,7
+11,7
@@
from lxml import etree
from urllib import urlretrieve
from StringIO import StringIO
from Texml.processor import process
from urllib import urlretrieve
from StringIO import StringIO
from Texml.processor import process
-from librarian import DCNS, XMLNamespace, BuildError,
VIDEO_PROVIDERS
+from librarian import DCNS, XMLNamespace, BuildError,
get_provider
from librarian.formats import Format
from librarian.output import OutputFile
from librarian.renderers import Register, TreeRenderer
from librarian.formats import Format
from librarian.output import OutputFile
from librarian.renderers import Register, TreeRenderer
@@
-316,7
+316,7
@@
PdfFormat.renderers.register(core.Div, 'img', ImgRenderer('insertimage'))
class VideoRenderer(CmdRenderer):
def render(self, element, ctx):
root = super(VideoRenderer, self).render(element, ctx)
class VideoRenderer(CmdRenderer):
def render(self, element, ctx):
root = super(VideoRenderer, self).render(element, ctx)
- url =
VIDEO_PROVIDERS[element.attrib.get('provider')]
['url'] % element.attrib.get('videoid', '')
+ url =
get_provider(element.attrib.get('provider'))
['url'] % element.attrib.get('videoid', '')
link = texml_cmd('href', url, url)
root[0][0].text = None
root[0][0].append(link)
link = texml_cmd('href', url, url)
root[0][0].text = None
root[0][0].append(link)