This commit is contained in:
el Mau 2023-02-13 23:08:53 -06:00
parent ed24e0ea77
commit 0046f9da8d
1 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,8 @@
import random
import time
import re
from pathlib import Path
import wikipediaapi
from bs4 import BeautifulSoup
from django.conf import settings
@ -170,12 +172,12 @@ class MovieQuerySet(models.QuerySet):
movie["duration_formatted"] = self.format_duration(movie["duration"])
movie["count_formatted"] = self.format_count(movie["count"])
movie["stars_icons"] = self.format_stars(movie["stars"])
movie["file_name"] = self.fix_path(movie["file_name"])
movie["cartel"] = f"{settings.MEDIA_URL}{movie['cartel']}"
movie["file_name"] = self._fix_path_movie(movie["file_name"])
movie["cartel"] = self._fix_path_cartel(movie['cartel'])
if wikipedia:
movie["wiki"] = self.get_wiki(movie)
def fix_path(self, file_name):
def _fix_path_movie(self, file_name):
"""
Enmienda ruta a medio.
"""
@ -188,6 +190,17 @@ class MovieQuerySet(models.QuerySet):
url = f"{settings.URL_CDN}/{letter}/{file_name}"
return url
def _fix_path_cartel(self, file_name):
""" Si no existe el cartel regresa el default """
url = f"{settings.MEDIA_URL}{file_name}"
path = Path(f"{settings.MEDIA_ROOT}{file_name}")
if not path.exists():
url = f"{settings.MEDIA_URL}default.png"
return url
def fix_summ(self, raw):
"""
Enmienda sinopsis de Wikipedia.