YouTube Support (Search and Play)

Suggestions/requests/ideas for RuneAudio core features and functions

Re: YouTube Support (Search and Play)

Postby tuna » 30 Oct 2016, 18:07

NOTE: This addon can now be installed automatically as part of Addons Menu

Hi I've extended wave's mod.
  • Added youtube button to playlist
  • Adds youtube files to the media library for playback later
  • Accepts youtube playlists
  • Converted the bash script to run in the background (Rune no longer freezes when downloading)

Image

Create /srv/http/youtube.php
Code: Select all
<?php
try {
   set_time_limit(0);
   ini_set('max_execution_time', 600);
    $u = urldecode($_GET['url']);
    #validate
    $youtube = "/^(https:\/\/|http:\/\/|)(www\.|m\.|)(youtube\.com\/watch\?v=|youtu\.be\/)[\w-]+$/";
    $playlist ="/^(https:\/\/|http:\/\/|)(www\.|m\.|)(youtube\.com\/playlist\?list=|youtu\.be\/)[\w-]+$/";
   
    if ( preg_match ($youtube, $u ) )
    {
      exec("tube " . $u );
      echo "sent song" . $u;
   }
    if(preg_match($playlist, $u))
   {
      exec("tubeplaylist " . $u . " >/dev/null 2>&1 &");
      echo "sent playlist" . $u;
   }
}    
catch (Exception $e) {
    echo "Exception :  ", $e->getMessage(),"<br />";
}
?>


