kieraneglin/pinchflat

[FR] Bulk Delete Shorts

Closed this issue · 3 comments

Is your feature request related to a problem? Please describe.
Now that shorts detection is (hopefully) fixed, I'd like to clean up my library and delete all of the existing shorts (and associated data) that were mistakenly downloaded.

Describe the solution you'd like
I'd like a button to delete all shorts on a source/media profile.

Describe alternatives you've considered
I also considered some sort of scheduled task that automatically deleted shorts on sources using a media profile where that setting was disabled. That would keep the library clean in case the shorts detection fails and gets updated in the future. Problem is that I don't really know how you would prevent deleting shorts the user actually wants to keep around (they manually downloaded it).

I guess it depends on if the shorts setting means "I never want these" or "don't download them automatically, but I might manually download some in the future"

Or, have a better media management list when clicking on a source; one where I can checkmark and bulk edit/delete media. It would also have to list the shorts flag in the list for it to solve my issue. This would be a more generic solution, but probably more useful.

Otherwise, I'll have to search the database for select * from media_items where short_form_content = 1 and media_filepath is not null;, find them in the frontend by ID, and then "Actions -> Delete Files" them one by one.

Additional context
I don't think I have any additional context, but awesome job on this project!

Hey there! Thanks for the suggestion (:

Since this is hopefully a one-off thing, I don't think it makes sense to put a button in the UI for this such a specific purpose. But I should be able to whip up a one-liner for you tomorrow to automatically delete any offending files!

(note to self: post the one-liner on the original GH issue so others can use it if they need)

Okay! I've come up with some god-awful incantations that should do the trick.

⚠️⚠️⚠️
These commands delete any media items who's format (ie: shorts/livestream) doesn't match the current preferences set by the media profile. It cannot be scoped to only shorts impacted by this bug - all downloaded shorts belonging to a media profile that is currently set to exclude shorts will be deleted. Same goes for livestreams
⚠️⚠️⚠️


Anyway, start by opening a new console into the Pinchflat container. For most people that'll be a command like docker exec -it pinchflat bash, but you may have to adapt it depending on your setup.

This command will list every media item that will be deleted. It's a good idea to use this as a spot-check to make sure only the expected files are getting removed. This command will not remove any files.

./bin/pinchflat rpc "alias Pinchflat.{Repo, Media}; use Pinchflat.Media.MediaQuery; MediaQuery.new() |> MediaQuery.require_assoc(:media_profile) |> where(^dynamic(^MediaQuery.downloaded() and not ^MediaQuery.format_matching_profile_preference())) |> Repo.all() |> Enum.map(&(Map.take(&1, [:id, :title, :short_form_content, :duration_seconds]))) |> IO.inspect(limit: :infinity); nil"

Then, assuming the last command looks good, you can use this command to delete these files:

./bin/pinchflat rpc "alias Pinchflat.{Repo, Media}; use Pinchflat.Media.MediaQuery; MediaQuery.new() |> MediaQuery.require_assoc(:media_profile) |> where(^dynamic(^MediaQuery.downloaded() and not ^MediaQuery.format_matching_profile_preference())) |> Repo.all() |> Enum.map(&Media.delete_media_files/1); nil"

That's it! Let me know how it works out 🤙

Looks like that worked perfectly, thank you so much!