/

SELECT "videos".* FROM "videos" WHERE (((original_filename IS NOT NULL AND provider IS DISTINCT FROM 'local') OR (provider NOT IN ('theync', 'xrares', 'okru', 'eporner', 'beeg', 'local', 'yandex', 'youtube', 'fsiblog5', 'pornhub', 'archive') AND (source_uri IS NULL OR source_uri NOT ILIKE ALL (ARRAY['%theync.com%', '%xrares.com%', '%ok.ru%', '%motherless.com%', '%fuq.com%', '%eporner.com%', '%beeg.com%'])) AND (stream_url IS NOT NULL OR source_uri LIKE 'http%'))) OR NOT (("videos"."embed_url" = '' OR "videos"."embed_url" IS NULL)) AND (embed_url NOT ILIKE ALL (ARRAY['%theync.com%', '%xrares.com%', '%ok.ru%', '%motherless.com%', '%fuq.com%', '%eporner.com%', '%beeg.com%']))) AND "videos"."our_rating" IS NULL ORDER BY CASE WHEN predicted_rating IS NULL THEN 2
                           WHEN updated_at > NOW() - INTERVAL '3 hours' THEN 0
                           ELSE 1 END ASC,
                      predicted_rating DESC NULLS LAST,
                      updated_at DESC NULLS LAST,
                      id DESC LIMIT 400 OFFSET 0