feat: dont redownload existing epub
This commit is contained in:
@@ -5,12 +5,14 @@ from django.core.paginator import Paginator
|
|||||||
from epub2go.convert import get_all_books, Book, allbooks_url
|
from epub2go.convert import get_all_books, Book, allbooks_url
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import glob
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from epub2go_web.tasks import getEpub
|
from epub2go_web.tasks import getEpub, getDir
|
||||||
|
|
||||||
logger = logging.getLogger(__name__) #TODO configure logging
|
logger = logging.getLogger(__name__) #TODO configure logging
|
||||||
|
logging.basicConfig(level=logging.INFO,format='%(asctime)s - %(levelname)s - %(message)s')
|
||||||
|
|
||||||
books = sorted(get_all_books(), key= lambda b: b.title)# TODO get from pickle
|
books = sorted(get_all_books(), key= lambda b: b.title)# TODO get from pickle
|
||||||
books_count = len(books)
|
books_count = len(books)
|
||||||
@@ -24,6 +26,13 @@ def index(request: HttpRequest):
|
|||||||
searchParam = request.GET.get('s', None)
|
searchParam = request.GET.get('s', None)
|
||||||
if targetParam:
|
if targetParam:
|
||||||
if validateUrl(targetParam):
|
if validateUrl(targetParam):
|
||||||
|
# does an epub already exist?
|
||||||
|
dir_download = getDir(targetParam)
|
||||||
|
listDir = glob.glob('*.epub', root_dir=dir_download)
|
||||||
|
if len(listDir) != 0:
|
||||||
|
fpath = os.path.join(dir_download, listDir[0])
|
||||||
|
logger.info('Found existing file at %s', fpath)
|
||||||
|
else:
|
||||||
# download file
|
# download file
|
||||||
result = getEpub.delay(targetParam)
|
result = getEpub.delay(targetParam)
|
||||||
fpath = result.get(timeout=60)
|
fpath = result.get(timeout=60)
|
||||||
|
|||||||
@@ -9,3 +9,6 @@ converter = GBConvert(downloaddir=settings.MEDIA_ROOT)
|
|||||||
def getEpub(book_url):
|
def getEpub(book_url):
|
||||||
# TODO check for existing file and age
|
# TODO check for existing file and age
|
||||||
return converter.download(book_url)
|
return converter.download(book_url)
|
||||||
|
|
||||||
|
def getDir(book_url):
|
||||||
|
return converter.getDir(book_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user