Exemplo n.º 1
0
def view_archive(slug):
    do = DoArchive()
    # TODO instead of json filtering,
    # write actual query
    # joining shows and items
    # so we can limit date etc.
    show_query = Show.query.filter_by(archive_lahmastore_base_url=slug)
    # item_query = Item.query.filter_by(parent_show=)
    show = show_query.first_or_404()
    if show:
        show_json = show_details_schema.dump(show)
        show_items = [
            show_item
            for show_item in show_json["items"]
            if datetime.strptime(show_item.get("play_date"), "%Y-%m-%d")
            + timedelta(days=1)
            < datetime.today()
        ]
        for show_item in show_items:
            show_item["image_url"] = do.download(
                show.archive_lahmastore_base_url, show_item["image_url"]
            )
        return json.dumps(show_items)
    else:
        return make_response("Show not found", 404, headers)
Exemplo n.º 2
0
def download_play_file(id):
    do = DoArchive()
    item_query = Item.query.filter_by(id=id)
    item = item_query.first_or_404()
    presigned = do.download(
        item.shows[0].archive_lahmastore_base_url, item.archive_lahmastore_canonical_url
    )
    return redirect(presigned, code=302)
Exemplo n.º 3
0
def listen_play_file(id):
    do = DoArchive()
    item_query = Item.query.filter_by(id=id)
    item = item_query.first()
    presigned = do.download(
        item.shows[0].archive_lahmastore_base_url, item.archive_lahmastore_canonical_url
    )
    return presigned
Exemplo n.º 4
0
def list_shows():
    do = DoArchive()
    shows = Show.query.all()
    for show in shows:
        if show.cover_image_url:
            show.cover_image_url = do.download(
                show.archive_lahmastore_base_url, show.cover_image_url
            )
    return many_show_details_schema.dumps(shows)
Exemplo n.º 5
0
def list_items():
    do = DoArchive()
    items = Item.query.all()
    for item in items:
        if item.image_url:
            item.image_url = do.download(
                item.shows[0].archive_lahmastore_base_url, item.image_url
            )
    return many_item_details_schema.dumps(items)
Exemplo n.º 6
0
def view_item(id):
    item_query = Item.query.filter_by(id=id)
    item = item_query.first_or_404()
    if item:
        if item.image_url:
            do = DoArchive()
            item.image_url = do.download(
                item.shows[0].archive_lahmastore_base_url, item.image_url
            )
        return item_details_schema.dump(item)
    else:
        return make_response("Item not found", 404, headers)
Exemplo n.º 7
0
def view_show(id):
    do = DoArchive()
    show_query = Show.query.filter_by(id=id)
    show = show_query.first_or_404()
    if show:
        if show.cover_image_url:
            show.cover_image_url = do.download(
                show.archive_lahmastore_base_url, show.cover_image_url
            )
        # Display episodes by date in descending order
        # We need to sort nested: episode list of the full object then re-apply that part
        serial_show = show_details_schema.dump(show)
        date_desc_episodes = sort_for(serial_show["items"], "play_date", "desc")
        serial_show["items"] = date_desc_episodes

        return serial_show
    else:
        return make_response("Show not found", 404, headers)