]> littlesong.place Git - littlesongplace.git/commitdiff
Prevent my songs from showing up at top of random page
authorChris Fulljames <christianfulljames@gmail.com>
Sun, 2 Mar 2025 19:14:32 +0000 (14:14 -0500)
committerChris Fulljames <christianfulljames@gmail.com>
Sun, 2 Mar 2025 19:14:32 +0000 (14:14 -0500)
main.py
todo.txt

diff --git a/main.py b/main.py
index 200741053fee4bfbb7cee486ea42a309e7f7ce20..6103b4debc7481d6bf4f6d025313100653727f00 100644 (file)
--- a/main.py
+++ b/main.py
@@ -1090,8 +1090,18 @@ class Song:
 
     @classmethod
     def get_random(cls, count):
-        songs = cls._from_db("select * from songs inner join users on songs.userid = users.userid where songid in (select songid from songs order by random() limit ?)", [count])
+        # Get random songs + 10 extras so I can filter out my own (I uploaded too many :/)
+        songs = cls._from_db("select * from songs inner join users on songs.userid = users.userid where songid in (select songid from songs order by random() limit ?)", [count + 10])
         random.shuffle(songs)
+
+        # Prevent my songs from showing up in the first 10 results
+        for i in reversed(range(min(10, len(songs)))):
+            if songs[i].username == "cfulljames":
+                del songs[i]
+
+        # Drop any extra songs (since we asked for 10 extras)
+        songs = songs[:count]
+
         return songs
 
     @classmethod
index 66208ad63a4500648d59e497f392b7ad77e38128..2177b71c8437b94b056a3253cce75b8b1ae2aa6a 100644 (file)
--- a/todo.txt
+++ b/todo.txt
@@ -1,4 +1,5 @@
 NOW
+- Hide shuffle button for song lists with 1 song or fewer
 - Pinned profile playlists
 - Player minimize button