I recently ran into an interesting problem with cleaning up some uploads from my Netgear Meural account. The mobile app and web interface both let me upload pictures and videos to a playlist, but when I delete the playlist it won’t delete the media items from the playlist. The only way to delete the media is to batch select them from “All Uploads” section. I had about 2000 media items, and only 1100 items in all of the playlists combined. So it would have been a very frustrating experience if I had to visually identify each of those 900 items from “All Uploads” that didn’t belong to any playlist.
Now, this might not have bothered me too much as I can simply let the media items pile up in “All Uploads” even if they are not in any playlists I display on the Meural Canvas, but Netgear only offers up to 4GB of Meural cloud storage for free. When I started getting low on remaining storage, I reached out to Netgear with a quick solution to wipe all the uploads which are not in any of the playlists to recover some of the cloud storage. When I didn’t hear back from support, I was already down to less than 0.4GB of free storage remaining and decided to take this matter into my own hands.
Automating the boring stuff
When I have to choose automation vs. manual work, even when coming up with an automated solution would probably take me an equal amount of time as manual work, I always go for automation since it’s reusable work and I get to apply my engineering skills.
I started with monitoring the network requests and listing down the API endpoints involved when browsing a playlist and deleting an item from “All Uploads”. I also noticed it uses a simple bearer token for authorization. Normally, I would have used a proxy (e.g. Charles, Proxyman, etc.) to intercept and monitor network traffic to reverse engineer and document APIs, but I found out this has already been done by someone else here. So all I had to do was import this collection into Postman and explore.
Using postman, I was able to send a login request and get an auth token, which I saved in the authentication environment variable for the API collection in Postman. Now I can make subsequent API requests with the authentication header populated from the global variable. I was interested in only the following API endpoints and verified that I can make these requests through Postman
- POST /authenticate to get authentication token
- GET /user/items to get all the items user has uploaded
- This is a paginated request, so I have to make multiple GET requests and merge the results
- GET /usr/galleries to get list of all the galleries user has created
- DELETE /items/:itemId to delete an item
For each of these requests, once I was able to make a successful request through Postman, I copied over the autogenerated code from Postman for Python and started building my script to process the results from the API requests and identify the extra items which needs to be deleted. Extra items = (All items – Items in any gallery)
After successful execution of this script, I was able to claim a total of 2.5 GB of cloud storage back from those unused media files.
You can find the script I wrote for this automation on github gist.
A big thank you mate for your work. Was stuck cursing that I had to download 400 pics one by one and then i found your blog. Kudos to you!!!