Implement downloading pictures to local cache and opening them from there.

sqlite
VikingKong 3 years ago
parent 2564246126
commit 9a2af39be7

@ -7,6 +7,7 @@ from concurrent.futures import ThreadPoolExecutor
from API import Fetcher
from Cache import Cache
from Render import Render
from FileCache import FileCache
import Utils
warnings.filterwarnings("ignore")
@ -359,9 +360,12 @@ class Links(urwid.ListBox):
self.body = walker
def parseLink(self, link):
ext = link.split(".")[-1]
if Utils.checkPic(ext.lower()):
os.system('nohup feh ' + link + ' </dev/null >/dev/null 2>&1 &')
ext = Utils.checkPic(link.split(".")[-1]).lower()
if ext:
fc = FileCache(link, ext)
fp = fc.fetch()
if fp is not None:
os.system('nohup feh ' + fp + ' </dev/null >/dev/null 2>&1 &')
elif Utils.checkStreamingVideo(link):
tui.destroyOverlay()
os.system(

@ -0,0 +1,29 @@
import httpx
import os
import Utils
import hashlib
class FileCache:
def __init__(self, link, ext):
self.link = link
path = os.path.expanduser("~") + "/.config/inomnibus/file_cache/"
h = hashlib.sha1()
h.update(self.link.encode())
self.file_path = path + h.hexdigest() + "." + ext
def download(self):
try:
file = httpx.get(self.link, follow_redirects=True)
open(self.file_path, "wb").write(file.content)
return self.file_path
except BaseException as e:
Utils.writeLog(str(e))
return None
def fetch(self):
if os.path.isfile(self.file_path):
return self.file_path
else:
return self.download()

@ -12,7 +12,7 @@ def timestampToDate(ts):
def checkPic(ext):
for p in pics:
if re.search(p, ext) is not None:
return True
return p[1:p.find("\\")]
return False

Loading…
Cancel
Save