Skip to content

Commit 0664e22

Browse files
author
Khaled Monsoor
committed
fix version issue, Youtube size issue
1 parent a1a71fb commit 0664e22

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
lines changed

embedx/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
from .embedx import OnlineContent
2+
from .version import __version__
23

34

embedx/embedx.py

Lines changed: 45 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,23 @@ class OnlineContent(object):
1515
Object to represent a single content on Internet which can be accessed through a link.
1616
After initiating the `OnlineContent` object using its URL, embeddable code can be generated.
1717
Embeddable code generation is offline, by default.
18-
However, by using oEmbed protocol, it can be generated from the host site using its own API.
18+
19+
However, by using oEmbed protocol, it can be generated from the host site using its own API. (Experimental)
20+
In some cases, e.g. Flickr images, embed code must be generated online.
1921
2022
>>> from embedx import OnlineContent
2123
>>> content = OnlineContent('http://www.youtube.com/watch?v=_lOT2p_FCvA')
22-
>>> content.extract_id()
24+
>>> content.get_content_uid()
2325
'_lOT2p_FCvA'
2426
>>> content.get_embed_code()
25-
"<div class='embed-container'><iframe src='http://www.youtube.com/embed/_lOT2p_FCvA' 'frameborder='0'allowfullscreen></iframe></div>"
26-
27-
>>> content = OnlineContent('https://twitter.com/codinghorror/status/686254714938200064')
28-
>>> content.extract_id()
29-
'686254714938200064'
30-
>>> content.get_embed_code()
31-
"<div id='embedx-twt' align='center'></div><script async src='https://platform.twitter.com/widgets.js'></script><script> window.onload=(function(){twttr.widgets.createTweet(686254714938200064, document.getElementById('embedx-twt'),{});});</script>"
32-
33-
"""
27+
"<div class='embedx-yt'><iframe src='http://www.youtube.com/embed/_lOT2p_FCvA' 'frameborder='0' allowfullscreen></iframe></div>"
28+
>>> content.check_if_alive()
29+
True
30+
"""
3431

3532
# pointer to current `OnlineContent` object
3633
instance = None
37-
38-
# these templates must be defined by providing subclasses
34+
# these templates must be defined by implementor subclasses
3935
hostnames = []
4036
EMBED_SCRIPT = ""
4137
STATUS_LINK = "" # it is needed for hosts which generate HTTP:200 even if CONTENT_ID is invalid e.g. Youtube
@@ -65,6 +61,7 @@ def get_embed_code(self):
6561
return self.instance.EMBED_SCRIPT % ({'content_uid': self.get_content_uid()})
6662
elif len(self.instance.OEMBED_LINK):
6763
oembed_req_url = self.instance.EMBED_SCRIPT % ({'URL': self.instance.url})
64+
return oembed_req_url
6865
else:
6966
raise NotImplementedError
7067

@@ -109,10 +106,16 @@ def check_if_alive(self):
109106

110107

111108
class YouTube(OnlineContent):
109+
""" Use `OnlineContent` object to instatiate or use this class
110+
111+
>>> from embedx import OnlineContent
112+
>>> content = OnlineContent('http://www.youtube.com/watch?v=_lOT2p_FCvA')
113+
>>> content.get_content_uid()
114+
'_lOT2p_FCvA'
115+
"""
116+
112117
hostnames = ['youtube', 'youtu.be']
113-
EMBED_SCRIPT = ("<div class='embedx-yt'>"
114-
"<iframe src='http://www.youtube.com/embed/%(content_uid)s' 'frameborder='0' allowfullscreen>"
115-
"</iframe></div>")
118+
EMBED_SCRIPT = '''<iframe id="embedx-yt" type="text/html" width="640" height="390" position="center" src="http://www.youtube.com/embed/%(content_uid)s" frameborder="0"/>'''
116119
STATUS_LINK = '''http://www.youtube.com/oembed?url=http://www.youtube.com/watch?v=%(content_uid)s&format=json'''
117120
LINK_TEMPLATE = '''https://www.youtube.com/watch?v=%(content_uid)s'''
118121

@@ -137,10 +140,17 @@ def extract_id(self):
137140
elif 'youtu.be' in parsed_url.hostname:
138141
return parsed_url.path[1:]
139142
else:
140-
raise ValueError
143+
raise ValueError("Invalid URL for a Youtube video")
141144

142145

