1
0
mirror of https://gitlab.crans.org/mediatek/med.git synced 2025-07-07 07:04:00 +02:00

Split comic strips and mangas

This commit is contained in:
Yohann D'ANELLO
2020-05-21 16:56:41 +02:00
parent 1657f5c42c
commit 82efeba272
10 changed files with 202 additions and 12 deletions

View File

@ -10,7 +10,7 @@ import urllib.request
from django.forms import ModelForm
from django.utils.translation import gettext_lazy as _
from .models import Auteur
from .models import Auteur, Media
from .scraper import BedetequeScraper
@ -54,7 +54,6 @@ class MediaAdminForm(ModelForm):
return False
def parse_data_google(self, data):
print(data)
info = data['volumeInfo']
self.cleaned_data['external_url'] = info['canonicalVolumeLink']
if 'title' in info:
@ -71,7 +70,7 @@ class MediaAdminForm(ModelForm):
if 'publishedDate' in info:
self.cleaned_data['publish_date'] = info['publishedDate']
if 'authors' not in self.cleaned_data:
if 'authors' not in self.cleaned_data or not self.cleaned_data['authors']:
self.cleaned_data['authors'] = list()
if 'authors' in info:
@ -144,7 +143,7 @@ class MediaAdminForm(ModelForm):
.format(split[2], months.index(split[0])
+ 1, int(split[1]), )
if 'authors' not in self.cleaned_data:
if 'authors' not in self.cleaned_data or not self.cleaned_data['authors']:
self.cleaned_data['authors'] = list()
if 'authors' in data:
@ -159,17 +158,17 @@ class MediaAdminForm(ModelForm):
"""
super().clean()
if "_isbn" in self.request.POST\
or "_isbn_addanother" in self.request.POST:
if "_isbn" in self.data\
or "_isbn_addanother" in self.data:
isbn = self.cleaned_data.get('isbn')
if "_isbn_addanother" in self.request.POST:
self.request.POST = self.request.POST.copy()
self.request.POST['_addanother'] = 42
if "_isbn_addanother" in self.data:
self.data = self.data.copy()
self.data['_addanother'] = 42
if isbn:
# ISBN is present, try with bedeteque
scrap_result = self.download_data_bedeteque(isbn)
if not scrap_result:
# Try with Fnac
# Try with Google
scrap_result = self.download_data_google(isbn)
if not scrap_result:
# Try with OpenLibrary
@ -251,7 +250,7 @@ class MediaAdminForm(ModelForm):
from django.core.exceptions import ValidationError
try:
# We don't want to check a field when we enter an ISBN.
if "isbn" not in self.request.POST \
if "isbn" not in self.data \
or not self.cleaned_data.get('isbn'):
value = field.clean(value)
self.cleaned_data[name] = value
@ -260,3 +259,7 @@ class MediaAdminForm(ModelForm):
self.cleaned_data[name] = value
except ValidationError as e:
self.add_error(name, e)
class Meta:
model = Media
fields = '__all__'