|
|
|
@ -59,9 +59,6 @@ from entertainment_decider.models import (
|
|
|
|
|
setup_custom_tables,
|
|
|
|
|
update_element_lookup_cache,
|
|
|
|
|
)
|
|
|
|
|
from entertainment_decider.models.sql_helpers import (
|
|
|
|
|
sql_condition_join,
|
|
|
|
|
)
|
|
|
|
|
from entertainment_decider.preferences import PreferenceScore, generate_preference_list
|
|
|
|
|
from entertainment_decider.extractors.collection import (
|
|
|
|
|
collection_extract_uri,
|
|
|
|
@ -443,10 +440,18 @@ def show_collection(collection_id: int) -> ResponseReturnValue:
|
|
|
|
|
collection: MediaCollection = MediaCollection.get(id=collection_id)
|
|
|
|
|
if collection is None:
|
|
|
|
|
return make_response(f"Not found", 404)
|
|
|
|
|
media_links = None
|
|
|
|
|
media_titles = None
|
|
|
|
|
if orm.count(collection.media_links) <= SMALL_COLLECTION_MAX_COUNT:
|
|
|
|
|
media_links, media_titles = prepare_collection_episodes(collection)
|
|
|
|
|
media_links = (
|
|
|
|
|
MediaCollectionLink.sorted(
|
|
|
|
|
MediaCollectionLink.select(lambda l: l.collection == collection)
|
|
|
|
|
)
|
|
|
|
|
if orm.count(collection.media_links) <= SMALL_COLLECTION_MAX_COUNT
|
|
|
|
|
else None
|
|
|
|
|
)
|
|
|
|
|
media_titles = (
|
|
|
|
|
remove_common_trails([link.element.title for link in media_links])
|
|
|
|
|
if media_links is not None
|
|
|
|
|
else None
|
|
|
|
|
)
|
|
|
|
|
return render_template(
|
|
|
|
|
"collection_element.htm",
|
|
|
|
|
collection=collection,
|
|
|
|
@ -460,7 +465,10 @@ def show_collection_episodes(collection_id: int) -> ResponseReturnValue:
|
|
|
|
|
collection: MediaCollection = MediaCollection.get(id=collection_id)
|
|
|
|
|
if collection is None:
|
|
|
|
|
return make_response(f"Not found", 404)
|
|
|
|
|
media_links, media_titles = prepare_collection_episodes(collection)
|
|
|
|
|
media_links = MediaCollectionLink.sorted(
|
|
|
|
|
MediaCollectionLink.select(lambda l: l.collection == collection)
|
|
|
|
|
)
|
|
|
|
|
media_titles = remove_common_trails([link.element.title for link in media_links])
|
|
|
|
|
return render_template(
|
|
|
|
|
"collection_episodes.htm",
|
|
|
|
|
collection=collection,
|
|
|
|
@ -469,28 +477,43 @@ def show_collection_episodes(collection_id: int) -> ResponseReturnValue:
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_collection_episodes(
|
|
|
|
|
collection: MediaCollection,
|
|
|
|
|
) -> tuple[Iterable[MediaCollectionLink], Iterable[str]]:
|
|
|
|
|
media_links = MediaCollectionLink.select(
|
|
|
|
|
lambda l: l.collection == collection
|
|
|
|
|
).order_by(
|
|
|
|
|
MediaCollectionLink.desc_sort_key
|
|
|
|
|
if collection.is_creator
|
|
|
|
|
else MediaCollectionLink.sort_key
|
|
|
|
|
)
|
|
|
|
|
media_titles = remove_common_trails([link.element.title for link in media_links])
|
|
|
|
|
return media_links, media_titles
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@flask_app.route("/media")
|
|
|
|
|
def list_media() -> ResponseReturnValue:
|
|
|
|
|
media_list = prepare_media_sql()
|
|
|
|
|
media_list: Iterable[MediaElement] = get_all_considered(
|
|
|
|
|
"elem.release_date DESC, elem.id"
|
|
|
|
|
)
|
|
|
|
|
return render_template(
|
|
|
|
|
"media_list.htm",
|
|
|
|
|
media_list=common.limit_iter(media_list, 100),
|
|
|
|
|
check_considered=False,
|
|
|
|
|
**pass_media_filter_vals(),
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@flask_app.route("/media/short")
|
|
|
|
|
@flask_app.route("/media/short/<int:seconds>")
|
|
|
|
|
def list_short_media(seconds: int = 10 * 60) -> ResponseReturnValue:
|
|
|
|
|
media_list: Iterable[MediaElement] = get_all_considered(
|
|
|
|
|
filter_by=f"(length - progress) <= {seconds}",
|
|
|
|
|
order_by="elem.release_date DESC, elem.id",
|
|
|
|
|
)
|
|
|
|
|
return render_template(
|
|
|
|
|
"media_list.htm",
|
|
|
|
|
media_list=list(itertools.islice(media_list, 100)),
|
|
|
|
|
check_considered=False,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@flask_app.route("/media/long")
|
|
|
|
|
@flask_app.route("/media/long/<int:seconds>")
|
|
|
|
|
def list_long_media(seconds: int = 10 * 60) -> ResponseReturnValue:
|
|
|
|
|
media_list: Iterable[MediaElement] = get_all_considered(
|
|
|
|
|
filter_by=f"{seconds} <= (length - progress)",
|
|
|
|
|
order_by="elem.release_date DESC, elem.id",
|
|
|
|
|
)
|
|
|
|
|
return render_template(
|
|
|
|
|
"media_list.htm",
|
|
|
|
|
media_list=list(itertools.islice(media_list, 100)),
|
|
|
|
|
check_considered=False,
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -527,33 +550,6 @@ def list_unsorted_media() -> ResponseReturnValue:
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def prepare_media_sql(
|
|
|
|
|
filter_by: str | None = None,
|
|
|
|
|
) -> Sequence[MediaElement]:
|
|
|
|
|
elem_len = "(elem.length - elem.progress)"
|
|
|
|
|
min_len = request.args.get("min_length", default=None, type=int)
|
|
|
|
|
max_len = request.args.get("max_length", default=None, type=int)
|
|
|
|
|
filter_str = sql_condition_join(
|
|
|
|
|
filter_by,
|
|
|
|
|
f"{min_len * 60} <= {elem_len}" if min_len else None,
|
|
|
|
|
f"{elem_len} <= {max_len * 60}" if max_len else None,
|
|
|
|
|
)
|
|
|
|
|
return get_all_considered(
|
|
|
|
|
filter_by=filter_str,
|
|
|
|
|
order_by="elem.release_date DESC, elem.id",
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def pass_media_filter_vals() -> Mapping[str, Any]:
|
|
|
|
|
KEYS = [
|
|
|
|
|
"min_length",
|
|
|
|
|
"max_length",
|
|
|
|
|
]
|
|
|
|
|
return {
|
|
|
|
|
"show_filters": True,
|
|
|
|
|
} | {key: request.args.get(key) for key in KEYS}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@flask_app.route("/media/extract")
|
|
|
|
|
def extract_media() -> ResponseReturnValue:
|
|
|
|
|
return render_template("media_extract.htm")
|
|
|
|
@ -783,7 +779,11 @@ def refresh_collections() -> ResponseReturnValue:
|
|
|
|
|
orm.rollback()
|
|
|
|
|
errors.append(
|
|
|
|
|
{
|
|
|
|
|
"collection": coll.json_summary,
|
|
|
|
|
"collection": {
|
|
|
|
|
"id": coll.id,
|
|
|
|
|
"title": coll.title,
|
|
|
|
|
"uri": coll.primary_uri,
|
|
|
|
|
},
|
|
|
|
|
"error": gen_api_error(e),
|
|
|
|
|
},
|
|
|
|
|
)
|
|
|
|
@ -807,25 +807,7 @@ def force_refresh_collection(collection_id: int) -> ResponseReturnValue:
|
|
|
|
|
coll: MediaCollection = MediaCollection.get(id=collection_id)
|
|
|
|
|
if coll is None:
|
|
|
|
|
return "404 Not Found", 404
|
|
|
|
|
try:
|
|
|
|
|
state = collection_update(coll, check_cache_expired=False)
|
|
|
|
|
except Exception as e:
|
|
|
|
|
orm.rollback()
|
|
|
|
|
return (
|
|
|
|
|
{
|
|
|
|
|
"status": False,
|
|
|
|
|
"error": {
|
|
|
|
|
"msg": "Failed to update collection successfully",
|
|
|
|
|
"data": [
|
|
|
|
|
{
|
|
|
|
|
"collection": coll.json_summary,
|
|
|
|
|
"error": gen_api_error(e),
|
|
|
|
|
}
|
|
|
|
|
],
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
501,
|
|
|
|
|
)
|
|
|
|
|
state = collection_update(coll, check_cache_expired=False)
|
|
|
|
|
if state.may_has_changed:
|
|
|
|
|
update_element_lookup_cache((coll.id,))
|
|
|
|
|
return redirect_back_or_okay()
|
|
|
|
|