youtube-dl

Written by pmd - - no comments

youtube-dl is a usefull packet to download youtube video through command line. GitHub.

List what to download

First step is to list what youtube video you wanna download and convert to mp3 file:

2 files to put on a web server which are:

  1. liste.txt which must be chmod 777 (index.php will write links in this file)
  2. index.php
<!DOCTYPE html>
<html>
<head>
<title>youtube-dl</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
width: 550px;
font-size: 75%;
}
p {
font-family: "Lucida Console", "Courier New", monospace;
white-space: nowrap
}
li {
font-family: "Lucida Console", "Courier New", monospace;
white-space: nowrap
}
hr {
border: 0;
border-bottom: 1px dashed #CCCCCC;
background: #FFFFFF;
}
input[type=text], select {
width: 80%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
border-radius: 4px;
box-sizing: border-box;
}

input[type=submit] {
width: 80%;
background-color: #4CAF50;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
border-radius: 4px;
cursor: pointer;
}

input[type=submit]:hover {
background-color: #45a049;
}

div {
border-radius: 5px;
background-color: #f2f2f2;
padding: 20px;
overflow:auto;
width: 500px;
}
</style>
</head>
<body>
<span style="white-space: nowrap">
<div>
<p>
<?php
if(isset($_POST['field1']))
{
$data = $_POST['field1'] . "\r\n";
$ret = file_put_contents('liste.txt', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
echo "There was an error writing this file.";
}
else {
echo "$ret bytes written to file.";
}
}
else {
echo "No post data to process.";
}
?>
</p>
</div>
<hr>

<div>

<p>Format to be respected:</p>
<ol>
<li>« https://www.youtube.com/watch?v=1YRW1QRKTBc »</li>
<li>« https://youtu.be/9cBtJYI6itg »</li>
<li>« https://soundcloud.com/hungry-music/nto-alter-ego »</li>
</ol>

<form action="index.php" method="POST">
<input type="text" id="fname" name="field1" placeholder="https://www.youtube.com/watch?v=1YRW1QRKTBc"><br />
<input type="submit" value="Submit">
</form>
</div>

<hr>

<div>
<p>Next link(s) to be downloaded and saved to mp3 files:</p>
<p>
<?php
echo nl2br(file_get_contents( "liste.txt" ));
?>
</p>
</div>

<hr>

<div>
<p>
Logs (last 200 lines): <br />
<?php
//echo nl2br(file_get_contents( "/path/to/history.txt" ));
echo nl2br(trim(implode("", array_slice(file("/path/to/history.txt"), -200))));
?>
</p>
</div>
</body>
</html>

Sources 1, 2

Secure input form

https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-http-basic-authentication/
http://www.htaccesstools.com/htpasswd-generator/

location ^~ /youtube-dl {
     auth_basic           "Иди на хуй мозгоёб!!!";
     auth_basic_user_file /path/to/.htpasswd;
     location ~ \.php$ {
         include snippets/fastcgi-php.conf;
         fastcgi_pass unix:/run/php/php7.0-fpm.sock;
         }
 }

Restart nginx:

$ sudo service nginx restart

Download script

He depends on:

  • /path/to/liste_en_cours.txt
  • /path/to/history.txt
#!/usr/bin/bash
filename="$1"
liste_en_cours=/path/to/Downloads/youtube_auto/liste_en_cours.txt

cp -f $1 $liste_en_cours
sleep 1
echo -n > $1

echo "  " >> /path/to/Downloads/youtube_auto/history.txt
date >> /path/to/Downloads/youtube_auto/history.txt

while read -r line
do
    name="$(echo $line | sed 's/\r//g')"
    echo -n "$name | " >> /path/to/Downloads/youtube_auto/history.txt
    page="$(wget -O - $name)"
    echo $page | sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q' >> /path/to/Downloads/youtube_auto/history.txt

    /usr/local/bin/youtube-dl -f bestaudio $name --extract-audio --audio-format mp3 -o "/path/to/Downloads/youtube_auto/downloads/%(title)s.%(ext)s" | grep ffmpeg | grep mp3 | sed 's/.*\//===> /' | sed 's/mp3.*/mp3/' >> /path/to/Downloads/youtube_auto/history.txt

done < "$liste_en_cours"

