📜 ⬆️ ⬇️

Media Magic: Customization

Article on setting up Mediasika. What is it - you can read here
image

Details under the cut.


1. Install the torrent client rtorrent
There are several ways to install applications in Ubuntu. For example, you can use the Synaptic graphical client, or you can start the installation process from the console. We will go the second way, because, firstly, it is easier to describe, and secondly, it is always useful to be able to use the console. Moreover, we will have to contact her more than once (we're in Linux, whatever one may say).
To start, start the terminal, if it is not already running. And copy this line there:
sudo apt-get install rtorrent 

For beginners in brief explain what it means. "Sudo" means that the command needs to be run with administrator privileges. "Apt-get" is a console client for installing applications. “Install” is a command to the “apt-get” client, reporting the need to “install” an application. rtorrent, respectively, the name of the application that we install.
Another little advice for those who are just starting to deal with Linux - in the console it is very convenient to use the TAB button, which “appends” commands / paths / etc and displays their list if there is more than one option for writing. For example, you can type the command like this: sudo apt-g [TAB] i [TAB] rto [TAB]
Ok, typed the command, entered the password, the installation started. Apt-get will ask if you are sure of what you are doing. Click "D" (or just Enter) and the installation will go on. Ok, we installed the app. To check in the console, we write: rtorrent
press Enter and the rtorrent interface should appear in front of us.
Ok super. Everything is working. Press Ctrl + q to exit the application.
')
2. We configure rtorrent
In the beginning we will create directories with which we will work. In the console, this is done with the mkdir command and specifying the directory we want to create.
Accordingly, we write in the console:
 mkdir ~/torrents mkdir ~/.rtorrent-session mkdir /var/lib/mythtv/videos/downloads 

"~" Is an abbreviation in Linux, indicating the path to your home directory.
So, we created a “torrents” directory in which we will have torrent files, a “.rtorrent-session” directory in which rtorrent will store its session and a “downloads” directory in which rtorrent will download movies.
The rtorrent settings are stored in a file called .rtorrent.rc, which is stored in your home directory. But when you install the application, such a file is not created, so first we have to create it. We write in the console: nano ~/.rtorrent.rc
a console text editor opens with empty content.
Insert the following lines there: download_rate = 1000
upload_rate = 100

directory=/var/lib/mythtv/videos/downloads
session=/home//.rtorrent-session

schedule = u_night_mode,02:00:00,24:00:00,upload_rate=0
schedule = u_day_mode,07:00:00,24:00:00,upload_rate=100
schedule = d_night_mode,02:00:00,24:00:00,download_rate=0
schedule = d_day_mode,07:00:00,24:00:00,download_rate=1000
schedule = low_diskspace,5,60,close_low_diskspace=100M

schedule = watch_directory,10,10,load_start=/home//torrents/*.torrent

schedule = tied_directory,10,10,start_tied=
schedule = untied_directory,10,10,stop_untied=

schedule = ratio,60,60,"stop_on_ratio=200,200M,2000"

# Maximum and minimum number of peers to connect to per torrent
min_peers = 20
max_peers = 40

# Maximum number of simultanious uploads per torrent
max_uploads = 5

encryption = allow_incoming,enable_retry,prefer_plaintext
port_range = 55558-55558

scgi_port = :5000
encoding_list = UTF-8
umask = 0000
download_rate = 1000
upload_rate = 100

directory=/var/lib/mythtv/videos/downloads
session=/home//.rtorrent-session

schedule = u_night_mode,02:00:00,24:00:00,upload_rate=0
schedule = u_day_mode,07:00:00,24:00:00,upload_rate=100
schedule = d_night_mode,02:00:00,24:00:00,download_rate=0
schedule = d_day_mode,07:00:00,24:00:00,download_rate=1000
schedule = low_diskspace,5,60,close_low_diskspace=100M

schedule = watch_directory,10,10,load_start=/home//torrents/*.torrent

schedule = tied_directory,10,10,start_tied=
schedule = untied_directory,10,10,stop_untied=

schedule = ratio,60,60,"stop_on_ratio=200,200M,2000"

# Maximum and minimum number of peers to connect to per torrent
min_peers = 20
max_peers = 40

# Maximum number of simultanious uploads per torrent
max_uploads = 5

encryption = allow_incoming,enable_retry,prefer_plaintext
port_range = 55558-55558

scgi_port = :5000
encoding_list = UTF-8
umask = 0000


Do not forget in two places to replace “your name” with your name in the system (that is, the path to your home directory)

Now I will describe what all these settings mean:
download_rate, upload_rate - limit the speed of downlower and applode, respectively. In kilobytes.
directory - directory for saving downloaded files
session - directory needed by rtorrent to save download sessions

schedule = u_night_mode, 02: 00: 00,24: 00: 00, upload_rate = 0
schedule = u_day_mode, 07: 00: 00,24: 00: 00, upload_rate = 100
schedule = d_night_mode, 02: 00: 00,24: 00: 00, download_rate = 0
schedule = d_day_mode, 07: 00: 00,24: 00: 00, download_rate = 1000
These four lines say that from 7 am to 2 nights you need to limit the speed to 1000/100 kbps (down / up), and from 2 nights to 7 am to work without speed limits.

schedule = low_diskspace, 5.60, close_low_diskspace = 100M
This means that once a minute you need to check if the place on the hard drive is running out and stop all downloads if less than 100 megabytes are left.

schedule = watch_directory, 10,10, load_start = / home / yourname / torrents / *. torrent
every 10 seconds check if new torrent files appeared in this directory

schedule = tied_directory, 10,10, start_tied =
Start download if a new torrent file has appeared

schedule = untied_directory, 10,10, stop_untied =
Stop the download if the torrent file is deleted

schedule = ratio, 60,60, "stop_on_ratio = 200,200M, 2000"
Stop the download if its rating is> = 2.00, while more than 200Mb have been added OR rating> = 20.00

min_peers, max_peers - the minimum and maximum number of peers per torrent. To be honest, I don’t understand what “min peers” means
max_uploads - the maximum number of applause per torrent
encryption
port_range - port. do not forget to forward the port on the DSL modem / router, by the way.

scgi_port - the port on which the web client (which we later deliver) will work with rtorrent
encoding_list - encoding
umask - default rights mask

More information about these or other settings can be read on the website rtorrent

And we save the file (Ctrl + o, Enter) and exit the editor (Ctrl + x)

we start rtorrent, we throw some torrent file in the ~ / torrents / directory, we check that everything works. The download should start and the download file will appear in the videos / downloads directory. Hooray.

3. We learn rtorrent to work in the background and start automatically.
At the same time let's overcome one bug with hanging up the rtorrent.
At the beginning we put the screen:
 sudo apt-get install screen 


Next, create a directory and scripts to run:
 mkdir ~/bin nano ~/bin/myrtorrent.sh 


Inside we write

 #!/bin/bash PROGRAM="/usr/bin/rtorrent" GRACE_DELAY=15 while true; do "$PROGRAM" RETURNED=$? if [ $RETURNED -ne 0 ] then echo "$PROGRAM did not exit cleanly with status code $RETURNED" echo "pausing for $GRACE_DELAY seconds before restarting $PROGRAM" sleep $GRACE_DELAY; else echo "$PROGRAM exited cleanly. It will not be restarted automatically" exit 0 fi done 

save, exit (ctrl + o, Enter, ctrl + x)
we write in the console
 >nano ~/bin/checkrtorrent.sh 

In the editor we write:
 #!/bin/sh if [ `pgrep myrtorrent|wc -l` -lt 1 ]; then if [ ! "$(pidof rtorrent)" ] then echo "Not running. Starting\n" /usr/bin/screen -fa -d -m -S rtorrent /home//bin/myrtorrent.sh fi fi 


do not forget to change "your name" to your name in the system. Save, exit.

Thus, we have created several scripts that run rtorrent in the background and make sure that it starts successfully.

Now we will make these scripts run. First, let's make them "runnable"
 chmod +x ~/bin/checkrtorrent.sh chmod +x ~/bin/myrtorrent.sh 

we put scripts in the task scheduler
 crontab -e 


crontab is an application that starts other applications at a certain point. When you first start, he will ask what text editor we want to use. "3 - nano", of course, we will answer. OK. See the nano with the following content:
 # mh dom mon dow command 

Very good. Now we enter the text we need in the line below.
 */10 * * * * /home//bin/checkrtorrent.sh 

just do not forget to replace your name with your name in the system.
Ctrl + o, Enter, Ctrl + x. You can reboot the system to check that everything is working.
To do this, after a reboot, we wait a few minutes (the script is triggered once every 10 minutes) and type in the console
 screen -r 

after that the rtorrent interface should appear. To exit rtorrent, but leave it running in the background DO NOT CLICK ON Ctrl + q, but instead press "Ctrl + a" and then "d". the program will continue to work.
At any time you can see what is happening with you by typing “screen -r” and exit by pressing “ctrl + a, d”

4. Install the necessary Mediagic scripts for the scripts.
we write in the console
 sudo apt-get install php5-cli php5-curl php5-gd php5-imap 


5. Install the scripts themselves. Fix config.xml

Download the archive with the scripts and unzip it on your computer with Windows (or whatever you have). I propose to edit it on your computer, and not on the media center, because it’s so faster
Open and see several folders and files. Open the config.xml file from the root.
Begin to carefully fill in the values.
Leave the verbose, system_encoding values ​​as they are
We reach the group of parameters
 <mediagic_db> <server>localhost</server> <username>mythtv</username> <password>__</password> <db_name>mediagic</db_name> </mediagic_db> 

Open the console on the media center. Typing
 cat /etc/mythtv/mysql.txt|grep DBPassword 

This tricky command will allow us to see the generated password from the MythTV database. Enter this password in the password field.

The next parameter we are interested in is called user_agent.
Previously, it was possible to do without this parameter. user_agent is the name of your browser in which you are authorized on the tracker. We need a browser name and cookies. In order to rip out the value of cookies, I recommend using the Opera browser (for sure, the value of cookies can be viewed in other browsers, but I don’t know how, because I use Opera).
So we go to the tracker from the opera, enter the login-password (if not yet authorized), then go to the website whatsmyuseragent.com (you will need the Internet).
All this can be done from your desktop computer, and not from the media center.
The site will show us some amount of information, at the very beginning you can read:
Your User Agent is:
Opera / 9.80 (Macintosh; Intel Mac OS X; U; en) Presto / 2.2.15 Version / 10.00
or something like that. Most likely you will have Opera / 9.80 written (Windows; something there)
Copy the contents of the line (starting with the word Opera) into the buffer and paste it into the xml file instead of the value specified there.
The next parameter we are interested in is called "coverarts"
Open the console on the media server and write:
 mkdir ~/.mythtv/MythVideo/ 

Go back to the configuration file and write:
 <coverarts>/home//.mythtv/MythVideo/</coverarts> 

Of course, replacing "yourname" in your name in the system.
look further. trash. Ok, I suggest using a system basket for this, but you can also use any other folder. The system basket is here.
 <trash>/home//.local/share/Trash/files/</trash> 

as always, replacing your name with your name in the system.
The next group of values ​​that interests us is called mythtv
We do not change anything here, just write the same password that we wrote in the mediagic_db / password field above.

Next comes the email setup block, but I suggest not to touch it and configure it later.

6. Edit trackers / tracker. * Tracker name * .xml

Open the file.
Open Opera. Open your favorite tracker in the opera. Click the right button and select "Edit Site Preferences / Site Settings." Select the "Cookies" tab. Below is a list of variables and values. By double-clicking on each of the values, you can open it in a new window and copy it. Gently fill all the parameters from the xml-file to get something like
 <cookies> <phpbb3_cqeo2_u>1</phpbb3_cqeo2_u> <phpbb3_cqeo2_k></phpbb3_cqeo2_k> <phpbb3_cqeo2_sid>a3ac2ae1232c43237eac4183726370ac</phpbb3_cqeo2_sid> <uid>1234</uid> <pass>2abc8bf34fb7b2948dc38749cc2cacbc</pass> <PHPSESSID>b55476116f38bcd5a91e22dc6280e4ee</PHPSESSID> <session>a3f616f38bcd58ab16f8bcd54916f8bc563</session> <mybbuser>1234_iUn9kednIu8Jd7wOjw09JHw672lJkwdjhfwJhdeU63Jdg22hsdjciIh7HdgeY7t</mybbuser> <hsdn_top>1</hsdn_top> </cookies> 


Next, change the value of minimum_number_of_seeds to the one that interests us.
We put in filters / decline filters that we don’t want to download under any circumstances.
Specify max_size and min_size.
Change directories / torrents_dir to the value we need
 /home//torrents/ 

Do not forget to replace your name, then change the value of directories / datafiles_dir to
 var/lib/mythtv/videos/downloads/ 

As a result, it looks like this for me:

 <directories> <!-- ,     ---> <!-- ! -       -   --> <torrents_dir>/home/vadim/torrents/</torrents_dir> <!-- ,   -  --> <datafiles_dir>/var/lib/mythtv/videos/downloads/</datafiles_dir> </directories></code> 


7. Edit scrubbers / scrubber * tracker name * .xml.

Copy the entire block of cookies from the previous file and paste it in the appropriate place here.
Despite the fact that it may seem folly to write 2 times the same thing in different places, this has a definite meaning. Let me briefly tell you how it all works and what the files listed above are responsible for.
Files located in trackers / are responsible for working with trackers. You can create the file trackers / torrents.ru.xml, prescribe the necessary values ​​there and Mediagik will work also with torrents.ru.
Files lying in scrubbers / are responsible for downloading information about the film. Since in the case of a local tracker we take the information directly from the torrent description, it turns out that the place where we download the torrent files and where we get the information is the same site. But it may turn out that we want to download movies with PirateBay or torrents.ru, and take information about them from film searches or from the same local torrents. Or, on the contrary, somehow it turns out that the place from where we download movies and the place from which we take information is not always the same, just in our particular case it is the same site.

8. Install the scripts and deploy the base.
Copy the entire mediagic folder with all the corrected config files to the media server. I recommend copying them to / var / www. To do this, first copy the folder to anywhere, for example, in your home directory, and then write from the console
 sudo mv ~/mediagic /var/www/ 

We type the password and the vulya are the scripts there.
Now let's create a database.
typing in the console

 mysql -u root -p 

enter your password and get inside MySQL.
 vadim@vadim-vmware:~$ mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 135 Server version: 5.0.75-0ubuntu10.2 (Ubuntu) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> 


We write the following:
 GRANT ALL ON *.* TO 'mythtv'@'localhost'; 


We return to the standard console.
For further work, we will need a password, which we found out when config.xml was ruled.
recruit
 mysql -u mythtv -p 

and enter this generated password from the database. We fall back into mysql but already under the user "mythtv". We write:
  create database mediagic; SHOW DATABASES; 


as a result, we should see 4 databases
 mysql> create database mediagic; Query OK, 1 row affected (0.00 sec) mysql> SHOW DATABASES; +--------------------+ | Database | +--------------------+ | information_schema | | mediagic | | mysql | | mythconverg | 

we write exit and we quit MySQL.
We write in the console:
 mysql --user=mythtv --password= mediagic < /var/www/mediagic/mediagic.sql 


replacing the “password” with the generated password from config.xml
Hooray. Database created.

9. Check that everything works
typing in the console
 php /var/www/mediagic/autodownload.php 

And carefully look at what the script produces. If everything is done correctly, then he will not give out any errors, but successfully download and write everything to the database. According to the results of the script, several new (but not yet downloaded) films should appear in Mythtv and new downloads in rtorrent.
I remind you that rtorrent can be viewed in the console by typing "screen -r" and exiting it by typing "Ctrl + a, d". To delete a download in rtorrent, select it with the buttons up and down and press 2 times Ctrl + d (the download will stop, but the partially downloaded file will remain).
MythTV can be run through Applications-> Audio and Video-> MythTV Frontend.
ten.
write in the terminal

 sudo touch /var/log/updatetorrents.log sudo chmod 777 /var/log/updatetorrents.log crontab -e 

and add another line to the bottom

 0 * * * * /usr/bin/php /var/www/mediagic/autodownload.php > /var/log/updatetorrents.log 


Now, once an hour, the media head will check whether new films have appeared, download them and save information to the MythTV database.

That's all for today. Next time, we will fight drivers and codecs, make MythTV beautiful, work with rtorrent through a beautiful web interface, screw the console, teach Mediagic to write and read mail, and also download TV shows that interest us into separate directories immediately after the appearance of at least one Sid on the tracker. In addition, the same Makar we will teach Mediagic download the expected releases as soon as they appear.

If you could not get something - write, let's figure it out. If you did everything exactly as I described - then there should be no problems, unless, of course, I have not described

Source: https://habr.com/ru/post/111956/


All Articles