From cafc6514cb506c70c52c3667270f6c43d942d2eb Mon Sep 17 00:00:00 2001 From: lrnselfreliance <33263708+lrnselfreliance@users.noreply.github.com> Date: Sat, 27 Jun 2026 09:48:21 -0600 Subject: [PATCH] Restore the censored-video search filter (#499) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Restore the censored-video search filter Censored videos (no longer publicly available — detected when a channel refresh drops them from the channel list, or when comment downloads fail with "video unavailable/private/removed") are already flagged on FileGroup.censored, but there was no way to find them since the search rework dropped the old filter. Add a "Censored" toggle to the reworked search filter modal, shown only on the Videos page (showCensored). When enabled the video search returns only videos with FileGroup.censored = TRUE, tracked via a ?censored=true query param (useSearchCensored). * Move Availability filter below the Tags/Results row --------- Co-authored-by: Claude Opus 4.8 (1M context) --- app/src/api.js | 5 ++- app/src/components/Files.js | 32 +++++++++++++++++++- app/src/components/SearchFilterModal.test.js | 30 ++++++++++++++++++ app/src/components/Videos.js | 1 + app/src/hooks/customHooks.js | 13 ++++++-- modules/videos/conftest.py | 3 ++ modules/videos/schema.py | 1 + modules/videos/test/test_api.py | 21 +++++++++++++ modules/videos/video/api.py | 1 + modules/videos/video/lib.py | 4 +++ 10 files changed, 107 insertions(+), 4 deletions(-) diff --git a/app/src/api.js b/app/src/api.js index 7e4e1581..f357fffb 100644 --- a/app/src/api.js +++ b/app/src/api.js @@ -187,7 +187,7 @@ export async function tagChannelInfo(channelId, tagName) { }); } -export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline) { +export async function searchVideos(offset, limit, channelId, searchStr, order_by, tagNames, headline, censored) { // Build a search query to retrieve a list of videos from the API offset = parseInt(offset || 0); limit = parseInt(limit || DEFAULT_LIMIT); @@ -205,6 +205,9 @@ export async function searchVideos(offset, limit, channelId, searchStr, order_by if (headline) { body['headline'] = true; } + if (censored) { + body['censored'] = true; + } console.debug('searching videos', body); diff --git a/app/src/components/Files.js b/app/src/components/Files.js index 696f75b0..eb820754 100644 --- a/app/src/components/Files.js +++ b/app/src/components/Files.js @@ -31,6 +31,7 @@ import { PreviewLink, SearchInput, TagIcon, + Toggle, textEllipsis, useTitle } from "./Common"; @@ -38,6 +39,7 @@ import { usePages, useSearchDate, useSearchFiles, + useSearchCensored, useSearchFilter, useSearchOrder, useSearchView, @@ -541,6 +543,7 @@ export function SearchFilterModal( showDates = false, showTags = true, showLimit = true, + showCensored = false, limitOptions = [12, 24, 48, 96], }, ) { @@ -549,6 +552,7 @@ export function SearchFilterModal( const {sort} = useSearchOrder(); const {dateRange, months} = useSearchDate(); const {activeTags, anyTag} = useSearch(); + const {censored} = useSearchCensored(); const {limit} = usePages(DEFAULT_SEARCH_LIMIT); const {updateQuery} = useContext(QueryContext); @@ -565,6 +569,7 @@ export function SearchFilterModal( const [draftLimit, setDraftLimit] = useState(null); const [draftMonths, setDraftMonths] = useState([]); const [draftRange, setDraftRange] = useState(emptyRange); + const [draftCensored, setDraftCensored] = useState(false); // Seed the drafts from the URL each time the modal is opened. React.useEffect(() => { @@ -576,6 +581,7 @@ export function SearchFilterModal( setDraftLimit(limit); setDraftMonths(seededMonths); setDraftRange(seededRange); + setDraftCensored(censored || false); } }, [open]); @@ -613,6 +619,9 @@ export function SearchFilterModal( params.toDate = newToDate; params.month = draftMonths; } + if (showCensored && draftCensored !== censored) { + params.censored = draftCensored ? 'true' : null; + } if (Object.keys(params).length > 0) { params.o = 0; updateQuery(params); @@ -631,6 +640,7 @@ export function SearchFilterModal( setDraftLimit(DEFAULT_SEARCH_LIMIT); setDraftMonths([]); setDraftRange(emptyRange); + setDraftCensored(false); } // Sort section (operates on the draft). @@ -732,6 +742,18 @@ export function SearchFilterModal( } } + {showCensored && + + + + + + + } + {showDates && @@ -760,6 +782,7 @@ export function SearchFilterButton( showDates = false, showTags = true, showLimit = true, + showCensored = false, limitOptions = [12, 24, 48, 96], size = 'medium', content = 'Filter', @@ -770,6 +793,7 @@ export function SearchFilterButton( const {sort} = useSearchOrder(); const {dateRange, months} = useSearchDate(); const {activeTags, anyTag} = useSearch(); + const {censored} = useSearchCensored(); let count = 0; if (fileFilterOptions && filter) { @@ -784,6 +808,9 @@ export function SearchFilterButton( if (showDates && ((months && months.length > 0) || !dateRangeIsEmpty(dateRange))) { count += 1; } + if (showCensored && censored) { + count += 1; + } const active = count > 0; return <> @@ -801,6 +828,7 @@ export function SearchFilterButton( showDates={showDates} showTags={showTags} showLimit={showLimit} + showCensored={showCensored} limitOptions={limitOptions} /> @@ -820,6 +848,7 @@ export function SearchControlBar( sorts = null, fileFilterOptions = null, showDates = false, + showCensored = false, }, ) { const [localSearchStr, setLocalSearchStr] = useState(searchStr || ''); @@ -836,7 +865,8 @@ export function SearchControlBar( return
{viewButton}
{searchInput}
- +
} diff --git a/app/src/components/SearchFilterModal.test.js b/app/src/components/SearchFilterModal.test.js index 711460ca..5e919dfb 100644 --- a/app/src/components/SearchFilterModal.test.js +++ b/app/src/components/SearchFilterModal.test.js @@ -116,6 +116,36 @@ describe('SearchFilterButton', () => { expect(spy).not.toHaveBeenCalled(); }); + it('counts the censored filter and applies it on close when showCensored is set', () => { + const spy = jest.fn(); + renderButton({sorts: videoOrders, showCensored: true}, {}, spy); + + // No censored badge initially. + expect(screen.queryByText('1')).toBeNull(); + + fireEvent.click(screen.getByText('Filter')); + // The Availability section/toggle is shown. + expect(screen.getByText('Availability')).toBeInTheDocument(); + fireEvent.mouseUp(screen.getByTestId('toggle')); + // Draft only — nothing applied yet. + expect(spy).not.toHaveBeenCalled(); + + fireEvent.click(screen.getByText('Done')); + expect(spy).toHaveBeenCalledTimes(1); + expect(spy.mock.calls[0][0]).toMatchObject({censored: 'true'}); + }); + + it('does not show the Availability section unless showCensored is set', () => { + renderButton({sorts: videoOrders}); + fireEvent.click(screen.getByText('Filter')); + expect(screen.queryByText('Availability')).toBeNull(); + }); + + it('shows a count badge when the censored filter is active in the URL', () => { + renderButton({sorts: videoOrders, showCensored: true}, {censored: 'true'}); + expect(screen.getByText('1')).toBeInTheDocument(); + }); + it('shows the File Type section when fileFilterOptions are provided', () => { renderButton({ sorts: videoOrders, diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js index cfc77ba1..50c75aed 100644 --- a/app/src/components/Videos.js +++ b/app/src/components/Videos.js @@ -240,6 +240,7 @@ export function VideosPage() { inputRef={searchInputRef} viewButton={viewButton} sorts={videoOrders} + showCensored={true} /> {body} {paginator} diff --git a/app/src/hooks/customHooks.js b/app/src/hooks/customHooks.js index 8a6fde8e..fef299c1 100644 --- a/app/src/hooks/customHooks.js +++ b/app/src/hooks/customHooks.js @@ -616,6 +616,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => { const {view} = useSearchView(); const headline = view === 'headline'; const anyTag = searchParams.get('anyTag') === 'true'; + const censored = searchParams.get('censored') === 'true'; const [videos, setVideos] = useState(null); const [totalPages, setTotalPages] = useState(0); @@ -626,7 +627,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => { setLoading(true); setTotalPages(0); try { - let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags, headline, anyTag); + let [videos_, total] = await searchVideos(offset, limit, channelId, searchStr, order, activeTags, headline, censored); setVideos(videos_); setTotalPages(calculateTotalPages(total, limit)); } catch (e) { @@ -639,7 +640,7 @@ export const useSearchVideos = (defaultLimit, channelId, order_by) => { useEffect(() => { localSearchVideos(); - }, [searchStr, limit, channelId, offset, order_by, JSON.stringify(activeTags), headline]); + }, [searchStr, limit, channelId, offset, order_by, JSON.stringify(activeTags), headline, censored]); const setSearchStr = (value) => { updateQuery({q: value, o: 0, order: undefined}); @@ -1624,6 +1625,14 @@ export const useSearchOrder = () => { return {sort, setSort} } +export const useSearchCensored = () => { + // Filters Videos to only those which are no longer available for download (?censored=true). + const [value, setValue] = useOneQuery('censored'); + const censored = value === 'true'; + const setCensored = (newValue) => setValue(newValue ? 'true' : undefined); + return {censored, setCensored} +} + export const useSearchDate = () => { // Filters files using // ?month=1&month=2&month=3 diff --git a/modules/videos/conftest.py b/modules/videos/conftest.py index 2a0774ea..7241b255 100644 --- a/modules/videos/conftest.py +++ b/modules/videos/conftest.py @@ -335,6 +335,7 @@ def assert_video_search(async_client): limit: int = None, order_by: str = None, channel_id: int = None, + censored: bool = None, ): content = dict() if search_str is not None: @@ -349,6 +350,8 @@ def assert_video_search(async_client): content['order_by'] = order_by if channel_id is not None: content['channel_id'] = channel_id + if censored is not None: + content['censored'] = censored request, response = await async_client.post('/api/videos/search', content=json.dumps(content)) diff --git a/modules/videos/schema.py b/modules/videos/schema.py index 652ea27b..7da8ae3e 100644 --- a/modules/videos/schema.py +++ b/modules/videos/schema.py @@ -177,6 +177,7 @@ class VideoSearchRequest: channel_id: Optional[int] = None tag_names: List[str] = field(default_factory=list) headline: bool = False + censored: bool = False @dataclass diff --git a/modules/videos/test/test_api.py b/modules/videos/test/test_api.py index 5f6c2b07..6f714996 100644 --- a/modules/videos/test/test_api.py +++ b/modules/videos/test/test_api.py @@ -264,6 +264,27 @@ async def test_search_videos(test_session, video_factory, assert_video_search, s await assert_video_search(order_by=order_by) +@pytest.mark.asyncio +async def test_search_videos_censored(test_session, video_factory, assert_video_search): + """The censored filter returns only Videos which are no longer available for download.""" + vid1: Video = video_factory(upload_date='2022-09-16', with_video_file=True, title='vid1') + vid2: Video = video_factory(upload_date='2022-09-17', with_video_file=True, title='vid2') + vid3: Video = video_factory(upload_date='2022-09-18', with_video_file=True, title='vid3') + + # vid2 is no longer available. + vid2.file_group.censored = True + test_session.commit() + + # Without the filter, all Videos are returned. + await assert_video_search(assert_total=3, assert_ids=[vid1.id, vid2.id, vid3.id], + order_by='published_datetime') + await assert_video_search(assert_total=3, assert_ids=[vid1.id, vid2.id, vid3.id], + order_by='published_datetime', censored=False) + + # With the filter, only the censored Video is returned. + await assert_video_search(assert_total=1, assert_ids=[vid2.id], order_by='published_datetime', censored=True) + + @pytest.mark.asyncio async def test_search_audio_only(test_session, audio_factory, assert_video_search): """Audio-only files should be searchable alongside videos.""" diff --git a/modules/videos/video/api.py b/modules/videos/video/api.py index ede8939e..4f9f3dd9 100644 --- a/modules/videos/video/api.py +++ b/modules/videos/video/api.py @@ -65,6 +65,7 @@ async def search_videos(_: Request, body: schema.VideoSearchRequest): body.order_by, body.tag_names, body.headline, + body.censored, ) ret = {'file_groups': list(file_groups), 'totals': {'file_groups': videos_total}} diff --git a/modules/videos/video/lib.py b/modules/videos/video/lib.py index 1e7c02e8..9de2065c 100644 --- a/modules/videos/video/lib.py +++ b/modules/videos/video/lib.py @@ -92,10 +92,14 @@ def search_videos( order: str = None, tag_names: List[str] = None, headline: bool = False, + censored: bool = False, ) -> Tuple[List[dict], int]: tag_names = tag_names or [] # Search videos and audio-only files. wheres = ["(fg.mimetype LIKE 'video/%%' OR fg.mimetype LIKE 'audio/%%')"] + if censored: + # Only return videos which are no longer available for download. + wheres.append('fg.censored = TRUE') joins = list() join_video = False