rewriting url and adding new one if they were not created
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 4s
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from apps.betaserie.utils import betaserieUtils
|
||||
from django.db.models import Count
|
||||
from django.core.exceptions import MultipleObjectsReturned
|
||||
from celery.worker.state import active_requests
|
||||
from requests.compat import str
|
||||
from apps.betaserie.utils import betaserieUtils
|
||||
from .models import simpsons_data_object
|
||||
|
||||
betaserie = betaserieUtils()
|
||||
@@ -35,3 +36,49 @@ def unwatch_all_episodes():
|
||||
for episode in range(1,maximum_number_of_episodes+1):
|
||||
print("S"+str(season)+"E"+str(episode))
|
||||
mark_episode_watched(season,episode,"unwatched")
|
||||
|
||||
|
||||
def generate_new_urls_for_episode(verbose=False):
|
||||
# kisscartoons didn't work anymore so moving to another website with the format:
|
||||
# URL.com/simpsons/season=XX&episode=XX
|
||||
# example
|
||||
# https://www.1shows.org/tv/456-the-simpsons?streaming=true&season=33&episode=18
|
||||
|
||||
simpsons_series_information = betaserie.series_information(simpsons_id)
|
||||
seasons_information = simpsons_series_information[0]
|
||||
|
||||
#for the simpsons, there is a season 0 which increase the count of seasons by 1
|
||||
# we need to remove this entry ,
|
||||
# so we cannot trust the maximum_number_season coming from simpsons_series_information
|
||||
|
||||
season_0_to_remove = seasons_information[0]
|
||||
|
||||
if verbose : print(season_0_to_remove)
|
||||
|
||||
seasons_information.remove(season_0_to_remove)
|
||||
maximum_number_season = len(seasons_information)
|
||||
|
||||
for season in range(1,maximum_number_season+1):
|
||||
# the list doesn't start with season 0 anymore so we cannot use the season number as index
|
||||
# we need to add -1
|
||||
|
||||
number_episodes_in_season = int(seasons_information[season-1]['episodes'])
|
||||
|
||||
for episode in range(1,number_episodes_in_season+1):
|
||||
if verbose : print("Season: "+str(season))
|
||||
if verbose : print("episode: "+str(episode))
|
||||
new_url = "https://www.1shows.org/tv/456-the-simpsons?streaming=true&season="+str(season)+"&episode="+str(episode)
|
||||
|
||||
if verbose : print(new_url)
|
||||
try:
|
||||
obj,created = simpsons_data_object.get_or_create(
|
||||
season=season,
|
||||
episode=episode,
|
||||
defaults={"url":new_url,"seen":"False"}
|
||||
)
|
||||
obj.url=new_url
|
||||
obj.save()
|
||||
except MultipleObjectsReturned:
|
||||
print("duplicated object for season: "+str(episode)+" episode: "+str(episode)+", ignoring")
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user