Home media server minidlna

What the hell is this for?

Circumstances so developed that I managed to connect an old PC, and so that it simply did not gather dust, since I am ashamed to sell such old stuff for 5-7 thousand (the price in my region for such a configuration), but getting 3 thousand for it - well, that ... I decided to make a small library of films, music at home, and my wife also has a lot of photographs that are very dear to her. The idea was as follows.





  • A kind of media server that will broadcast media content to the TV.





  • Some local storage for files, sometimes you have to run around with flash drives, otherwise the 500GB hard drive is not enough.





  • A torrent client that will download whatever I want.





The goals have been set, it remains to realize them. It is unlikely that experienced users will find something useful here, probably just novice Linux users, since all the actions are very simple to perform.





Installing Linux

How to install Linux, I think, is not worth talking about. I'll just describe what I did after installation. First, while the computer was near me, I set up a static address in the file/etc/netplan/00-installer-config.yaml







# This is the network config written by 'subiquity'
#ens34
network:
ethernets:
 ens34:
  addresses:
   - 192.168.31.5/24
  gateway4: 192.68.31.1
  nameservers:
   addresses: [192.168.31.1, 8.8.8.8]
 optional: true
 version: 2
      
      



, , . ,    ip- , Xiaomi,  ... ip- . . ssh-





maks@Kubuntu:~/.ssh$ ssh-keygen -f ~/.ssh/home
Generating public/private rsa key pair.

Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/maks/.ssh/home
Your public key has been saved in /home/maks/.ssh/home.pub
The key fingerprint is:
SHA256:i4rpsCZdQq5S+M2JyPWavEtCZqjsIJj2rHa69dzPgz0 maks@Kubuntu
The key's randomart image is:
+---[RSA 3072]----+
|                 |
|                 |
|                 |
|. .              |
|.B      S        |
|O.+..  . .       |
|OX.O... +        |
|X*@+Bo...E       |
|**OO=o ..oo      |
+----[SHA256]-----+
maks@Kubuntu:~/.ssh$ 
      
      







$ ssh-copy-id -i ~/.ssh/home.pub maks@192.168.31.5
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/maks/.ssh/home.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed%sudo   ALL=(ALL:ALL) NOPASSWD:ALL
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
maks@192.168.31.5's password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'maks@192.168.31.5'"
and check to make sure that only the key(s) you wanted were added.
      
      



~/.ssh/config







Host home
        HostName        192.168.31.5
        User            maks
        IdentityFile    /home/maks/.ssh/home
      
      



ssh home



, , , sudo. NOPASSWD /etc/sudoerc







%sudo   ALL=(ALL:ALL) NOPASSWD:ALL
      
      



transmission-daemon

, - transmiss-daemon.





$ sudo apt update && sudo apt upgrade -y && sudo apt install -y transmission-daemon
      
      



transmiss-daemon. ,  , ,    - . transmission-daemon .





$ sudo systemctl stop transmission-daemon.service 
      
      



/etc/transmission-daemon/settings.json



, . ,  . /media



/media/torrent/downloads



/media/torrent/complete







$ mkdir -p /media/torrent/{downloads,complete}
      
      



debian-transmission





$ sudo chown -R debian-transmission:debian-transmission /media/torrent
      
      



transmission. , /etc/transmission-daemon/settings.json



. ,





  • "download-dir": "/var/lib/transmission-daemon/downloads"



     -    , /media/torrent/complete







  • "incomplete-dir": "/var/lib/transmission-daemon/Downloads"



    -      , /media/torrent/downloads







  • "incomplete-dir-enabled": false



     - true



      





  • "rpc-authentication-required": true



    - false



    ,





  • "rpc-host-whitelist-enabled": true



     - false



    " ip-"





  • "rpc-password": "{a3edc70552a46d634e81ad9fabca6f51f9303197F8.No4L4"



     - , . , transmiss-daemon  





  • "rpc-username": "transmission"



     -





  • "rpc-whitelist-enabled": true



     - -  ip- true



    false







  transmission





sudo systemctl start transmission-daemon.service
      
      



web- transmission ip- 9091, 192.168.31.5:9091







transmission web interface
web- transmission

transmission   NGINX





NGINX

nginx,   nginx





sudo apt install -y nginx-full
      
      



 ,   ip-





Welcome message from Nginx
Nginx

