Using the UrlFetchApp library and the fetch method we call the Plex media server to retrieve all the contents of our library. We parse the XML response to JSON using a method that you can find here. You can add the parsing method to the same file, if you want.
This tutorial is going to cover what it takes to automatically cleanup a Plex media server, using Google Apps Scripts.