Commit 14b4e593 authored by Denis Salem's avatar Denis Salem
Browse files

done with oembed

parent e6b94fb1
......@@ -127,7 +127,7 @@
DONE | Allow disabling exportation of specific kind of thread.
DONE | Add categories tree in entry.
DONE | Remove illegal character from path.
WIP | Add support for embed content (oEmbed, OGP)
DONE | Add support for embed content (oEmbed)
TODO | Export entry in nicely named folder instead of permalink
TODO | Client-side search engine.
TODO | Fix unit test.
......
......@@ -17,6 +17,7 @@
# You should have received a copy of the GNU General Public License
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import hashlib
import json
import os
......@@ -283,7 +284,12 @@ class DataStore:
return merge(items, argv)
def cache_embed_exists(self, link):
return ""
cache_filename = hashlib.md5(link.encode('utf-8')).hexdigest()
try:
return open("caches/embed/"+cache_filename,"r").read()
except FileNotFoundError:
return ""
def wrapper_embed_content(self, argv):
cache = self.cache_embed_exists(argv[0])
......
......@@ -17,12 +17,15 @@
# You should have received a copy of the GNU General Public License
# along with VenC. If not, see <http://www.gnu.org/licenses/>.
import hashlib
import json
import os
import requests
from venc2 import venc_version
from venc2.l10n import messages
from venc2.helpers import PatternInvalidArgument
from venc2.helpers import GenericMessage
from venc2.helpers import notify
from urllib.parse import urlparse
def try_oembed(providers, url):
......@@ -45,9 +48,18 @@ def try_oembed(providers, url):
try:
html = json.loads(r.text)["html"]
except Exception as e:
raise GenericMessage(messages.response_is_not_json.format(url.geturl()))
try:
cache_filename = hashlib.md5(url.geturl().encode('utf-8')).hexdigest()
os.makedirs("caches/embed", exist_ok=True)
f = open("caches/embed/"+cache_filename, "w")
f.write(html)
f.close()
except PermissionError:
notify(messages.wrong_permissions.format("caches/embed/"+cache_filename), color="YELLOW")
return html
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment