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 API import Fetcher
from Cache import Cache from Cache import Cache
from Render import Render from Render import Render
from FileCache import FileCache
import Utils import Utils
warnings.filterwarnings("ignore") warnings.filterwarnings("ignore")
@ -359,9 +360,12 @@ class Links(urwid.ListBox):
self.body = walker self.body = walker
def parseLink(self, link): def parseLink(self, link):
ext = link.split(".")[-1] ext = Utils.checkPic(link.split(".")[-1]).lower()
if Utils.checkPic(ext.lower()): if ext:
os.system('nohup feh ' + link + ' </dev/null >/dev/null 2>&1 &') 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): elif Utils.checkStreamingVideo(link):
tui.destroyOverlay() tui.destroyOverlay()
os.system( 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): def checkPic(ext):
for p in pics: for p in pics:
if re.search(p, ext) is not None: if re.search(p, ext) is not None:
return True return p[1:p.find("\\")]
return False return False

Loading…
Cancel
Save