A Movie Downloader (a weekend project in Go)

Last weekend’s project I made was a CLI downloader, named A Movie Downloader (movie-dl), that searches for a movie and downloads both magnet link and a matching English subtitles. A magnet is then opened with Transmission that handles its download. Subtitles are placed in a folder where a movie will be downloaded. That meant that somehow I needed to figure it out where and how this folder will be called. I did it with downloading magnet’s metadata – extracted its name and movie filename. A name is used to create a folder which will contain resulting magnet’s files. A filename is used to rename subtitles which are downloaded as a ZIP file and extracted so that video players can detect them.

Both movie magnet and subtitles ZIP file are downloaded via requesting websites’ search URLs and then scraping for the appropriate links. Links are also requested and scraped just as a user had to click a number of times for getting to the appropriate download buttons.

Workflow BEFORE this program for getting a movie and subtitles was:

  1. visit a page with movies,
  2. click search page,
  3. enter a search term, hit enter,
  4. click on a movie that is the first search result,
  5. click download button which shows a popup where you can pick a quality that you want to watch (magnet is being downloaded then),
  6. visit a page with subtitles,
  7. enter a search term, hit enter,
  8. click on a movie that is the first search result,
  9. click a link for English subtitles that has the highest approval rating,
  10. click a download button (ZIP file is being downloaded then),
  11. extract ZIP file,
  12. rename it according to video file’s name.

Workflow for getting a movie (say La La Land) AFTER this program (movie-dl) was made and subtitles is:

  1. open up the terminal and execute movie-dl "la la land"

The number of steps in BEFORE section can be reduced if you are searching for a movie that exists. You then don’t have to visit a search page, because the first page offers search box that takes you straight to movie’s page if a movie is found in the database (you continue from the 5th and 9th step). This is probably always the case for me, I just listed all the steps that a program is actually doing. In AFTER section you don’t actually have to specify whole movie name, just enough to make it uniquely identifiable.

I coded movie downloader coded in Go. It was a pleasant experience because I didn’t have to deal with a lot of bugs. Every time I (manually) tested a functionality I’ve just coded it resulted in desired output. A reason why is probably in using Go because it offers great tools that spot trivial bugs even before you compile the code. I also didn’t have to solve all problems myself. Reading a magnet’s info was done with torrent package, searching the website for links with go-libxml2 package – I just needed to learn how to use their API and refresh my XPath skills.

This movie downloader works as expected but there’s still work to be done. I want to make it more efficient and more maintainable, efficiency being my primary focus. That’s because I love Go’s concurrency and searching for movie’s magnet and its subtitles can certainly be done in parallel. Both steps are requesting websites and scraping them so there’s a room for improvement.