--- Title: Using a Filesystem vs Database Date: 2022-01-28 Sequence: Tags:  ---
I'm working on a poor man's version of plex and netflix with the goal being something extremely simple. I have used kodi and plex but they get messy with trying to automatically catalogue shows and have a lot going on. I figured I could get the very essence of them distilled down as I don't really expect much from something like plex. I just want to be able to download shows and movies and play it on my phone at home.
With that very simple idea, I figured I'll make a site that serves mp4 as that is natively supported by all the browsers. The first version of the site took the form of just being a listing of directories with mp4s at the ends of them. It was cumbersome but it worked and I happily used it for quite some time.
After almost a year, I decided to take a stab at making it look pretty! I also took this chance to learn css grid and flexbox properly which I think worked out great. I learned quite a bit and I'm still learning new things. So far I was able to get away with not even using media queries to get responsiveness thanks to the following article.
One of my initial ideas to make my plex clone was to use the file system as the source of truth. I was going to just query and transform all my downloaded files into a format that I could then use on the front end. This was not too much work as I recursed down the directories and built up an in memory database. This way the system would be as up to date as possible without me having to do anything.
This quickly got messy with way more code than I expected being written. There was probably an abstraction that I could have added that would have made this idea worthwhile but I quickly gave it up and went the traditional route of setting up a database that stored the metadata about each directory. The metadata is entered manually as I add shows and movies, I also download the posters and banners and update the descriptions. I also clean up the folders so that seasons are laid out how I want them to be. This is all very much extra steps but for now its fine. I don't download enough or have enough content that this is impossible.
Switching to using a database ended up being a good idea, it simplified the code drastically and a lot of the junk I had written could now be deleted. It's not news but databases are better than ad-hoc databases!
I think there is a way to get around using a database as after all I rely on sequelize to do all the complex work and that's why I think the database is simple. There is probably some abstraction that would make the file system idea work but I want to just get to watching my shows so I'll consider the clone done for now.