Skip to content

Commit

Permalink
cast Path to string
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Aug 17, 2023
1 parent c5063b4 commit 6885dc4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
[![GitHub Sponsors](https://img.shields.io/github/sponsors/meisnate12?color=%238a2be2&style=plastic)](https://github.com/sponsors/meisnate12)
[![Sponsor or Donate](https://img.shields.io/badge/-Sponsor%2FDonate-blueviolet?style=plastic)](https://github.com/sponsors/meisnate12)

Your Plex directories are growing out of control. You use overlays from [Plex Meta Manager](https://github.com/meisnate12/Plex-Meta-Manager) (PMM) or upload lots of custom art from [Title Card Maker](https://github.com/CollinHeist/TitleCardMaker) (TCM) that you no longer want to use or need to eliminate. You don't want to perform the [plex dance](https://www.plexopedia.com/plex-media-server/general/plex-dance/) if you can avoid it. This script will free up gigs of space....
Your Plex directories are growing out of control. You use overlays from [Plex Meta Manager](https://github.com/meisnate12/Plex-Meta-Manager) (PMM) or upload lots of custom art from [Title Card Maker](https://github.com/CollinHeist/TitleCardMaker) (TCM) that you no longer want to use or need to eliminate. You don't want to perform the [plex dance](https://www.plexopedia.com/plex-media-server/general/plex-dance/) if you can avoid it. This script can free up gigs of space....

As well as being able to clean the PhotoTranscoder Directory and running the Plex operations Empty Trash, Clean Bundles, and Optimize DB.

Expand Down Expand Up @@ -178,17 +178,21 @@ To set the `Plex Path` for the run:

How Plex Image Cleanup runs depends on the `Mode` Option that's currently set for that run.

* `report`: Metadata Directory File changes will be reported but not performed.
* `move`: Metadata Directory Files will be moved to the PIC Restore Directory. (CAN BE RESTORED)
* `restore`: Restores the Metadata Directory Files from the PIC Restore Directory.
* `clear`: Clears out the PIC Restore Directory. (CANNOT BE RESTORED)
* `remove`: Metadata Directory Files will be removed. (CANNOT BE RESTORED)
* `nothing`: Metadata Directory Files will not even be looked at.
Here, "unused images" refers to unused uploaded images as described above.

* `report`: Reports statistics on unused images [count, size] but takes no action on them [like moving or deleting].
* `move`: Moves unused images to the PIC Restore Directory. From there they can be `restore`d or `clear`ed.
* `restore`: Restores the unused images from the PIC Restore Directory [as created by `move`] to the Metadata Directory. This restores Plex to its state prior to running PIC.
* `clear`: Deletes the unused images from the PIC Restore Directory [as created by `move`]. (CANNOT BE UNDONE)
* `remove`: Deletes the unused images from the Metadata Directory immediately, without the stop in the PIC Restore Directory. (CANNOT BE UNDONE)
* `nothing`: Does nothing with unused images; no report, no action.

To set the Global `Mode` for the run:
* **Environment Variable:** `MODE=remove`
* **Shell Command:** `-m remove` or `--mode remove`

**NOTE: `report` is the default mode if you do not specify a mode.**

### Other Operations

In addition to cleaning the Plex Metadata Directory for custom images the script can clean out your PhotoTranscoder Directory, Empty Trash, Clean Bundles, and Optimize DB.
Expand Down
4 changes: 2 additions & 2 deletions plex_image_cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ def run_plex_image_cleanup(attrs):
restore_dir = pmmargs["plex"] / "PIC Restore"

if not pmmargs["plex"].exists():
raise Failed(f"Directory Error: Plex Databases Directory Not Found: {pmmargs['plex']}")
raise Failed(f"Directory Error: Plex Directory Not Found: {pmmargs['plex']}")
elif mode != "nothing" and not meta_dir.exists():
raise Failed(f"Directory Error: Metadata Directory Not Found: {meta_dir}")
elif do_transcode and not transcoder_dir.exists():
Expand Down Expand Up @@ -294,7 +294,7 @@ def get_resources(media):

logger.info("Restoring Renamed Bloat Images", start="work")
for source_path in tqdm(restore_images, unit=" restored", desc="| Restoring Renamed Bloat Images"):
destination_path = (meta_dir / str(source_path).removeprefix(restore_dir)[1:]).with_suffix(".jpg")
destination_path = (meta_dir / str(source_path).removeprefix(str(restore_dir))[1:]).with_suffix(".jpg")
messages.append(f"RENAME: {source_path}\n ----> {destination_path}\n")
destination_path.parent.mkdir(exist_ok=True)
source_path.rename(destination_path)
Expand Down

0 comments on commit 6885dc4

Please sign in to comment.