143146
class Vimeo(OnlineContent):
147+
"""Use `OnlineContent` object to instatiate or use this class
148+
149+
>>> from embedx import OnlineContent
150+
>>> vimeo = OnlineContent('https://vimeo.com/92129360')
151+
>>> vimeo.get_embed_code()
152+
"<div class='embedx-vm'><iframe src='http://player.vimeo.com/video/92129360' frameborder='0' webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe></div>"
153+
"""
144154
hostnames = ['vimeo', ]
145155

146156
LINK_TEMPLATE = '''https://vimeo.com/%(content_uid)s'''
@@ -161,8 +171,16 @@ def extract_id(self):
161171

162172

163173
class Twitter(OnlineContent):
164-
hostnames = ['twitter', ]
174+
"""Use `OnlineContent` object to instatiate or use this class
175+
176+
>>> from embedx import OnlineContent
177+
>>> twit = OnlineContent('https://twitter.com/jack/status/20')
178+
>>> twit.get_embed_code()
179+
"<div id='embedx-twt' align='center'></div><script async src='https://platform.twitter.com/widgets.js'></script><script> window.onload=(function(){twttr.widgets.createTweet('20', document.getElementById('embedx-twt'),{});});</script>"
180+
181+
"""
165182

183+
hostnames = ['twitter', ]
166184
EMBED_SCRIPT = ("<div id='embedx-twt' align='center'></div>"
167185
"<script async src='https://platform.twitter.com/widgets.js'></script>"
168186
"<script> window.onload=(function(){twttr.widgets.createTweet('%(content_uid)s',"
@@ -179,11 +197,15 @@ def extract_id(self):
179197

180198

181199
class Github(OnlineContent):
200+
"""Use `OnlineContent` object to instatiate or use this class
201+
202+
>>> from embedx import OnlineContent
203+
>>> gist = OnlineContent('https://gist.github.com/kmonsoor/2a1afba4ee127cce50a0')
204+
>>> gist.get_embed_code()
205+
"<script src='https://gist.github.com/2a1afba4ee127cce50a0.js'></script>"
182206
"""
183-
Generate embed script for Github gist
184-
"""
185-
hostnames = ['github', ]
186207

208+
hostnames = ['github', ]
187209
EMBED_SCRIPT = "<script src='https://gist.github.com/%(content_uid)s.js'></script>"
188210

189211
def __init__(self, url):
@@ -199,7 +221,6 @@ def extract_id(self):
199221
class Flickr(OnlineContent):
200222
hostnames = ['flickr', ]
201223

202-
# EMBED_SCRIPT = ""
203224
OEMBED_LINK = "https://www.flickr.com/services/oembed/?url=%(URL)s&format=json"
204225

205226
def extract_id(self):
@@ -216,6 +237,7 @@ def extract_id(self):
216237
raise NotImplementedError
217238

218239

240+
# for quick overview testing
219241
if __name__ == '__main__':
220242
test_urls = ['https://twitter.com/thepodcastdude/status/686258030229336064',
221243
'youtube.com/watch?v=_lOT2p_FCvA',
@@ -227,7 +249,7 @@ def extract_id(self):
227249
try:
228250
ov = OnlineContent(a_url)
229251
print(ov.get_content_uid())
230-
# print ov.check_if_alive()
252+
# print(ov.check_if_alive())
231253
print(ov.get_embed_code())
232254
except NotImplementedError:
233255
pass

embedx/version.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__version__ = '0.0.6'
2+

setup.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,26 @@
1-
from setuptools import setup, find_packages
21
from codecs import open
32
from os import path
43

4+
from setuptools import setup, find_packages
5+
6+
# bringing in __version__ data
7+
exec(open('embedx/version.py').read())
8+
59
# Load the README.md to `long_description`
6-
here = path.abspath(path.dirname(__file__))
710
try:
811
from pypandoc import convert
12+
913
long_description = convert('README.md', 'rst')
1014
except(OSError, IOError, ImportError):
15+
here = path.abspath(path.dirname(__file__))
1116
with open(path.join(here, 'README.md'), encoding='utf-8') as f:
1217
long_description = f.read()
1318

19+
# finally
1420
setup(
1521
name='embedx',
1622
packages=find_packages(),
17-
version='0.0.4',
23+
version=__version__,
1824
url='https://github.com/kmonsoor/embedX',
1925
license='MIT',
2026
author='Khaled Monsoor',
@@ -26,7 +32,8 @@
2632
install_requires=[],
2733
classifiers=[
2834
'Development Status :: 3 - Alpha',
29-
'Programming Language :: Python',
35+
'Programming Language :: Python :: 2',
36+
'Programming Language :: Python :: 3',
3037
'Environment :: Console',
3138
'Environment :: Web Environment',
3239
'Intended Audience :: Developers',

0 commit comments

Comments
 (0)