Create /usr/local/bin/tube
Code: Select all
#!/bin/bash
youtube-dl --no-mtime --restrict-filenames -o '/mnt/MPD/LocalStorage/Youtube/%(title)s.%(ext)s' --write-description -f "bestaudio[ext=m4a]" $1 && mpc update --wait LocalStorage/Youtube && VV=$(ls /mnt/MPD/LocalStorage/Youtube/*.description -t | head -n1) && VV=$(basename $VV .description) && mpc add "LocalStorage/Youtube/$VV.m4a" && echo $VV && chown -R http:http /mnt/MPD/LocalStorage/Youtube/$VV.*


Create /usr/local/bin/tubeplaylist
Code: Select all
#!/bin/bash
youtube-dl --no-mtime --restrict-filenames --ignore-errors -o '/mnt/MPD/LocalStorage/Youtube/%(title)s.%(ext)s' --write-description -f "bestaudio[ext=m4a]" $1 && mpc update --wait LocalStorage/Youtube

(IFS='
'
for x in $(find /mnt/MPD/LocalStorage/Youtube/ -type f -name *.description -mmin -15); do VV=$(basename "$x" .description) && mpc add "LocalStorage/Youtube/$VV.m4a" && echo $VV; done)
#Find all descriptions less than 15 min modifcation time then add to playlist


Edit /srv/http/app/templates/playback.php

Find:
Code: Select all
<div id="pl-manage">
                <button id="pl-manage-list" class="btn btn-default" type="button" title="Manage playlists"><i class="fa fa-file-text-o"></i></button>
                <button id="pl-manage-save" class="btn btn-default" type="button" title="Save current queue as playlist" data-toggle="modal" data-target="#modal-pl-save"><i class="fa fa-save"></i></button>

Add this line after:
Code: Select all
<button id="yt-inport" class="btn btn-default" type="button" title="Import a playlist or video from youtube."><i class="fa fa-youtube-play"></i></button>


Edit /srv/http/assets/js/runeui.js
Find:
Code: Select all
        // LIBRARY
        // ----------------------------------------------------------------------------------------------------
       
        // on ready Library tab

Add ABOVE
Code: Select all
      $('#yt-inport').click(function(){
        var stream = prompt("Enter youtube video or playlist URL", "");
        if (stream != null) {
         var encstream = encodeURI(stream);  //url encode
         encstream = encodeURIComponent(encstream); //encodes also ? & ... chars
         $.get("youtube.php?url=" + encstream);
         return false;
        }     
      });
       


Create folder
Code: Select all
mkdir /mnt/MPD/LocalStorage/Youtube


Run these shell commands
Code: Select all
pacman -Sy
pacman -S glibc
pacman -S openssl
pacman -S youtube-dl
chmod 777 /usr/local/bin/tube
chmod 777 /usr/local/bin/tubeplaylist
chmod 777 /srv/http/youtube.php

chown http:http /srv/http/youtube.php
chown http:http /usr/local/bin/tube
chown http:http /usr/local/bin/tubeplaylist
chown http:http /mnt/MPD/LocalStorage/Youtube


Clear rune cache
http://[your rune name]/clear

Note: By default the rune partition is 2gb (with 40mb free space)... I recommend resizing this or you can only store 10 songs.
Last edited by tuna on 14 Nov 2017, 11:03, edited 5 times in total.
tuna
 
Posts: 18
Joined: 30 Oct 2016, 17:39

Re: YouTube Support (Search and Play)

Postby waves » 03 Nov 2016, 22:31

Way to go tuna! :) I will test your version when I have some spare time but these look to be very nice improvements. Your youtube button is more user friendly than my shortcut. And the youtube playlist feature will come in handy.
waves
 
Posts: 125
Joined: 31 Dec 2014, 10:33

Re: YouTube Support (Search and Play)

Postby Kakaomonster » 24 Nov 2016, 10:46

Hey tuna,

thanks for this great work, I like it :-)

BUT, I make step by step and the first video was perfect, but after that nothing goes on. I can put in what I want from youtube, but no download will be starting.

Did you have any idea? I can't found the mistake. I go step by step your tutorial again and again and make double check for every thing, but it don't works again.

I hope you can help me,

regards, Kakaomonster - Ralf
Kakaomonster
 
Posts: 5
Joined: 24 Nov 2016, 01:22

Re: YouTube Support (Search and Play)

Postby hondagx35 » 24 Nov 2016, 16:55

Hi Ralf,

please check the free space on your SD card (/dev/root).
You can do this by reading the debug data (Menu->Debug).
Code: Select all
###### Filesystem mounts - free space (df -h) ######
Filesystem             Size  Used Avail Use% Mounted on
/dev/root              7.1G  2.3G  4.6G  33% /
devtmpfs               457M     0  457M   0% /dev
tmpfs                  462M     0  462M   0% /dev/shm
tmpfs                  462M   12M  450M   3% /run
tmpfs                  462M     0  462M   0% /sys/fs/cgroup
tmpfs                  462M  780K  461M   1% /tmp
logs                   5.0M   28K  5.0M   1% /var/log
rune-logs              5.0M  276K  4.8M   6% /var/log/runeaudio
/dev/mmcblk0p1         100M   18M   82M  19% /boot
//192.168.0.106/Musik  266G  176G   90G  67% /mnt/MPD/NAS/Musik


Frank
User avatar
hondagx35
 
Posts: 3042
Joined: 11 Sep 2014, 22:06
Location: Germany

Re: YouTube Support (Search and Play)

Postby Kakaomonster » 24 Nov 2016, 17:01

Hallo Frank,

danke für die schnelle Antwort, aber wenn ich mich jetzt nicht vertan habe, sollte das mehr als genügend sein. Hier der Auszug:

Code: Select all
###### Filesystem mounts - free space (df -h) ######
Filesystem      Size  Used Avail Use% Mounted on
/dev/root       1.9G  1.8G   41M  98% /
devtmpfs        458M     0  458M   0% /dev
tmpfs           462M     0  462M   0% /dev/shm
tmpfs           462M   12M  450M   3% /run
tmpfs           462M     0  462M   0% /sys/fs/cgroup
tmpfs           462M  8.0K  462M   1% /tmp
logs            5.0M   24K  5.0M   1% /var/log
rune-logs       5.0M   60K  5.0M   2% /var/log/runeaudio
/dev/mmcblk0p1  100M   18M   83M  18% /boot
/dev/sda1       2.0T   37G  1.9T   2% /mnt/MPD/USB/sda1-usb-General_UDisk-0:
/dev/sdb1        15G   32K   15G   1% /mnt/MPD/USB/INTENSO


EDIT: Also ich habe keinen Plan was passiert ist, aber auf einmal klappt es einwandfrei. Dennoch eine Frage, kann es sein das immer nur ein Song geladen werden kann? Bei mehreren aus youtube gibt es Probleme? Und wäre es nicht noch möglich eine Fortschrittsanzeige einzubauen oder eine finish Anzeige? Irgend etwas, dass man erkennt, wann es fertig ist?

Egal wie, jedenfalls schon mal bisher eine super arbeit, danke an den Basler oder developer :-)
Kakaomonster
 
Posts: 5
Joined: 24 Nov 2016, 01:22

Re: YouTube Support (Search and Play)

Postby hpeter » 12 Feb 2017, 18:04

Hey everybody,

I tried to add youtube support to me rune audio installation as well.

I tried the version from tuna's post from 30 Oct 2016, 18:07. Unfortenatly it does not work for me.
I did everything how it was described in the post and doublechecked it all. After that I do get "play" button on the left botton of the "queue" page. But if I press the button, nothing happens. Do I have register it anywhere?

I am running rune audio on a Rasbperry Pi Zero in Version beta 0.3.

Hope anyone has a hint for me.
Tell me if you need any information!
hpeter
 
Posts: 12
Joined: 08 Jun 2016, 07:50

Re: YouTube Support (Search and Play)

Postby NOrion » 15 Mar 2017, 10:35

Hi, thanks for this.

The function doesn't work to me too. I tried the tutorial many times.
When i clicking on YT button there is no textbox to paste the link but the windows is fading to black.
Is it working now for someone ?

I think this kind of functionnality may be incorpored in the full version should be very interest (play only sound on jukebox)
User avatar
NOrion
 
Posts: 1
Joined: 15 Mar 2017, 10:23

Re: YouTube Support (Search and Play)

Postby tuna » 01 Apr 2017, 14:30

Hi, make sure you clear your rune cache (last step in the post)

Also make sure your Youtube-DL is running the latest version (2017.03.15)

Also your mobile browser needs to support JS popup dialog entries (see screenshot above)
tuna
 
Posts: 18
Joined: 30 Oct 2016, 17:39

Re: YouTube Support (Search and Play)

Postby tuna » 09 Jul 2017, 23:13

Upgrade to enter the Youtube url VIA a modal (Should now work on any mobile browser)
Image

Install as per the top post on page #3, note down the paths for the files:

In runeui.js find:
Code: Select all
// sort queue entries

Add before:
Code: Select all
      // save youtube to playlist
        $('#modal-pl-youtube-btn').click(function(){
            var playlistname = $('#pl-video-url').val();
            if (playlistname != null) {
             var encstream = encodeURI(playlistname);  //url encode
             encstream = encodeURIComponent(encstream); //encodes also ? & ... chars
             $.get("youtube.php?url=" + encstream);
        }   
        });


in playback.php find
Code: Select all
<div id="modal-pl-save" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal-pl-save-label" aria-hidden="true">

Add before
Code: Select all
<div id="modal-pl-youtube" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal-pl-youtube-label" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h3 class="modal-title" id="modal-pl-youtube-label">Import from youtube</h3>
            </div>
            <div class="modal-body">
                <label for="pl-video-url">Enter a video or playlist url</label>
                <input id="pl-video-url" class="form-control osk-trigger" type="text" placeholder="Enter url">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default btn-lg" data-dismiss="modal">Close</button>
                <button type="button" id="modal-pl-youtube-btn" class="btn btn-primary btn-lg" data-dismiss="modal">Import</button>
            </div>
        </div>
    </div>
</div>


Change
Code: Select all
<button id="yt-inport" class="btn btn-default" type="button" title="Import a playlist or video from youtube."><i class="fa fa-youtube-play"></i></button>

to
Code: Select all
<button id="pl-import-youtube" class="btn btn-default" type="button" title="Import a playlist or video from youtube." data-toggle="modal" data-target="#modal-pl-youtube"><i class="fa fa-youtube-play"></i></button>
tuna
 
Posts: 18
Joined: 30 Oct 2016, 17:39

Re: YouTube Support (Search and Play)

Postby tuna » 14 Nov 2017, 10:51

This addon can now be installed automatically as part of Addons Menu
Future releases will be made there for ease of installation/updating :D
tuna
 
Posts: 18
Joined: 30 Oct 2016, 17:39

support RuneAudio Donate with PayPal

PreviousNext

Return to Feature request

Who is online

Users browsing this forum: No registered users and 1 guest