def get_continue_media(): database = Database() viewed = database.select_viewed() for item in viewed: try: media_id = int(item.get("id")) info = database.select_media(media_id) except Exception: continue if not info: return info["id"] = media_id info["elapsed"] = int(item.get("elapsed") or 0) category = info.get("category").lower() if category in ["film", "television"]: if info["elapsed"] > 0: return info if category == "television": previous, next = get_nearby_episodes(media_id) if next: info = database.select_media(next) info["id"] = next info["elapsed"] = 0 return info
def media(media_id): if media_id == "disc": item = { "category": media_id } else: media_id = int(media_id) database = Database() item = database.select_media(media_id) if item["category"].lower() == "television": item["season"] = str(item["name_two"]).zfill(2) item["episode"] = str(item["name_three"]).zfill(2) item["previous"], item["next"] = retrieve.get_nearby_episodes(media_id) data = database.select_viewed(media_id) if data: item["viewed"] = retrieve.get_viewed_date(data["viewed"]) item["elapsed"] = data["elapsed"] queue = True if retrieve.get_playing_snakes() else False return flask.render_template("media.html", page="media", item=item, queue=queue)
def update_viewed(media_id, elapsed=None, delete=False): try: database = Database() try: info = database.select_media(int(media_id)) except Exception: info = {} if info.get("category") in config.getlist("viewed", "no_history"): return "0" if elapsed: database.update_viewed(media_id, elapsed) elif delete: database.delete_viewed(media_id) else: database.insert_viewed(media_id) return "0" except Exception as excp: log.error("Update viewed failed: %s", excp) return "1"