nginx.    /etc/nginx/*



. /etc/nginx/nginx.conf







nginx.conf
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;

events {
        worker_connections 768;
}

http {
        sendfile on;
        tcp_nopush on;
        types_hash_max_size 2048;

        include /etc/nginx/mime.types;
        default_type application/octet-stream;

        access_log /var/log/nginx/access.log;
        error_log /var/log/nginx/error.log;


        include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/home.conf;
}
      
      



/etc/nginx/sites-enabled/home.conf







home.conf
server {
        listen 80;

        root /var/www/home;

        server_name home.ru;

        location / {
                index index.html;
                try_files $uri $uri/ =404;
        }
}
      
      



  . listen 80



, root /var/wwww/home



root html    .





html page downloaded from the internet
html

192.168.31.5    home.ru



/etc/hosts



   home.ru home.conf server_name home.ru







transmission-daemon  nginx

NGINX  , web- transmisson http://home.ru/transmission/



. /etc/nginx/sites-enabled/home.conf



location



   home.ru/transmission/



127.0.0.1:9091







location transmission
        location /transmission/ {
                proxy_pass http://localhost:9091 ;
        }
      
      



transmission-daemon asks for X-Transmission-Session-Id
transmission-daemon X-Transmission-Session-Id

, transmission X-Transmission-Id



. , 2 location transmission.





home.conf
server {
        listen 80;

        root /var/www/home;

        server_name home.ru;

        location / {
                index index.html;
                try_files $uri $uri/ =404;
        }

        location /transmission/ {
                proxy_read_timeout 300;
                proxy_pass_header  X-Transmission-Session-Id;
                proxy_set_header   X-Forwarded-Host $host;
                proxy_set_header   X-Forwarded-Server $host;
                proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_pass         http://127.0.0.1:9091/transmission/web/;
        }

        location /rpc {
                proxy_pass         http://127.0.0.1:9091/transmission/rpc;
        }
       
        location /upload {
                proxy_pass         http://127.0.0.1:9091/transmission/upload;
        }
}
      
      



transmission earned
transmission

, Samsung avi,   . ,  —  ,   . mkv .    bash transmission-daemon . , . -  ,   . ,      DNLA , , . , , avi ffmpeg



, mkv , - , /tmp . ,  ,   , . ,





download.sh
#!/bin/bash
COMPLETE="___"
CHAT_ID="__"
TELEGRAM_BOT="___"

#   
dir () {
        #   
        mkdir $COMPLETE/$TR_TORRENT_NAME
        #     
        for movie in $(ls $TR_TORRENT_DIR/$TR_TORRENT_NAME)
        do
                #  
                if [[ $movie == *avi ]]; then
                        #   mkv
                        ffmpeg -i $TR_TORRENT_DIR/$TR_TORRENT_NAME/$movie $COMPLETE/$TR_TORRENT_NAME/$movie.mkv
                #  mkv
                elif [[ $movie == *mkv ]]; then
                        #    
                        mv $TR_TORRENT_DIR/$TR_TORRENT_NAME/$movie $COMPLETE/$movie
                #  ,    /tmp
                else
                        mkdir /tmp/$TR_TORRENT_NAME
                        mv $TR_TORRENT_DIR/$TR_TORRENT_NAME/$movie /tmp/$TR_TORRENT_NAME/$movie
                        echo -e "$movie\n  .   \n/tmp/$TR_TORRENT_NAME/$movie" >> /tmp/$TR_TORRENT_NAME.message
                fi
        done
        echo -e "\n$TR_TORRENT_NAME\n" >> /tmp/$TR_TORRENT_NAME.message
}

#   
file () {
        #    
        if [[ $TR_TORRENT_DIR/$TR_TORRENT_NAME == *avi ]]; then
                #
                ffmpeg -i $TR_TORRENT_DIR/$TR_TORRENT_NAME $COMPLETE/$TR_TORRENT_NAME.mkv
        elif [[ $TR_TORRENT_DIR/$TR_TORRENT_NAME == *mkv ]]; then
                #
                mv $TR_TORRENT_DIR/$TR_TORRENT_NAME $COMPLETE/$TR_TORRENT_NAME
        else
                mkdir /tmp/$TR_TORRENT_NAME
                mv $TR_TORRENT_DIR/$TR_TORRENT_NAME /tmp/$TR_TORRENT_NAME/$TR_TORRENT_NAME
                echo -e "\n$TR_TORRENT_NAME\n    " >> /tmp/$TR_TORRENT_NAME.message
        fi
        echo -e "\n$TR_TORRENT_NAME\n" >> /tmp/$TR_TORRENT_NAME.message
}

send_message () {
        curl https://api.telegram.org/bot$TELEGRAM_BOT/sendMessage?parse_mode=markdown -d chat_id=$CHAT_ID -d text="$(</tmp/$TR_TORRENT_NAME)"
}

if [[ -d $TR_TORRENT_DIR/$TR_TORRENT_NAME ]]; then
        dir
else
        file
fi
send_message

#     
rm -rf $TR_TORRENT_DIR/$TR_TORRENT_NAME
rm -rf /tmp/$TR_TORRENT_NAME.message
      
      



, ,  .iso  .    , , . ,   , . . ,    , transmission





sudo mv download.sh /etc/transmission-daemon/ 
      
      







sudo chmod +x download.sh
      
      







sudo chown debian-transmission:debian-transmission /etc/transmission-daemon/download.sh
      
      



transmission-daemon  





sudo systemctl stop transmission-daemon
      
      



   2 /etc/transmission-daemon/setings.json







  • "script-torrent-done-enabled": false





  • "script-torrent-done-filename": ""





done-enabled



true, -   ,  done-file



, transmission, .





"script-torrent-done-enabled": true,
"script-torrent-done-filename": "/etc/transmission-daemon/download.sh",
      
      



 

   DNLA minidlna. ubuntu, .





sudo apt install -y minidlna
      
      



/etc/minidlna.conf



, , ,





  • media_dir=A,/media/gerbera/music







  • media_dir=P,/media/gerbera/photo







  • media_dir=V,/media/gerbera/movie







   minidlna





db_dir=/var/cache/minidlna
      
      







log_dir=/var/log/minidlna
      
      







friendly_name=Home_Media
      
      







sudo systemctl restart minidlna
      
      







samba .   , , ) , OpenWRT  , .    , bash   , , .    cron. , . Wildberries . C++that will take the link to view from the database and look at the price. If the price recorded in the database is higher, then send a message in the same telegram that the value of such and such a product has changed. And for various experiments and training, you can raise a virtual machine to the server and pick it up. There is also an idea to implement some kind of TV recording. We don't have regular TV, we only have 1 XD channel, and my wife watches several programs. I think it's easy to set up recording them to the same media server. But all these are plans, there is not much desire for fulfillment.





PS

This is the first time I write such a long text, and in general, the first time I write somewhere alongside private messages. Do not judge strictly.








All Articles