-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from openzim/handle_videos_iframes
Handle videos iframes and add visual indicator of external links
- Loading branch information
Showing
9 changed files
with
193 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import requests | ||
|
||
from mindtouch2zim.constants import ( | ||
HTTP_TIMEOUT_NORMAL_SECONDS, | ||
logger, | ||
) | ||
|
||
|
||
class VimeoThumbnailError(Exception): | ||
"""Error raised when there is a problem with a vimeo video""" | ||
|
||
pass | ||
|
||
|
||
def get_vimeo_thumbnail_url(video_url: str) -> str: | ||
"""From a vimeo URL - player or normal - retrieve corresponding thumbnail URL""" | ||
resp = requests.get( | ||
f"https://vimeo.com/api/oembed.json?url={video_url}", | ||
timeout=HTTP_TIMEOUT_NORMAL_SECONDS, | ||
) | ||
resp.raise_for_status() | ||
json_doc = resp.json() | ||
if "thumbnail_url" not in json_doc: | ||
logger.warning(f"Failed to find thumbnail_url in response:\n{resp.text}") | ||
raise VimeoThumbnailError("API response misses the thumbnail_url") | ||
thumbnail_url = json_doc["thumbnail_url"] | ||
if not thumbnail_url: | ||
logger.warning(f"Emtpy thumbnail_url in response:\n{resp.text}") | ||
raise VimeoThumbnailError("API response has empty thumbnail_url") | ||
return thumbnail_url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
a[href^="http://"]:after, | ||
a[href^="https://"]:after | ||
{ | ||
content: ''; | ||
display: inline-block; | ||
width: 10px; | ||
height: 10px; | ||
background-image: url('external-link.svg'); | ||
background-size: contain; | ||
background-repeat: no-repeat; | ||
margin-left: 5px; | ||
position: relative; | ||
bottom: 0px; | ||
right: 0px; | ||
} | ||
|
||
.zim-removed-video { | ||
position: relative; | ||
display: inline-block; | ||
width: 100%; | ||
height: auto; | ||
} | ||
|
||
.zim-removed-video::before { | ||
content: ''; | ||
position: absolute; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-image: url('play-button.svg'); | ||
background-repeat: no-repeat; | ||
background-position: center; | ||
background-size: 30%; | ||
} | ||
|
||
.zim-removed-video img { | ||
width: 100%; | ||
height: auto; | ||
display: block; | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.