Only needed another 30 minutes of scripting and testing.
So I've now got it running.
url2kodi scripts for Windows
Q: What is this?
A: Lets say you are using your Windows Laptop in front of your TV. Lets say you are using it to browse video sites (with embedded videos on the website), or youtube. Those scripts allow you to easily send the direct videourl (which you can easily get on Chrome or Firefox using the Video DownloadHelper plugin (
https://www.downloadhelper.net/ ), to an Android box (connected to your TV f.e.), or an Android device, and then prompts Kodi on the Android device to start playing them.
After that you can even turn off your Laptop, and the video on Kodi will resume playing - so its only handing over the videourl, not mirroring. This has distinct advantages over mirroring (much lower energy consumption, source framerate remains untouched).
The closest equivalent to this is Chromecast. Or put the other way around, this is 'Chromecast' for close to _every webvideo_ (even those not supporting chromecast), where you'd cast the video to Kodi - so you also have all the benefits of using Kodi as a video player (great UI).
Q: What are the prerequisites.
A: Your Android box/Android device needs to be in your local WLAN. adb debugging on the device needs to be enabled. The wireless adb connection needs to be working.
In Kodi under System/Settings/Services "Allow remote control via HTTP" needs to be enabled, and the port needs to be set to 8087. Username kodi, no password.
A: On your Windows (Laptop) side: Windows subsystem for Linux needs to be installed. Debian needs to be installed from the Windows Store (about 500mb installed). It needs to be 'wsl' set to version 2. android-tools-adb (adb) needs to be installed and curl needs to be installed in Debian. You also need to run a _current_ version of Windows 10. Home or Premium doesnt matter.
A: Also Chrome or Firefox need to be installed on the Windows laptop and the Video DownloadHelper plugin, in Chrome or Firefox as well. This will allow you to copy a direct videolink from a website, and have it stored in your clipboard. (The thing where the things you are copy and pasting reside.
)
A: You also need a way to find out the IP address of your android box/device, as the communication between your Windows (laptop) and the Android box/device will be IP based. Usually it is shown in your Android box/device under network settings but you can also get it from your router.
--
Setup:
The easiest part of the chain to set up is Kodi on your android device - so set the settings mentioned above under System/Settings/Services in Kodi first. After that, exit Kodi (via the shutdown button in Kodi, not via back on your remote..
) - and you are done with that part.
The next step is to enable adb debugging on the android box. On Android TV boxes (like the FIre TV stick) it usually also allows wireless adb (over WLAN). Which is what we want. The implementation might be different from vendor to vendor. Some android boxes might forget, that its was enabled after reboot, some will not (Amazon FireTV sticks do not), where you'd have to enable it again. If you have root on the android box this app (
https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb ) allows you to automatically enable wireless adb after every reboot, in case your Android box doesnt remember that it should be enabled after reboot.
So that part is a little bit more finicky, but you should be able to figure it out.
The next step is to test the adb connection. For that we actually do it within the linux subsystem for windows already -- so we have to set that up first, and then jump back to testing the adb connection (from your Windows (laptop) to your android box/device).
Installing windows subsystem for linux - first and foremost is easy as pie - its just that windows wants it to be stupidly ackward while also being easy.
So forget easy installer and do four steps or so, that seem to stem from 1995 or so...
The entire thing stays within a 500mb sandbox (folder), only adds another programm icon (distro) to your windows startbar - is installed and launched within seconds, usually in the background. So dont be scared of it - its really a thing that can be set up in five minutes - and then you can forget it, and it will stay out of your way.
(I'll also step you through unsinstalling it, just for the fun of it.
). The video I linked you to above already steps you through all the steps needed, so I strongly recommend, that you do the setup following the video above.
You basically open "windows features", check two checkboxes - this will install the capability to Windows, then prompt you to reboot. After you reboot open up powershell and type wsl --set-default-version 2 into it followed by enter. Should you get a prompt, that you need to install an update, visit the site mentioned on screen, and download, as well as install the update there. Again - the entire process is documented in the WSL 2: getting started video above. Then you open the Microsoft Store, search for Debian (instead of Ubuntu - the video tutorial above installs Ubuntu, we are installing Debian, its only about half the size once installed), install it, open up the Debian icon in your start menu, this will start the set up of the linux virtual machine, which only takes seconds, you type in a username for your linux installation, and a password (I used the same ones as in my Windows installation (not sure if needed, but probably a good idea)), and then when the installation is finished, you type in exit (followed by enter) to exit.
Then open up powershell, type in wsl -l -v to see your Debian instance and version number and to see if it already installed as wsl version 2 (number on the right). If not you'd have to convert it to a version 2. How thats done, can also be seen in the video already posted above. After confirming version 2, you close powershell, then open up powershell as an administrator, and type in set-executionpolicy remotesigned (followed by enter), and confirm A for all (afair).
(see:
https://superuser.com/questions/106360/how-to-enable-execution-of-powershell-scripts )
This allows you to run powershell scripts created on your local computer, and signed ones you might download from the web. But then, dont download powershell scripts from the web.
(Unless you understand what they are doing.) After that you can close powershell.
(If you dont know what powershell is, again - the video above steps you through it as well (just not through the set-executionpolicy remotesigned entry), which you have to type in on your own.
)
After all that, open up Debian once more (from the start menu), and then type in:
sudo apt-get update
(followed by enter) and after thats finished:
sudo apt install curl
(followed by enter), then type in Y and enter when prompted and after thats finished:
sudo apt install android-tools-adb
(followed by enter), then type in Y and enter when prompted.
After thats done, type in exit and enter - you are done with setup.
--
Testing if adb works
This can go incredibly easy and fast, or become a process thats a little bit more drawn out.
And it all depends on your Android box/device vendor, and/or the version of android you are running.
(What is adb? The android debug bridge. So simply a command line protocol to talk to your android device.)
First make sure your Windows laptop/machine and your Android box/device are connected to the same network, make sure that on the Android box adb debugging is enabled. And write down the IP address of your Android box.
Then on windows, open up Debian from the start menu, and type in
adb connect IP.ADD.RE.SS
(replace IP.ADD.RE.SS with the address you wrote down) hit enter -
if after a while (maybe confirming yes and enter) you get "adb connected" you are done. Maybe type in adb devices (followed by enter) once, to confirm you are connected, but even thats optional.
If not - this is where the trouble shooting begins. Here is a little background. Most android box vendors, really make it this easy, also most android boxes run Android versions that might be a bit older..
On some Android devices running newer builds of Android wireless adb only works, if you get a key certificate file in a certain folder of your OS trying to run adb. In our instance that would be a specific folder in Debian -- I havent had to do this, so I cant step you through it. Here is a corresponding thread in the Oneplus (android smartphones
) community - that should fill you in on whats needed:
https://forums.oneplus.com/threads/...o-longer-available-on-oneplus-devices.874115/
Also I dont know in which folder this has to be put on Debian (watch this video on how to access the Debian files from Windows: h**ps://
www.youtube.com/watch?v=GFgJgGV4d28 ) so you'd have to figure that out on your own.
The good news is, that the vast majority of Android boxes shouldn't require this, and simply connect, once you've enabled adb debugging on the Android device. The good news also is, that you only have to do it once.
--
Once you've got that running, its scripts all the way down.
Scripts
First - on Windows - create a folder in your Documents folder called FireRemote
I do this to keep the architecture identical to the setups for MacOS and Android, I've done in the past - also you have to name the folder FireRemote (name originally chosen for FireTV Stick and remoting into it..
) exactly, as some of the scripts rely on absolute folder paths.
All scripts you'll ever need to create or run, will reside in that folder.
First script:
Create a new file named fkopy.bat in that folder (make sure it doesnt have the .txt file extension anymore) then open it in a texteditor. (I prefer
https://notepad-plus-plus.org/downloads/ as my texteditor, but you can use any of them with a search/replace function.)
Paste the following into the file (without the leading fkopy.bat or Code: ):
fkopy.bat
Code:
Powershell.exe ~\Documents\FireRemote\fkopy.ps1
(This simply tells cmd to run the script fkopy.ps1 using Powershell.)
save it, and create the next file.
This time create a new file named fkopy.ps1 in the FireRemote folder (make sure it doesnt have the .txt file extension anymore) then open it in a texteditor and paste the following into it (without the leading fkopy.ps1 or Code: ).
fkopy.ps1
Code:
cd ~\Documents\FireRemote\
del ~\Documents\FireRemote\zwischenablagetmp.m3u -ErrorAction SilentlyContinue
del ~\Documents\FireRemote\zwischenablage.m3u -ErrorAction SilentlyContinue
Get-Clipboard > ~\Documents\FireRemote\zwischenablagetmp.m3u
Get-Content ~\Documents\FireRemote\zwischenablagetmp.m3u | out-file -encoding ASCII ~\Documents\FireRemote\zwischenablage.m3u
del ~\Documents\FireRemote\zwischenablagetmp.m3u
wsl sh /mnt/c/Users/notimp/Documents/FireRemote/fkopy.sh
(This navigates into the FireRemote folder, then deletes the files zwischenablage.m3u and zwischenablagetmp.m3u - which might be in there from previous uses, then gets the content of your clipboard and writes it to a file. Then the file gets read, and rewritten to another file, using ASCII encoding. This saves the file with UTF-8 encoding, which is needed to be able to edit it from linux, and not end up with encoding errors (strange chinese characters.
), after that the first file is deleted, and the linux script (which comes next) is started.)
Notice the /Users/notimp/ portion in the last line. Replace notimp with your windows Username - otherwise the linux script wont get launched.
(zwischenablage.m3u ? What are you... zwischenablage is the german word for clipboard, which also has the benefit of beginning with a z, which makes it easily findable in any folder on Windows or Android - which is why I'm sticking with the german name here.
.m3u is the extension for a playlist file Kodi can read and play back.)
Save it.
Next create a new file named fkopy.sh in the FireRemote folder (make sure it doesnt have the .txt file extension anymore) then open it in a texteditor, and paste the following into it (without the leading fkopy.sh or Code: ):
fkopy.sh
Code:
head -c -1 /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u > /mnt/c/Users/notimp/Documents/FireRemote/zwischenablagetmp.m3u && adb disconnect && rm /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && mv /mnt/c/Users/notimp/Documents/FireRemote/zwischenablagetmp.m3u /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && sleep 1 && head -c -1 /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u > /mnt/c/Users/notimp/Documents/FireRemote/zwischenablagetmp.m3u && rm /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && mv /mnt/c/Users/notimp/Documents/FireRemote/zwischenablagetmp.m3u /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && sed -i 's,https://www.youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g' /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && sed -i 's,http://www.youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g' /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && sed -i 's,https://youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g' /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && sed -i 's,http://youtube.com/watch?v=,plugin://plugin.video.youtube/play/?video_id=,g' /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && eval $(cat /mnt/c/Users/notimp/Documents/FireRemote/adbip.txt) && sleep 1 && adb push /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u /sdcard/ && sleep 1.5 && adb shell am start -n org.xbmc.kodi/.Splash -a android.intent.action.VIEW && XBMC_HOST="http://$(cat /mnt/c/Users/notimp/Documents/FireRemote/adbip.txt | 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/zwischenablage.m3u"}},"id":1}' "${XBMC_HOST}/jsonrpc" && adb disconnect && echo end
In this script we first remove all newlines from the playlist file, then check if the link in it is a youtube link, and do the replacements Kodi needs to play back youtube videos in its youtube app, then we adb push the file over to /sdcard/ on the android device (which is its internal storage ('top folder') - not necessarily the sdcard on the device..
), then we start Kodi on the android device (in case it isnt already in the foreground), then we stop any video playing on Kodi on android, and then we have Kodi on android play back /sdcard/zwischenablage.m3u which we pushed (copied over), and which contains the direct video url.)
Notice all the /notimp/ instances in that text? You need to search&replace (all of) them in your text editor with your Windows username, before continuing on. Only then -
save it.
Next create a new file named adbip.txt in the FireRemote folder (this time make sure it _does_ have the .txt file extension.
) then open it in a texteditor and paste the following into it (without the leading adbip.txt or Code: ):
adbip.txt
Code:
adb connect 192.168.1.107
Replace 192.168.1.107 with the ip address of your android box/device (your are trying to cast to), and _make sure_ that the text file only contains one line, so no enter and then an empty second line (newline) - one line only.
Save it.
And thats it.
From now on, all you have to do to start the video url casting process (and have the video playing in Kodi on your Android device), is to doubleclick the .bat file, once you have a direct videourl in your clipboard.
--
A few additional concepts.
Direct video urls? You get them using Video DownloadHelper for Chrome or Firefox. On Crome you also can set up a keyboard shortcut for every addon, which makes launching the plugin on an open website much faster. Video DownloadHelper can be set to copy the direct video url of a video entry you are clicking on in the plugin directly into your clipboard by default. As it starts out the default 'one click action' would be to download said video, but you can change that within Video DownloadHelper. This only has to be set up once.
What videos should I test this on? I recommend kickstarter.com for testing, go to a project page, see if you can pick up the direct videourl of the embeded video on the site - and then try casting it to your android device, by running the .bat.
You'll always go the Video DownloadHelper route - _except_ when dealing with youtube videos. For those you need the video url. (To see how to copy a youtube video url - watch my 'Preview video' above.) The reason simply is, that youtube doesnt like to give out direct video urls, and the Kodi Youtube plugin is set up to deal with the video links. For every other webvideo, you need the direct video url in your clipboard.
What if I want the behavior back I see in the Preview video above? (Launch the videourl in Kodi on your local installation, and not on Kodi on an Android box/device in your wireless network) You simply add one line to the end of your .ps1 file.
Code:
&"C:\Program Files\Kodi\kodi.exe" "C:\Users\notimp\Documents\FireRemote\zwischenablage.m3u"
replace notimp with your actual Windows user name.
(You can also delete much of the stuff at the end of the .sh script, starting with
Code:
&& eval $(cat /mnt/c/Users/notimp/Documents/FireRemote/adbip.txt) &&
So delete everything from that point on - to the end. Make (double check) sure the last letters in the script are m3u, and not a trailing && - which might lead to problems.
To be explained within the next days:
Kodi |referrer=somesite.com&verifypeer=false handling (once more cant hurt
).
How to set up the youtube app in Kodi to resolve 1080p and or 4k videos (once more cant hurt
).
How to uninstall Debian (wsl) from Windows.