mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 04:53:01 +00:00
add docs for playlist endpoints
+ limit recently added tracks to 100
This commit is contained in:
committed by
Mungai Njoroge
parent
4edb3a5e7a
commit
ae031014a9
@@ -12,7 +12,7 @@ from app.serializers.artist import serialize_for_card
|
||||
|
||||
from itertools import groupby
|
||||
|
||||
from app.utils.dates import timestamp_from_days_ago, timestamp_to_time_passed
|
||||
from app.utils.dates import timestamp_to_time_passed
|
||||
|
||||
older_albums = set()
|
||||
older_artists = set()
|
||||
@@ -216,8 +216,6 @@ def get_recent_items(limit: int = 7):
|
||||
return recent_items
|
||||
|
||||
|
||||
def get_recent_tracks(cutoff_days: int):
|
||||
def get_recent_tracks(limit: int):
|
||||
tracks = sorted(TrackStore.tracks, key=lambda t: t.created_date, reverse=True)
|
||||
timestamp = timestamp_from_days_ago(cutoff_days)
|
||||
|
||||
return [t for t in tracks if t.created_date > timestamp]
|
||||
return tracks[:limit]
|
||||
@@ -1,6 +1,7 @@
|
||||
"""
|
||||
This library contains all the functions related to playlists.
|
||||
"""
|
||||
|
||||
import os
|
||||
import random
|
||||
import string
|
||||
@@ -62,7 +63,7 @@ def create_gif_thumbnail(image: Any, img_path: str):
|
||||
|
||||
|
||||
def save_p_image(
|
||||
img: Image, pid: str, content_type: str = None, filename: str = None
|
||||
img: Image, pid: int, content_type: str = None, filename: str = None
|
||||
) -> str:
|
||||
"""
|
||||
Saves a playlist banner image and returns the filepath.
|
||||
@@ -72,7 +73,7 @@ def save_p_image(
|
||||
random_str = "".join(random.choices(string.ascii_letters + string.digits, k=5))
|
||||
|
||||
if not filename:
|
||||
filename = pid + str(random_str) + ".webp"
|
||||
filename = str(pid) + str(random_str) + ".webp"
|
||||
|
||||
full_img_path = os.path.join(settings.Paths.get_playlist_img_path(), filename)
|
||||
|
||||
@@ -134,7 +135,7 @@ def get_first_4_images(
|
||||
return duplicate_images(images)
|
||||
|
||||
|
||||
def get_recently_added_playlist(cutoff: int = 14):
|
||||
def get_recently_added_playlist(limit: int = 100):
|
||||
playlist = Playlist(
|
||||
id="recentlyadded",
|
||||
name="Recently Added",
|
||||
@@ -144,8 +145,10 @@ def get_recently_added_playlist(cutoff: int = 14):
|
||||
trackhashes=[],
|
||||
)
|
||||
|
||||
tracks = get_recent_tracks(cutoff)
|
||||
tracks = get_recent_tracks(limit=limit)
|
||||
|
||||
try:
|
||||
# Create date to show as last updated
|
||||
date = datetime.fromtimestamp(tracks[0].created_date)
|
||||
except IndexError:
|
||||
return playlist, []
|
||||
|
||||
Reference in New Issue
Block a user