mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-03 20:13:02 +00:00
port: recent items for homepage
This commit is contained in:
@@ -1,29 +1,36 @@
|
||||
from datetime import datetime
|
||||
import os
|
||||
from app.db.libdata import AlbumTable, ArtistTable, TrackTable
|
||||
from app.db.userdata import FavoritesTable, ScrobbleTable
|
||||
from app.models.logger import TrackLog
|
||||
|
||||
from app.db.sqlite.logger.tracks import SQLiteTrackLogger as db
|
||||
from app.db.sqlite.playlists import SQLitePlaylistMethods as pdb
|
||||
from app.db.sqlite.favorite import SQLiteFavoriteMethods as fdb
|
||||
# from app.db.sqlite.logger.tracks import SQLiteTrackLogger as db
|
||||
# from app.db.sqlite.playlists import SQLitePlaylistMethods as pdb
|
||||
# from app.db.sqlite.favorite import SQLiteFavoriteMethods as fdb
|
||||
|
||||
from app.models.playlist import Playlist
|
||||
from app.serializers.track import serialize_track
|
||||
from app.serializers.album import album_serializer
|
||||
from app.lib.playlistlib import get_first_4_images
|
||||
from app.utils.dates import create_new_date, date_string_to_time_passed, timestamp_to_time_passed
|
||||
from app.store.folder import FolderStore
|
||||
from app.utils.dates import (
|
||||
create_new_date,
|
||||
date_string_to_time_passed,
|
||||
timestamp_to_time_passed,
|
||||
)
|
||||
from app.serializers.artist import serialize_for_card
|
||||
from app.serializers.playlist import serialize_for_card as serialize_playlist
|
||||
from app.lib.home.recentlyadded import get_recently_added_playlist
|
||||
|
||||
from app.store.albums import AlbumStore
|
||||
from app.store.tracks import TrackStore
|
||||
from app.store.artists import ArtistStore
|
||||
|
||||
# from app.store.albums import AlbumStore
|
||||
# from app.store.tracks import TrackStore
|
||||
# from app.store.artists import ArtistStore
|
||||
|
||||
|
||||
def get_recently_played(limit=7):
|
||||
# TODO: Paginate this
|
||||
entries = db.get_all()
|
||||
# entries = db.get_all()
|
||||
entries = ScrobbleTable.get_all(0, 200)
|
||||
items = []
|
||||
added = set()
|
||||
|
||||
@@ -36,7 +43,7 @@ def get_recently_played(limit=7):
|
||||
if len(items) >= limit:
|
||||
break
|
||||
|
||||
entry = TrackLog(*entry)
|
||||
# entry = TrackLog(*entry)
|
||||
|
||||
if entry.source in added:
|
||||
continue
|
||||
@@ -44,7 +51,8 @@ def get_recently_played(limit=7):
|
||||
added.add(entry.source)
|
||||
|
||||
if entry.type == "album":
|
||||
album = AlbumStore.get_album_by_hash(entry.type_src)
|
||||
# album = AlbumStore.get_album_by_hash(entry.type_src)
|
||||
album = AlbumTable.get_album_by_albumhash(entry.type_src)
|
||||
|
||||
if album is None:
|
||||
continue
|
||||
@@ -72,7 +80,8 @@ def get_recently_played(limit=7):
|
||||
continue
|
||||
|
||||
if entry.type == "artist":
|
||||
artist = ArtistStore.get_artist_by_hash(entry.type_src)
|
||||
# artist = ArtistStore.get_artist_by_hash(entry.type_src)
|
||||
artist = ArtistTable.get_artist_by_hash(entry.type_src)
|
||||
|
||||
if artist is None:
|
||||
continue
|
||||
@@ -107,13 +116,14 @@ def get_recently_played(limit=7):
|
||||
# print(folder)
|
||||
# folder = os.path.join("/", folder, "")
|
||||
# print(folder)
|
||||
count = len([t for t in TrackStore.tracks if t.folder == folder])
|
||||
# count = len([t for t in TrackStore.tracks if t.folder == folder])
|
||||
count = FolderStore.count_tracks_containing_paths([folder])
|
||||
items.append(
|
||||
{
|
||||
"type": "folder",
|
||||
"item": {
|
||||
"path": folder,
|
||||
"count": count,
|
||||
"count": count[0]["trackcount"],
|
||||
"help_text": "folder",
|
||||
"time": timestamp_to_time_passed(entry.timestamp),
|
||||
},
|
||||
@@ -122,12 +132,15 @@ def get_recently_played(limit=7):
|
||||
continue
|
||||
|
||||
if entry.type == "playlist":
|
||||
continue
|
||||
is_custom = entry.type_src in [i["name"] for i in custom_playlists]
|
||||
# is_recently_added = entry.type_src == "recentlyadded"
|
||||
|
||||
if is_custom:
|
||||
playlist, _ = next(
|
||||
i["handler"]() for i in custom_playlists if i["name"] == entry.type_src
|
||||
i["handler"]()
|
||||
for i in custom_playlists
|
||||
if i["name"] == entry.type_src
|
||||
)
|
||||
playlist.images = [i["image"] for i in playlist.images]
|
||||
|
||||
@@ -175,16 +188,17 @@ def get_recently_played(limit=7):
|
||||
"type": "favorite_tracks",
|
||||
"item": {
|
||||
"help_text": "playlist",
|
||||
"count": fdb.get_track_count(),
|
||||
"count": FavoritesTable.count(),
|
||||
"time": timestamp_to_time_passed(entry.timestamp),
|
||||
},
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
try:
|
||||
track = TrackStore.get_tracks_by_trackhashes([entry.trackhash])[0]
|
||||
except IndexError:
|
||||
# track = TrackStore.get_tracks_by_trackhashes([entry.trackhash])[0]
|
||||
track = TrackTable.get_track_by_trackhash(entry.trackhash)
|
||||
|
||||
if track is None:
|
||||
continue
|
||||
|
||||
track = serialize_track(track)
|
||||
@@ -202,10 +216,12 @@ def get_recently_played(limit=7):
|
||||
|
||||
|
||||
def get_recently_played_tracks(limit: int):
|
||||
records = db.get_recently_played(start=0, limit=limit)
|
||||
last_updated = records[0].timestamp
|
||||
tracks = TrackStore.get_tracks_by_trackhashes([r.trackhash for r in records])
|
||||
return tracks, last_updated
|
||||
# records = db.get_recently_played(start=0, limit=limit)
|
||||
# last_updated = records[0].timestamp
|
||||
# tracks = TrackStore.get_tracks_by_trackhashes([r.trackhash for r in records])
|
||||
# return tracks, last_updated
|
||||
return TrackTable.get_recently_played(limit)
|
||||
|
||||
|
||||
def get_recently_played_playlist(limit: int = 100):
|
||||
playlist = Playlist(
|
||||
@@ -217,13 +233,12 @@ def get_recently_played_playlist(limit: int = 100):
|
||||
trackhashes=[],
|
||||
)
|
||||
|
||||
tracks, timestamp = get_recently_played_tracks(limit)
|
||||
|
||||
date = datetime.fromtimestamp(timestamp)
|
||||
tracks = get_recently_played_tracks(limit)
|
||||
date = datetime.fromtimestamp(tracks[0].lastplayed)
|
||||
playlist.last_updated = date_string_to_time_passed(create_new_date(date))
|
||||
|
||||
images = get_first_4_images(tracks=tracks)
|
||||
playlist.images = images
|
||||
playlist.set_count(len(tracks))
|
||||
|
||||
return playlist, tracks
|
||||
return playlist, tracks
|
||||
|
||||
@@ -10,10 +10,8 @@ from typing import Any
|
||||
from PIL import Image, ImageSequence
|
||||
|
||||
from app import settings
|
||||
from app.db.libdata import AlbumTable, TrackTable
|
||||
from app.models.track import Track
|
||||
from app.store.albums import AlbumStore
|
||||
from app.store.tracks import TrackStore
|
||||
|
||||
|
||||
def create_thumbnail(image: Any, img_path: str) -> str:
|
||||
"""
|
||||
@@ -105,7 +103,8 @@ def get_first_4_images(
|
||||
tracks: list[Track] = [], trackhashes: list[str] = []
|
||||
) -> list[dict["str", str]]:
|
||||
if len(trackhashes) > 0:
|
||||
tracks = TrackStore.get_tracks_by_trackhashes(trackhashes)
|
||||
# tracks = TrackStore.get_tracks_by_trackhashes(trackhashes)
|
||||
tracks = TrackTable.get_tracks_by_trackhashes(trackhashes)
|
||||
|
||||
albums = []
|
||||
|
||||
@@ -116,11 +115,12 @@ def get_first_4_images(
|
||||
if len(albums) == 4:
|
||||
break
|
||||
|
||||
albums = AlbumStore.get_albums_by_hashes(albums)
|
||||
# albums = AlbumStore.get_albums_by_hashes(albums)
|
||||
albums = AlbumTable.get_albums_by_albumhashes(albums)
|
||||
images = [
|
||||
{
|
||||
"image": album.image,
|
||||
"color": "".join(album.colors),
|
||||
"color": album.color,
|
||||
}
|
||||
for album in albums
|
||||
]
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import gc
|
||||
import os
|
||||
from pprint import pprint
|
||||
from time import time
|
||||
@@ -280,6 +281,7 @@ class IndexEverything:
|
||||
# pass
|
||||
|
||||
CordinateMedia(instance_key=str(time()))
|
||||
gc.collect()
|
||||
|
||||
|
||||
@background
|
||||
|
||||
Reference in New Issue
Block a user