From 71318d66c366cef2c0643bfab4e5b1e0a759f61d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ciar=C3=A1n=20Ainsworth?= <cda@rootkey.co.uk>
Date: Thu, 23 Jul 2020 17:33:29 +0200
Subject: [PATCH] Resolve "The "radio - random" function also plays podcasts"

---
 api/funkwhale_api/radios/radios.py | 10 +++++++---
 changes/changelog.d/1140.bugfix    |  1 +
 2 files changed, 8 insertions(+), 3 deletions(-)
 create mode 100644 changes/changelog.d/1140.bugfix

diff --git a/api/funkwhale_api/radios/radios.py b/api/funkwhale_api/radios/radios.py
index 08329c6ead..a85111983a 100644
--- a/api/funkwhale_api/radios/radios.py
+++ b/api/funkwhale_api/radios/radios.py
@@ -102,7 +102,7 @@ class SessionRadio(SimpleRadio):
 class RandomRadio(SessionRadio):
     def get_queryset(self, **kwargs):
         qs = super().get_queryset(**kwargs)
-        return qs.order_by("?")
+        return qs.filter(artist__content_category="music").order_by("?")
 
 
 @registry.register(name="favorites")
@@ -116,7 +116,7 @@ class FavoritesRadio(SessionRadio):
     def get_queryset(self, **kwargs):
         qs = super().get_queryset(**kwargs)
         track_ids = kwargs["user"].track_favorites.all().values_list("track", flat=True)
-        return qs.filter(pk__in=track_ids)
+        return qs.filter(pk__in=track_ids, artist__content_category="music")
 
 
 @registry.register(name="custom")
@@ -271,7 +271,11 @@ class LessListenedRadio(SessionRadio):
     def get_queryset(self, **kwargs):
         qs = super().get_queryset(**kwargs)
         listened = self.session.user.listenings.all().values_list("track", flat=True)
-        return qs.exclude(pk__in=listened).order_by("?")
+        return (
+            qs.filter(artist__content_category="music")
+            .exclude(pk__in=listened)
+            .order_by("?")
+        )
 
 
 @registry.register(name="actor_content")
diff --git a/changes/changelog.d/1140.bugfix b/changes/changelog.d/1140.bugfix
new file mode 100644
index 0000000000..d9702a5f45
--- /dev/null
+++ b/changes/changelog.d/1140.bugfix
@@ -0,0 +1 @@
+Fix random radio so that podcast content is not picked up (#1140)
\ No newline at end of file
-- 
GitLab