How I Watch Movies From Any Device At Home Using NFS Server
Tags: learning, showdev, raspberrypi
Published: 2022-02-15 19:10:50

I'm a lazy fellow by design. Every time I downloaded movies or TV series on my phone or laptop, I would have to manually copy these files to a physical hard-disk-drive (HDD) via laptop and then connect the HDD to the back of my TV so I could watch them.

## The Problem
I wanted a way to download movies on phone and then somehow transfer it to my HDD directly (which would always be connected to my TV) so I could watch shows anytime I want. All this, without having to physically move my HDD back and forth to copy files.

## The Solution
The most do-able solution I could come up with was
- To connect and mount a pen drive (can replace it with a SSD in future) on a Raspberry Pi.
- Install [NFS server](https://www.weka.io/learn/what-is-network-file-system/#:~:text=NFS%20is%20an%20Internet%20Standard,if%20they%20were%20locally%20stored.) on that Raspberry Pi.
- Download movies on phone (or laptop, even).
- Transfer movies to your NFS server (on Pi) on mounted path (we can use [Termux](https://termux.com/) to SSH to Pi from Android phone).
- Install a media player app that allows you to stream media on your local network on your Android TV (no Android TV? See in Troubleshoots below). I personally use [VLC media player](https://play.google.com/store/apps/details?id=org.videolan.vlc&hl=en_IN&gl=US) to do this. Configure VLC to setup streaming.
- You can also config this on other devices (Android phones, laptop) as well. This way you can move all your movies/ shows to NFS server and free up space on your devices.

![Diagram to show how this looks after final setup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/61imj5zzsink8u7rlb0y.png)
In above diagram
1. Mount USB devices to a Raspberry Pi and setup a NFS server on that Pi.
2. Download your movies/ shows from a non-legal, non-piracy website (see what I did there?) on your phone or laptop.
3. Copy your downloaded content from your non-legal, non-piracy website (I did it again) to the mounted path on your Pi.
4. Install VLC on your device you want to watch content on and configure it to allow stream from your NFS server.

## The Brainstorming
Things I needed to figure out were
- Can I connect my HDD to Wifi/ Ethernet so I can transfer movies to it via my home network?
- What if I mount my HDD to Pi as storage? Can I then have that Pi + HDD connect to my TV via home network?
- How do I connect Pi to my TV? Can I connect TV and Pi via LAN; would be best config for zero-latency. Wifi would be convenient though; and no wires.
- What if I want to watch movies from Pi + HDD on other devices on my network - iPad, other phone, etc.
- Since HDD is outdated, can I use SSD instead for performance? Let's use a pen drive as SSD drive for now.
- Lets create NFS server on Pi, and try to stream media content from this server across all devices on home network.


## The Implementation
- Get a Raspberry Pi (any old one will also do. I used an old [Raspberry Pi 3 Model B+](https://www.amazon.in/Raspberry-Pi-3B-plus-Motherboard/dp/B07BDR5PDW) I had lying around the house) and [do initial setup](https://www.tomshardware.com/reviews/raspberry-pi-set-up-how-to,6029.html) - install Pi OS, setup username, password and SSH. Note down IP address of Pi or hostname (`hostname -I`) once it's connected to your network. I recommend to setup a static IP address for your Pi.
- Get a pen drive, at least a 128 GB. I recommend getting one of [those USB 3.0 or 3.1 ones](https://www.amazon.in/s?k=128gb+usb3&crid=34BK90K3GTFGG&sprefix=128gb+usb3%2Caps%2C206&ref=nb_sb_noss) for faster read-write speeds.
- Connect and mount this pendrive (say to `/mnt/movies` path) and [setup USB automount](https://www.shellhacks.com/raspberry-pi-mount-usb-drive-automatically/) in `/etc/fstab`.
- [Install NFS server on Pi](https://pimylifeup.com/raspberry-pi-nfs/). If you're using a brand new USB, you might have to install an [exFAT server](https://pimylifeup.com/raspberry-pi-exfat/) instead. The steps are pretty much the same, except that you need to install and configure additional utilities to work with exFAT.
- Check that your NFS/ exFAT server is setup on Pi and that you can SSH into it and copy files as well. You can do this from your phone as well. You'll need to install a terminal call Termux. It's pretty cool. Do check it out.
- Download movie on your phone or laptop. [Copy content from your laptop (or phone) using `scp`](https://linuxize.com/post/how-to-use-scp-command-to-securely-transfer-files/) to your mounted `/mnt/movies` path on your Pi. If you're copying from your phone, see Troubleshoots below on how to allow Termux to access your "Downloads" folder. It is disabled be default due to security reasons.
- Copy your files from phone/ laptop to the mounted path on Pi `/mnt/movies`. The command is `scp -r <source-folder> pi@your-local-pi-ip-address:/mnt/movies`. You might be prompted for your Pi credentials to continue. Pro tip - since you'll be copying files regularly, consider creating a small copy-files-script to save some time.
- Install and setup VLC media player for free on your TV or android device. Setup and [configure VLC to stream](https://www.youtube.com/watch?v=xW_vQW1fK4g) media over your local network.
- If you have configured VLC to stream over local network properly, a new folder gets added on the VLC home menu with the folder-name that you gave in previous step. Open that folder and you should see the movies you had copied over to your Pi.

## Troubleshoots
- This solution works best on an Android TV. If you do not have an Android TV, and are still interested, you can consider converting your old TV (as long it has a USB + HDMI port) by one of the available options in the market - See [Xiaomi Box 4](https://www.mi.com/in/mi-box-4k/), [Google Chromecast 3](https://www.youtube.com/watch?v=Qvgw1-s6oMQ) or similar).
- Termux does not have access to your Android phone device storage by default. You need to [give it permission explicitly](https://wiki.termux.com/wiki/Termux-setup-storage) by running the command `termux-setup-storage`. It creates a `~/storage` symlink. You can navigate to your Downloads folder on phone from here. For example `cd ~/storage/Downloads`
- AFAIK, with NFS, you cannot stream shows to your iPad as it uses a different filesystem maybe. At least I wasn't able to setup streaming content on VLC on my iPad and the NFS option was not available.
- If you have an older pen-drive, NFS server should work for you. But for newer USB pen drives, you'll probably need to work with exFAT.
- If unable to connect to NFS server, make sure Pi has power and is turned ON. SSH into it and see if you can see the files in mounted path with expected size - `ls -alh`. Was data corrupted while copying?
- If you're still unable to scan, copy to or play media files from your NFS server, review your file permissions carefully.