mv -f /path/to/Downloads/youtube_auto/downloads/* /path/to/Music/youtube

#All big files goes to folder Mixes
for file in /path/to/Music/youtube/*; do
    SIZE="$(stat --printf="%s" "$file")"
    if (( $SIZE > 25000000 )); then
        mv -f "$file" /path/to/Music/Mixes
    fi
done

Source homemade. Now execute it with cron job by example.

 

Install Airsonic on Raspberry Pi 3

Written by pmd - - no comments

Stand-alone WAR installation integrated within systemd

Let's see how to install a stand-alone Airsonic on a Raspberry 3 integrated with Systemd.

First of all, we need Java to be installed:

$ sudo apt-get updateinstall openjdk-8-jre

By following these systemd setup instructions, Airsonic will be available at http://localhost:8080/airsonic.

  1. Setup dedicated airsonic user:
    $ sudo useradd airsonic
  2. Setup Airsonic data dir:
    $ sudo mkdir /var/airsonic
    $ sudo chown airsonic /var/airsonic
  3. Download the stand-alone WAR:
    $ sudo wget https://github.com/airsonic/airsonic/releases/download/v10.1.1/airsonic.war --output-document=/var/airsonic/airsonic.war
  4. Setup systemd service:
    $ sudo wget https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic.service -O /etc/systemd/system/airsonic.service
    $ sudo systemctl daemon-reload
    $ sudo systemctl start airsonic.service
    $ sudo systemctl enable airsonic.service
    $ sudo wget https://raw.githubusercontent.com/airsonic/airsonic/master/contrib/airsonic-systemd-env -O /etc/sysconfig/airsonic

    Note: On Debian systems you need to replace /etc/sysconfig with /etc/default)

  5. Go configure http://localhost:8080/airsonic.

Set up a reverse proxy: nginx

  1. Go edit nginx configuration:
    $ sudo nano /etc/nginx/sites-available/default
  2. location ^~ /airsonic {
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            #proxy_set_header X-Forwarded-Proto https;
            proxy_set_header Host $http_host;
            #proxy_max_temp_file_size 0;
            proxy_pass http://localhost:8080;
            #proxy_redirect http:// https://;
    }
  3. Restart nginx:
    $ sudo service nginx restart

Set up the transcoder

$ sudo apt-get install ffmpeg

Then we need to link Airsonic with the transcoder ffmpeg.

$ sudo mkdir /var/airsonic/transcode
$ cd /var/airsonic/transcode
$ sudo ln -s /usr/bin/ffmpeg /var/aisonic/transcode/ffmpeg
$ ls -alh
total 8.0K
drwxr-xr-x 2 airsonic airsonic 4.0K Jul 22 10:54 .
drwxr-xr-x 5 airsonic tomcat8  4.0K Jul 22 10:48 ..
lrwxrwxrwx 1 root     root       15 Jul 22 10:54 ffmpeg -> /usr/bin/ffmpeg
$ sudo chown -R airsonic:airsonic /var/airsonic
$ ls -alh
total 8.0K
drwxr-xr-x 2 airsonic airsonic 4.0K Jul 22 10:54 .
drwxr-xr-x 5 airsonic airsonic 4.0K Jul 22 10:48 ..
lrwxrwxrwx 1 airsonic airsonic   15 Jul 22 10:54 ffmpeg -> /usr/bin/ffmpeg

Interact with server from Android

I use the Ultrasonic application:
ultrasonic

Source 1, 2, 3,

Extra applications on LEDE (GL-AR150)

Written by pmd - - no comments

Transmission

  1. opkg update
  2. opkg install transmission-daemon-openssl transmission-web luci-app-transmission
  3. opkg install nano
  4. nano /etc/config/transmission
  5. chmod -R 777 /tmp/USB_KEY

It is necessary to make a swap file on AR150 otherwise you cannot access the web interface...

  1. cd /path/where/we/will/make/swap-file
  2. Create a 64MB swap-file:
    dd if=/dev/zero of=swap-file bs=1M count=64
  3. mkswap swap-file
  4. swapon swap-file
  5. Then go to LuCI to specify the swap file in System > Mount points to have it mounted at next router reboot.

For worldwide access add a rule in LEDE firewall:
Any tcp, udp
From any host in wan
To any router IP at port 9091 on this device

Source

Bandwidth Monitor (nlbw)

opkg install luci-app-nlbwmon

Aussi :

https://github.com/Kiougar/luci-wrtbwmon

LEDE/OpenWRT on GL-AR150

Written by pmd - - no comments

How to upgrade GL-AR150 to Stock OpenWRT

  1. Connect to router using SSH
  2. # cd /tmp
  3. Check what is the last available release for GL-AR150 here.
  4. # wget http://downloads.lede-project.org/releases/17.01.4/targets/ar71xx/generic/lede-17.01.4-ar71xx-generic-gl-ar150-squashfs-sysupgrade.bin
  5. # sysupgrade lede-17.01.4-ar71xx-generic-gl-ar150-squashfs-sysupgrade.bin

Source

I installed this version: LEDE Reboot (17.01.4, r3560-79f57e422d).

How to upgrade all packets

opkg list-upgradable | cut -f 1 -d ' ' | xargs opkg upgrade

Sources 1, 2

Enabling remote SSH access on LEDE/OpenWRT

Configure Dropbear

  1. Go to the System / Administration page.
  2. Under “SSH Access”, for the default “Dropbear instance”, set “Interface” to “unspecified”.

This will cause dropbear to accept connections on all interfaces.

Open port 22 (or other)

  1. Go to the Network / Firewall / Traffic Rules.
  2. Scroll down to the “Open ports on router” section.
  3. Enter a name for this rule, e.g. “Allow-SSH-WAN”.
  4. Set “Protocol” to “TCP”.
  5. Enter “22” as the “External Port”.
  6. Click “Add”.
  7. Click “Save and Apply”.

Source

Using USB storage devices and FAT32&NTFS filesystems

  1. Connect to router using SSH
  2. # opkg update
  3. # opkg install kmod-usb-storage
  4. # opkg install usbutils
  5. # lsusb -t
    /: Bus 01.Port 1: Dev 1, Class=root_hub, Driver=ehci-platform/1p, 480M
       |__ Port 1: Dev 2, If 0, Class=Mass Storage, Driver=usb-storage, 480M
  6. To add support of FAT32 and NTFS (not tested yet) usb flash/disk drives:
    # opkg install kmod-fs-vfat ntfs-3g
  7. Then go to the LuCI administration page, System > Mount points, and configure :

Sources 1, 2, 3, 4, 5

Using the Huawei E3372 Hi-Link LTE Dongle with OpenWRT

Huawei E3372 and AR-150 have 192.168.8.1/24 IPv4 networks, change the LAN IP of AR-150.

  1. # opkg update && opkg install kmod-usb-net-rndis usb-modeswitch
    Of course, an internet connection is needed through Ethernet or Wifi for this step. :(
  2. Then go to the LuCI administration page, Network > Interfaces > Add new interface...:
  3. In my case interface "eth2" is now available to configure:
  4. In tab Firewall Settings, add this new interface in the wan firewall-zone:
  5. Click on Connect of the new network 4G_LTE:
  6. Done, you even have access to the USB dongle administration page 192.168.8.1.

Source Nouvelle source (2020-02)

DDNS

  1. # opkg install luci-app-ddns
  2. Go to LuCI administration interface > Services > Dynamic DNS.
  3. I used a Free DNS provider named freedns.afraid.org.

Source

Samba network share

  1. # opkg install luci-app-samba
  2. Go to LuCI administration interface > Services > Network Shares.
  3. Add shared directories:
    • Name: samba
    • Path: /Path/to/mounted/usb/key
    • Allowed user: empty
    • Create mask: 777
    • Directory mask: 777

Source

SFTP server

  1. # opkg update && opkg install openssh-sftp-server
  2. Use Filezilla or other to connect to sftp server.

Source

Backup ftp server

Written by pmd - - no comments

Information from shellhacks.com.

Download

The following command recursively downloads your site with all its files and folders from FTP server and saves them to the current directory.

wget -r -l 0 -nH -X folder_to_skip ftp://user:pass@ftp.server.com

 

option description
user FTP username
pass FTP password
ftp.server.com IP address or domain name of an FTP server
-r Recursive retrieving
-l Maximum recursion depth (0 = unlimit) (default = 5)
-nH Disable generation of host-prefixed directories
-X exclude a list of directories

Backup

Now you can compress the folder with your site as follows:

tar -czf site-backup-$(date +%Y%m%d-%H%M%S).tar.gz yoursite.com

Install pluxml on raspberry pi

I am using nginx + php7 + pluxml followinf these two links:

  1. https://www.raspberrypi.org/documentation/remote-access/web-server/nginx.md
  2. https://blog.norore.fr/index.php?article13/pluxml-nginx-et-php-7-sont-dans-un-bateau
Rss feed of the category