[TUT] url to Kodi scripts for MacOS and Linux

Discussion in 'ZIDOO X9S' started by n_p, Jul 25, 2017.

  1. n_p

    n_p Active Member

    Its an easy concept, its a bit harder to get going - but once you've got it working it allows you to send direct video links from a Mac or Linux PC to Kodi and have them play straight away.

    What direct video links are we talking about? Most of them, really. :) You get them using Chrome or Firefox and the "Video Download Helper" plugin. Within Chrome you can set the plugin to be activated via a keyboard shortcut (when Chrome is running), which is recommended to get direct video links even faster. :)

    The idea is to have a direct video link copied into your clipboard - the script will then take it from there.

    Now to the prerequisite setup stuff.

    1. In Kodi - go to the settings (enable expert settings), services and webserver. Enable "allow control of Kodi via HTTP", set the port to 8087 (I've changed it from the default 8080, in case other apps would like to use the port, the script looks for 8087), dont set a password.

    2. Work out how to connect to the Android Box (f.e. X9S) via adb. This requires you to have the adb binary installed on your PC (google XDA adb quick installer, or install adb linux if on Linux), have adb (Android Debugging Bridge) enabled in the X9S' (Android-) Settings.
    And possibly even rooting the X9S and installing https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb (this is required if you connect to the X9S via Wifi - I'm currently unsure, if this is required if you connect to the X9S via Ethernet - all I know is, that I have it working - with Wifi ADB (app) installed and the X9S being rooted. Take some time to figure out how adb works (via commandline) get familiar with adb connect IP.ADD.RE.SS, adb devices, adb shell, adb disconnect - and other basic adb commands before you continue. adb is like "ssh for android devices" it basically allows you to get access to the command line on the android device.

    3. You have to have connected to your Android Box (X9S) via the command line and adb connect IP.ADD.RE.SS recently - so the IP address of the Android box shows up in the shell/terminal-history on your PC. The script will look up the most recent adb entry in your shell/terminal-history and connect to it again.

    I use this to switch devices also. I have small shell scripts that only include -

    adb connect IP.ADD.RE.SS
    adb disconnect

    to switch between different Android Boxes. Have one of them named livingroom.sh, bedroom.sh and so on and so forth. I leave it to you to find out exactly how to create (text editor) and run them, just make sure you have used chmod +x on the script files to make them executable. :)

    4. Create an empty file named clipboard.m3u in ~/Documents/zidoo/ on your PC (~/ stands for your home folder in MacOS and Linux).
    -

    Still with me? (Only the strong.. ;) )

    Now to the fun part.

    Code:
    eval $(history | cut -c 8- | grep "adb connect [0-9]" | tail -1)
    
    sleep 0.5
    
    set eof ~/Documents/zidoo/clipboard.m3u to 0
    
    pbpaste | sed 's,https://www.youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g'| pbcopy
    
    pbpaste | sed 's,http://www.youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g'| pbcopy
    
    pbpaste | sed 's,https://youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g'| pbcopy
    
    pbpaste | sed 's,http://youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g'| pbcopy
    
    pbpaste | sed 's,https://,http://,g'| pbcopy
    
    pbpaste | sed 's,&start=0,,g'| pbcopy
    
    pbpaste > ~/Documents/zidoo/clipboard.m3u
    
    adb push ~/Documents/zidoo/clipboard.m3u /sdcard/
    
    sleep 0.5
    
    adb shell am start -n org.xbmc.kodi/.Splash -a android.intent.action.VIEW
    
    #!/bin/bash
    XBMC_HOST="http://$(history | cut -c 8- | grep "adb connect [0-9]" | tail -1 | sed "s/[^0-9|\.]*//g"):8087"
    echo ${XBMC_HOST}
    curl --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"Player.Stop","params":{"playerid":1},"id":1}' "${XBMC_HOST}/jsonrpc"
    sleep 1
    curl --header "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"Player.Open","params":{"item":{"file":"/sdcard/clipboard.m3u"}},"id":1}' "${XBMC_HOST}/jsonrpc"
    
    adb disconnect
    
    killall Terminal
    The killall Terminal part in the last line is MacOS specific, all the other bash commands should be compatible with Linux as well.

    Save the code above as an .sh file (you can name it however you want), make it executable (chmod +x). Then run it - once you have a direct video link in your clipboard (on your PC).

    What the script does.

    - Looks into the Shell/Terminal history to find the last adb connect IP.ADD.RE.SS you've typed in there - then executes it again to adb connect to your Android Box (X9S).

    - Takes the link in the clipboard, makes a few replacements, in case it is a youtube video link (so Kodi launches them in the Youtube plugin) -

    - copies it to the ~/Documents/zidoo/clipboard.m3u file (the file gets blanked every time you run the script, so the links will not stack from the last time you used it)

    - copies the ~/Documents/zidoo/clipboard.m3u file over to the Android Box (X9S), using adb. (Every time you run the script the file on the Androud Box (located in /sdcard/) gets overwritten as well. So no "link stacking" there either.)

    - tells the Android Box (X9S) to launch Kodi (using adb).

    - tells Kodi to stop the current video (if none is playing - this does nothing)

    - tells Kodi to play the playlist file at /sdcard/clipboard.m3u - which the script just copied over - thereby instantly playing the direct video link contained in it. :)
    --

    On MacOS I use Applescript-Editor to create a little .app that launches the script upon activation.

    The code for the .app - should you "need it" simply is

    Code:
    tell application "Terminal"
        do script "~/Documents/zidoo/fcopyh.sh > /dev/null 2>&1 &"
    end tell
    tell application "System Events"
        tell application process "Terminal"
            set frontmost to true
            keystroke "h" using command down
        end tell
    end tell
    fcopyh.sh is my filename for the first script listed above. Make sure you dont forget to make it executable (chmod +x) like I told you before.
    -

    I also have a slightly modified version of it running with Kodi on a Raspberry Pi -

    Should you need some pointers for that - instead of adb you use scp with a little helper script containing:

    Code:
    #!/usr/bin/expect -f
    set bad_idea YOURRASPPISSHPASSWORD
    set timeout -1
    # now connect using ssh
    spawn scp /Users/YOURUSERNAME/Documents/zidoo/clipboard.m3u pi@192.168.1.103:/home/pi/
    expect "*?assword:*"
    send -- "$bad_idea\r"
    send -- "\r"
    expect elf
    save it as an .sh, make it executable - then execute this little script when you would adb push in the Android case -

    and then modify the /sdcard/ parts of the first script to point to /home/pi/ instead. :)

    Its a bit of a hack - as its NOT recommended to save your Pi's ssh password in plaintext in a script file - but, oh well... Its easier than the alternative (auth via synced key files). adb on Android doesnt require a password to authenticate, so we dont have that issue there. ;)
    -

    To the more geeky folks in here - have fun. :)

    n_p

    And if you dont think its worth it. It is. ;) (If you are using a PC/Laptop - while also having a TV with Kodi running.) But I'll not go into details. ;) (Hrmmm - what videos urls could you use it with I wonder... ;) )

    You can also make this work with Kodi forks like ZDMC, SPMC, FTMC. Just read the script closely and look for "kodi", then take some educated guesses and change where necessary. :)

    edit: Linux distros don't come with pbcopy and pbpaste - but your solution can be found here:
    https://superuser.com/questions/288320/whats-like-osxs-pbcopy-for-linux

    That said, because of it - the script above only works "out of the box" (with adb installed) on OSX now. Read the solution in the link and make it work for you on Linux though - shouldnt be too hard. :)
     
    Last edited: Aug 19, 2017
  2. HaoSs

    HaoSs Well-Known Member

    i will add this to the global tips and tricks guide, if you don't mind
     
  3. n_p

    n_p Active Member

    Fine with me. :)
     
  4. n_p

    n_p Active Member

    Linux distros don't come with pbcopy and pbpaste - but your solution can be found here:
    https://superuser.com/questions/288320/whats-like-osxs-pbcopy-for-linux

    That said, because of it - the script above only works "out of the box" (with adb installed) on OSX now. Read the solution in the link and make it work for you on Linux though - shouldnt be too hard. :)

    edit: To give Linux users a little help, for my (small ;) ) oversight - the easiest way to make the script working for you would be to take the two templates from the following posting: https://superuser.com/a/901550 - save them as two seperate files (one called pbcopy, one pbpaste - make sure they have no file extension (no .txt, no anything)), move them to /bin/ on your PC (this will require administrator permission), then open a shell, cd to /bin/ and sudo chmod +x both of those files individually. (This also requires administrator permission.) This should do it. :)

    Before you do this on Linux, make sure you have a little tool named xclip installed by default on your distro (open a shell, type xclip, enter - hope that you get no notification that tells you that it cant be found. :) ). If you are missing xclip,

    sudo apt-get install xclip

    will install it.
     
    Last edited: Jul 26, 2017
  5. n_p

    n_p Active Member

    Fun example of whats possible with the script above on a Macbook. :) (Apple only - sorry folks..)

    This script moves the last Chrome browser video to the front, clicks on the embeded video on an openload page (or a page with an embeded openlaod video) once to load it, then opens up Video DownloadHelper (via a Shortcut you have to set yourself in Chrome first, i've mapped it to ctrl+d in the script), then copys the video link of the first item in Video DownloadHelper, then checks if it is a openload direct video link, if not, it copies the link of the second item - then it starts the script from the first posting in here, to hand the link off to Kodi. :)

    That way, you never get "are you a human" checks - ever.. :)

    Code:
    -- set the x and y coordinates for the first, second and third click. set how many clicks at one position are performed (l)
    
    set v to {1, 525, 525, 540, 132, 540, 192}
    set {l, x, y, x1, y1, x2, y2} to v
    
    tell application "System Events"
    tell application process "Chrome"
    set frontmost to true
    end tell
    end tell
    
    -- click on the embedded video once (so the direct video link can be captured)
    
    do shell script "
    
    /usr/bin/python <<END
    import sys
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
              theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
              CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
              mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclick(posx,posy):
              mouseEvent(kCGEventLeftMouseDown, posx,posy);
              mouseEvent(kCGEventLeftMouseUp, posx,posy);
    ourEvent = CGEventCreate(None);
    currentpos=CGEventGetLocation(ourEvent);             # Save current mouse position
    for x in range(0, " & l & "):
              mouseclick(" & x & "," & y & ");
    mousemove(int(currentpos.x),int(currentpos.y));      # Restore mouse position
    
    END"
    
    -- Press ctrl + d to open up the Video DownloadHelper extension (shortcut has to be set for the extension in Google Chrome)
    
    tell application "System Events"
    tell application process "Chrome"
    set frontmost to true
    keystroke "d" using control down
    end tell
    end tell
    
    do shell script "sleep 0.1"
    
    -- click on the first video item that was captured, video link will be copied to the clipboard
    
    do shell script "
    
    /usr/bin/python <<END
    import sys
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
              theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
              CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
              mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclick(posx,posy):
              mouseEvent(kCGEventLeftMouseDown, posx,posy);
              mouseEvent(kCGEventLeftMouseUp, posx,posy);
    ourEvent = CGEventCreate(None);
    currentpos=CGEventGetLocation(ourEvent);             # Save current mouse position
    for x in range(0, " & l & "):
              mouseclick(" & x1 & "," & y1 & ");
    mousemove(int(currentpos.x),int(currentpos.y));      # Restore mouse position
    
    END"
    
    -- check if a link other than a playable link was captured, if so click on the second item box in Video DownloadHelper
    
    set check to the clipboard
    
    if {check starts with "http://openload" or check starts with "https://openload"} then
    
    tell application "System Events"
    tell application process "Chrome"
    set frontmost to true
    keystroke "d" using control down
    end tell
    end tell
    
    do shell script "sleep 0.1"
    
    do shell script "
    
    /usr/bin/python <<END
    import sys
    import time
    from Quartz.CoreGraphics import *
    def mouseEvent(type, posx, posy):
              theEvent = CGEventCreateMouseEvent(None, type, (posx,posy), kCGMouseButtonLeft)
              CGEventPost(kCGHIDEventTap, theEvent)
    def mousemove(posx,posy):
              mouseEvent(kCGEventMouseMoved, posx,posy);
    def mouseclick(posx,posy):
              mouseEvent(kCGEventLeftMouseDown, posx,posy);
              mouseEvent(kCGEventLeftMouseUp, posx,posy);
    ourEvent = CGEventCreate(None);
    currentpos=CGEventGetLocation(ourEvent);             # Save current mouse position
    for x in range(0, " & l & "):
              mouseclick(" & x2 & "," & y2 & ");
    mousemove(int(currentpos.x),int(currentpos.y));      # Restore mouse position
    
    END"
    
    end if
    
    -- open fcopy, now that a direct video link is in the clipboard
    
    tell application "Terminal"
    do script "~/Documents/zidoo/fcopyh.sh > /dev/null 2>&1 &"
    end tell
    
    tell application "Terminal"
    try
    get window 1
    end try
    end tell
    
    tell application "System Events"
    set visible of process "Terminal" to false
    end tell
    
    (You have to set your x and y positions for the first, the second and the potential third click at the top of the script for yourself.)

    The script can be copy/pasted into the Applescript Editor, and simply saved as an app. The app is supposed to be launched via Spotlight or Quicksilver or Alfred, while Chrome with an opened openload video page is in view.

    edit: Small fix for the http (not https) case.
     
    Last edited: Aug 19, 2017
  6. n_p

    n_p Active Member

    Made the applescript (in the thread above) a few seconds faster. :)

    Added a one second delay between the "open kodi" and "play m3u" commands, in the script in the first post (to make it work better in some situations where there is delay on part of the Android box.).
     
    Last edited: Aug 19, 2017
  7. paul lefebvre

    paul lefebvre New Member


    Voici un guide qui explique comment installer Kodi sur Linux de 3 façons différentes. Mais avant cela, obtenez Kodi VPN pour votre protection en ligne. Cela permettra de garder votre identité en ligne privée pendant que vous diffusez du contenu protégé par des droits d’auteur gratuitement. Vérifiez les meilleurs addons Kodi 2018 qui vous aident à diffuser le contenu. Apprenez tout sur Kodi dans notre guide. Pour cela, visitez notre site officiel PureVPN.FR-> allez dans la section blog -> sur le tab de recherche, tapez « Kodi sur linux » et vous verrez mon blog « Comment Installer Kodi sur Linux ». Liseez-la et profiter le meilleur streaming kodi sur linux.
     
  8. n_p

    n_p Active Member

    Please moderate the spam out at some point.. ;) #noturgent
     
  9. HaoSs

    HaoSs Well-Known Member

    i don't think they care . I offered multiple times to fix this for them, but it went with no response
     
    n_p likes this.
  10. Tony77

    Tony77 Member

    Lets say Im using the EMBY plugin, which works pretty nicely.. It'd be great IF i could get the files to DIRECT PLAY with zidoo's player.. The functionality is built into the emby app.. in settings there is an option for EXTERNAL PLAYER.. just can't get it to work, but I bet it's an easy fix...?
     
  11. n_p

    n_p Active Member

Share This Page