fnp
/
librarian.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
c5ed685
)
add vimeo
author
Jan Szejko
<janek37@gmail.com>
Wed, 5 Dec 2018 14:11:23 +0000
(15:11 +0100)
committer
Jan Szejko
<janek37@gmail.com>
Wed, 5 Dec 2018 14:11:23 +0000
(15:11 +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
a0d70e7
..
c9db26f
100644
(file)
--- a/
librarian/__init__.py
+++ b/
librarian/__init__.py
@@
-8,6
+8,18
@@
import urllib
from .utils import XMLNamespace
from .utils import XMLNamespace
+VIDEO_PROVIDERS = {
+ 'youtube': {
+ 'url': 'https://www.youtube.com/watch?v=%s',
+ 'embed': '//www.youtube.com/embed/%s?controls=2&rel=0&showinfo=0&theme=light',
+ },
+ 'vimeo': {
+ 'url': 'https://vimeo.com/%s',
+ 'embed': '//player.vimeo.com/video/%s',
+ },
+}
+
+
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
36891be
..
4e2e6e5
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
+from librarian import OPFNS, NCXNS, XHTMLNS, DCNS, BuildError
, VIDEO_PROVIDERS
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 =
'https://www.youtube.com/watch?v=%s'
% element.attrib.get('videoid', '')
+ src =
VIDEO_PROVIDERS[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
e1825a5
..
064eba7
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
+from librarian import core
, VIDEO_PROVIDERS
class HtmlFormat(Format):
class HtmlFormat(Format):
@@
-191,11
+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', '')
video_id = element.attrib.get('videoid', '')
attribs = {
'width': '854',
'height': '480',
video_id = element.attrib.get('videoid', '')
attribs = {
'width': '854',
'height': '480',
- 'src':
'//www.youtube.com/embed/%s?controls=2&rel=0&showinfo=0&theme=light'
% video_id,
+ 'src':
VIDEO_PROVIDERS[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
8bb68b0
..
de45fb8
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
+from librarian import DCNS, XMLNamespace, BuildError
, VIDEO_PROVIDERS
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 =
'https://www.youtube.com/watch?v=%s' % element.attrib.get('videoid
')
+ url =
VIDEO_PROVIDERS[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)