From 4d1a00a399ecac29c508b7402c5a3bb331b59fd4 Mon Sep 17 00:00:00 2001 From: sreeshanth-soma1 Date: Thu, 5 Feb 2026 06:25:05 +0530 Subject: [PATCH] feat(search): add ID search for media and playlists - Add Media ID filter to advanced search - Enable playlist search by numeric ID --- classes/models/media_model.php | 3 ++- classes/models/playlists_model.php | 7 ++++++- public/html/sidebar/advanced_search.html | 1 + 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/classes/models/media_model.php b/classes/models/media_model.php index 7ea7e342..6ee71a3d 100644 --- a/classes/models/media_model.php +++ b/classes/models/media_model.php @@ -952,7 +952,7 @@ public function search_filters_validate($args = []) OBFHelpers::require_args($args, ['filters']); $filters = $args['filters']; - $allowed_filters = ['comments','artist','title','album','year','type','category','country','language','genre','duration','is_copyright_owner','status']; + $allowed_filters = ['id','comments','artist','title','album','year','type','category','country','language','genre','duration','is_copyright_owner','status']; $allowed_operators = [ // deprecated 'like', @@ -1034,6 +1034,7 @@ public function search_filters_where_array($args = []) $column_array['duration'] = 'media.duration'; $column_array['comments'] = 'media.comments'; $column_array['is_copyright_owner'] = 'media.is_copyright_owner'; + $column_array['id'] = 'media.id'; $metadata_fields = $this->models->mediametadata('get_all'); $metadata_defaults = []; diff --git a/classes/models/playlists_model.php b/classes/models/playlists_model.php index 86649a37..c95422da 100644 --- a/classes/models/playlists_model.php +++ b/classes/models/playlists_model.php @@ -299,7 +299,12 @@ public function search($query, $limit, $offset, $sort_by, $sort_dir, $my = false $where_strings = []; if ($query !== '' && $query !== false && $query !== null) { - $where_strings[] = '(name LIKE "%' . $this->db->escape($query) . '%" OR description LIKE "%' . $this->db->escape($query) . '%")'; + // If query is numeric, also search by ID + if (is_numeric($query)) { + $where_strings[] = '(id = "' . $this->db->escape($query) . '" OR name LIKE "%' . $this->db->escape($query) . '%" OR description LIKE "%' . $this->db->escape($query) . '%")'; + } else { + $where_strings[] = '(name LIKE "%' . $this->db->escape($query) . '%" OR description LIKE "%' . $this->db->escape($query) . '%")'; + } } if (!$this->user->check_permission('manage_playlists')) { $where_strings[] = '(status = "public" or status = "visible" or owner_id = "' . $this->db->escape($this->user->param('id')) . '")'; diff --git a/public/html/sidebar/advanced_search.html b/public/html/sidebar/advanced_search.html index b96ecef1..bd6ed48c 100644 --- a/public/html/sidebar/advanced_search.html +++ b/public/html/sidebar/advanced_search.html @@ -7,6 +7,7 @@