mirror of
https://github.com/Dvorinka/swingmusic-extended.git
synced 2026-06-05 13:03: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
|
||||
|
||||
Reference in New Issue
Block a user