1. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    If your android box is rooted, you can use WiFi ADB to auto enable adb after every boot (if it doesnt stay enabled in your case), also if for some reason the adb server hangs, this can be used to reset it in two clicks.

    https://play.google.com/store/apps/details?id=com.ttxapps.wifiadb

    (Integrated it in the adb setup tutorial as well.)

    edit: To not bump the thread just for that - here is also

    How you enable high resolution videos (1080p and above) in the Kodi Youtube plugin

    First make sure InputStream Adaptive is installed and enabled, Add-ons > My Add-ons > VideoPlayer InputStream > InputStream Adaptive

    If its not on your device already, you should be able to install it through the official Kodi repo. If thats not the case, google for a package to install it on your specific platform (Android).

    Then configure InputStream Adaptive; Ignore Display Resolution: enabled, Max. Resolution general decoder: Max, Stream Selection: 4k, 1440p or 1080p.

    After that you only have to enable it in the youtube app:
    YouTube addon settings > MPEG-DASH > Use MPEG-DASH: enabled, MPEG-DASH > Use for videos: enabled. Also enable it for live streams. Exit the youtube plugin, enter it again, and it should work. :)

    and here is

    How you create and enter your own API ID in the youtube plugin settings

    so you never get "request limit reached" errors again - this time its just me linking to a badly voiced youtube video someone else made.. ;)
    h**ps://www.youtube.com/watch?v=lxPxMZbDgec
    --

    edit: One more small edit. Turns out, Kodi can do link completion from a referal link, if that link links to an m3u8 with relative links inside. But then it cant do auto bookmarking on where you left off the video/movie. :) (If you stop it f.e.) So the script (macOS and Android), that does full link completion in m3u8 playlists still is preferable.. :) Details. :)
     
    Last edited by notimp, Jan 31, 2020
  2. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Newer fork of aafm thats still maintained:
    https://github.com/Xerus2000/aafm

    Cant test it currently - but will do so in about a week and post findings. If everything goes well, I'll replace the link to the original in the first posting.

    have fun

    n.
     
  3. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Update to the last posting. Fork just works. :) Clone the repositary as a .zip file (or git clone it directly), place the contents of the src folder in ~/Documents/FireRemote/aafm/ and chmod +x *.py in that folder.

    Had to restart it once (would only work, once it created the config files).

    I wont be updating the link to the original version in the corresponding tutorial thread yet, because I've had some issues with it not displaying UI elements until its window is pulled to the foreground. Have to look into that still. (Is mostly an excuse to not fix the launcher script now.. ;) )
    Will update once I do. :)
    --

    Kodi referer handling

    In case you ever come across a .m3u8 file link that fails to play, sending it to Kodi, and that throws you the error 403 (access denied), when trying to download it on a PC - its likely, that the site wants itself as a referer, before it allows you to download the file (Checks if the last site you visited was itself).

    Luckily, Kodi can handle referers as well. :)

    I'll start with the Android push videolink to Kodi 'n play script.

    Simply take the automate workflow you created from one of the previous threads (the normal one, not the one that replaces relative links in playlists with absolute ones :) ), make a copy of it (duplicate is a menue item for workflows in automate. :) ), navigate to edit the last (third) write to file item. On its first line click on the fx icon right to it (displaying it in function form).

    You should see

    ="\n"

    which we just used to append a new line (\n) at the end of the videolink.

    Edit that so it reads

    ="|referer=http://somesite.com\n"

    save the workflow, and thats it.

    Kodi referer handling works by simply putting |referer=http://somesite.com directly after any video link. Kodi will then use that referer trying to access the link.
    -

    For the macOS based acopy script (that does the same), its as simple as adding the line

    Code:
    sed -i '' '$ s/$/|referer=http:\/\/somesite\.com/' ~/Documents/FireRemote/zwischenablage.m3u
    directly after the
    Code:
    pbpaste > ~/Documents/FireRemote/zwischenablage.m3u
    line in the helper script.

    note that sed -i followed by space and two ' and another space is needed for sed to edit/replace the current file in place on macOS. On linux distros the space''space directly after sed -i might not be needed. :)

    $ simply points to end of line, and 'replaces' it with what comes after. For sed, we have to escape some of the characters such as the / and the . thats, why there are a few more backslashes in the url. ;)

    Have fun. :)

    edit: Just for reference. 99.9% of websites dont require a referer, when accessing videolinks, or .m3u8 playlists. This is really just for the edge case, where one you really like - might do. :)
     
    Last edited by notimp, Feb 19, 2020
  4. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Fixed the aafmtrigger (launcher/closer) app (script-editor) code.

    aafm now gets correctly pulled into the foreground while launching.

    Also rewrote the script slightly to close all other terminal windows before launching aafm (/python), which caused an issue with aafm not rendering, when multiple terminal windows were open, when the script tried to launch aafm.

    Updated the link to the newer aafm fork in the original post as well.

    Its now recommended to update to the fork (if you used the original release of aafm), instead of the original release, because it fixes a few adb shell issues the original release of aafm had (deleting multiple files on the android side now works, f.e.).

    edit: Added a little bit of extra delay to make the launcher more reliable as well.

    Script might not work on the first launch (when you give it permissions) - because timings are not as expected. So launch it again (which should quit terminal and Python (make sure to manually quit terminal if it does not (depends on weither Python gets launched or not))), and then launch it a third time. From the third time on (with permissions granted) it should work as intended.

    With this, everything should be up to date again and working as expected. :)

    edit2: Changed timings once more (increased first delay) to increase reliability.
     
    Last edited by notimp, Apr 13, 2020
  5. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Wrote a mostly unrelated MacOS script yesterday, that might become useful for your Android TV media usage - but only in some edge cases.. ;)

    Its still a good one to learn a bunch of concepts at once, so I'm sharing it.

    Lets say a website is DNS blocked by your ISP - and simply changing over to one of the classic 'free DNS' providers (Google, Cloudflare, ..) doesnt fix this.

    Using Tunnelblick (VPN client) is an option (get a VPN connection to a country where the DNS problem doesnt exist), and if you are connected via Tunnelblick, DNS queries also will go over the VPN, which is ultimately what solves our issue.

    Now - for our browser to request the DNS query for our website again, its sufficient to simply open a Chrome incognito tab (if no incognito tab has been opened so far) - and surf to that site there. Also lets automate url entry.. ;)

    At the same time - if we are using a Mail client linked to Gmail for example - we want to close that before connecting to the VPN, because otherwise we get 'someone knows your password' warning mails from google (because we pop up in a different country (IP address) all of a sudden).

    Also - we want to make all of that reversable (normal operational state, with the email program running, and the VPN not connected), only pressing maybe two buttons.. ;)
    -

    Thats pretty much the point, where - if you are me, you start writing a script... ;) (Apple script, can be saved as an app using Script-Editor (comes with every installation of MacOS))

    Code:
    set x to isAppLoaded("Tunnelblick")
    if x then
        tell application "Google Chrome" to close (every window whose mode is "incognito")
        tell application "Tunnelblick"
            disconnect "Finland"
        end tell
        delay 1.5
        tell application "Tunnelblick" to quit
        tell application "Sparrow"
            activate
        end tell
        delay 1
        tell application "System Events"
            tell process "Sparrow"
                click button 1 of window 1
            end tell
        end tell
    else
        tell application "Sparrow" to quit
        delay 1
        tell application "Tunnelblick"
            connect "Finland"
            get state of first configuration where name = "Finland"
            repeat until result = "CONNECTED"
                delay 1
                get state of first configuration where name = "Finland"
            end repeat
        end tell
        set theURL to "https://mysite.com"
     
        if application "Google Chrome" is running then
            tell application "Google Chrome"
                activate
                make new window with properties {mode:"incognito"}
                delay 1
                set URL of active tab of front window to theURL
            end tell
        else
            do shell script "open -a 'Google Chrome' --args --incognito " & quoted form of theURL
        end if
     
        tell application "Google Chrome" to activate
     
    end if
    
    on isAppLoaded(app_name)
        tell application "System Events"
            set app_list to every application process whose name contains app_name
            if the (count of app_list) > 0 then
                return true
            else
                return false
            end if
        end tell
    end isAppLoaded
    
    Script checks if Tunnelblick (VPN client) is running, if not - it closes the email program (Sparrow), it launches the VPN client, it connects it to Finland (connection name in Tunnelblick), once a connection is made it starts a Chrome incognito window, loading the specified url.

    If you run the script a second time and it checks that Tunnelblick (VPN client) is running, it first closes all Chrome incognito tabs (just for convenience), then it disconnects the VPN, quits Tunnelblick, starts up the email client (Sparrow) again, and presses the close window button (closing the window, but not quitting out of the email client) - so it effectively runs in the background again.

    And this is indeed one of the advantages of using MacOS. ;) (High level of scriptability over your GUI programs as well... :) )
     
    Last edited by notimp, Apr 26, 2020
  6. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Reduced two delays in the acopy shell script (copy an url from a Mac to a Kodi Android box and play it) in my private setup.

    sleep 2.5 > sleep 0.5
    and
    sleep 1.5 > sleep 0.5

    those delays were a leftover, from when I used to run the script on a 2010 Macbook Air. Reducing those two delays saves 3 seconds on execution, on my current Macbook, while still being reliable.

    I left in the old values in the acopy script on the first plage, so it doesnt break for people with slower Macs, but if you run them on a somewhat current model, you can save three seconds on every execution. This adds up.. ;)

    Just fyi.
     
    Last edited by notimp, May 11, 2020
  7. Magsor

    Magsor I am watching you
    Member

    Joined:
    Dec 1, 2010
    Messages:
    1,234
    Country:
    Canada
    And may I ask what is your goal with ths software? What are you trying to do? I thinks it like VR; a path that many have tried to do but in the end its useless.
     
  8. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    I use it daily, so to me its certainly not useless. :) Also, documenting it publicly serves the purpose of a neat backup, thats easily accessible for me from everywhere, whenever I want to borrow a piece of code from any of the scripts.

    But to your question as for 'why'.

    Usability on this is top notch. Dare I say great. ;)

    The main script I still use daily is the 'send an online video file link to Kodi on an Android Box and let it play there'.

    So basically the same thing - you see every online video host do currently with a 'cast to chromecast' button, but rather cast it to Kodi (on any Android (TV) box) - and on pretty much every online video (played back on any website) that is out there, not just on those that have a 'play to chromecast' function built in already.

    This all came out of a 'there has got to be a better way' deliberation, when dealing with Kodi video plugins. Kodi has a vast video plugin ecosystem, but those things break from time to time. And they almost always break at the html scraping part (when a site changes something, ..). So instead of writing a bunch of Kodi video plugins, or getting really into python and learn how to read what the other authors Kodi plugin intended to do, with each and every video plugin you want to fix, or for every site you come across, that has a video embedded in it - at some point I had an 'aha' moment that went as follows:

    1. Almost all web videos are unencrypted .m3u8 or .mp4 streams. Kodi can play those back.
    2. A chrome plugin called video download helper I used for years can get me those links with 99% reliability with only two clicks (a button combo and a click)
    3. Almost all my 'discovery' is done better on my Macbook, or my android phone (discovering a web video I want to watch in an interface on my TV (that isnt youtube leanback) works less well), and I'm mostly in front of my TV using a second screen anyhow.

    (4. The Kodi UI is still what I'd want to use for playback/movie navigation. Hate other player Uis. ;) (Kodi is faster, lets you customize the jump forwards and back intervalls, can be set so when you pause a movie you only get a still image with no ui elements left (time indicator fading out after three seconds)...))
    --

    So I started to write a script that would take the videolink from the clipboard, put it in a file, transfer it to a Android Box running Kodi, and make Kodi play that back. (Thereby have it play back on my TV in less than 5 seconds.)

    And because I didn't want that to work only with just one Android Kodi Box, but with multiple ones in my home potentially - I used terminal history to look up the last Kodi box I was connected to (or at least the last one that was listed in terminal history).
    ---

    That was where all of this started. :)

    The rest then just grew out of it. (Wanted a way to do the same thing from my android phone, and not just my Mac, wanted a way to control Kodi from the Mac, wanted a way to control the entire android box (like you would with a remote), from a Mac, wanted a way to transfer files (in both directions) from and to the Mac, wanted to be able to throw videolinks at both Kodi and the Youtube leanback app on the android tv box (so both could be active in ram and I could switch between them, without losing playback state), ...)

    You should see me, when I'm navigating this in front of my TV. It really works. Its really fast. And really convenient... :)

    edit: Basically, think this:


    But instead of the Nintendo Switch, think living room TV (or Nintendo Switch, or both, or ...), and think at least 3 seconds faster, because I removed those delays, as mentioned above.. ;) And think this with pretty much every web video out there (some require referrers (1% maybe), and we can also hand over those.. ;) ).

    Also the main benefit over 'not just casting your screen' is, that you arent encoding/reencoding video here, you are just casting, you can close the browsertab on the Mac (heck, you could even turn the Mac off.. ;) )), you can do a bunch of different stuff, and the video will still be playing on the TV - only consuming the 4 Watt your Android box needs to play back a web video. And it can be fast forwarded, paused, stopped, ... with your TV remote. (Or the Mac controlling Kodi.. ;)) And it retains the intended framerate (the video does). So casting is better than mirroring, always.



    And an Android (TV) box or stick to do this costs 20-120 USD max. :)
    (I personally prefer the Zidoo X9S (with a Logitech Remote (Harmony Companion), as it also has dd-wrt built into it, which means it will basically always run a ftp server on a second OS in parallel (once set up that way) - which helps with the 'hand over a videolink from an android smartphone' script. :) -- but auto framerate switching on those is a bit kludgy (requires a Kodi fork named zdmc, which I stopped using after a while) - I solved that on the TV side, so as much as I love the Zidoo X9S, I cant recommend it for everyone.. :) ).
    Macbook Air (on the laptop side) costs more, but I like them. What can I say... ;)


    Still useless? ;) Or just hard to wrap your head around at first? (Because you could recommend to people that they use Netflix instead, but it just isnt the same, you see.. ;) ) Also usage experience is better than the youtube apps native video casting to f.e. the youtube lean back app. Meaning, with longer videos, I cast them to Kodi, because I know that skipping back 10 or 30 sec will be easier, pausing will be easier, with Kodi I can use voice control, I can set bookmarks, I can pause and photograph or screencap the screen without a UI element being present. (Great to look at/analyze cinematography.) And I dont have to swipe the youtube pairing on casting a video with the youtube app on the phone away after I'm done using it.

    And its fast and intuitive. But it isnt Netflix, so its useless? ;)

    Should you be new to scripting, part of why you would f.e. script an ftp upload via curl instead of using a ftp program is - speed - because once you defined your upload folder, its usually faster to get a file there, if you are not starting your ftp program first, and then connecting that via a bunch of clicks, then ... If you script something, its just faster.

    And you start doing that, once you see, that you do the same tasks over and over again - and start to wonder if you'd enjoy them more, and therefore maybe even do them more, once you cut the repetitive stuff out, and made the entire process faster. ;)

    Ask me next, how long it takes me to watch any movie in the world on my living room screen. Because of chrome search shortcuts, and certain sources.

    12 seconds. Usually.

    From the time I open up my laptop.

    (I promise I only did it once though. For research purposes... )

    Useless? That depends heavily on your perspective, I'd say.. ;)

    Ask me next, why I wrote a bunch of helper scripts to be able to copy over files to the android box faster. To be able to write and test the main scripts faster. :) Ask me why I wrote scripts to be able to control Kodi from my Macbook? Because I didn't want to look for the TV remote, while doing work on my laptop whilst listening to music in Kodi, wanting to skip a track. (And not wanting to do it in a web UI, but with shortcuts, because then I dont have to look. I just hit the shortcut.)

    Ask something you dont understand, and I'll try to answer it to the best of my ability. But dont just dismiss something outright, because you dont understand it, or because it only has one like.. ;)

    It could turn out, that the person you were talking to knows more about home theatre implementations than you do. But just didn't feel like paying for a prefab solution that would have been worse in many aspects.
     
    Last edited by notimp, May 13, 2020
  9. Magsor

    Magsor I am watching you
    Member

    Joined:
    Dec 1, 2010
    Messages:
    1,234
    Country:
    Canada
    Ok. it's just not clear in your intro. You mainly use this thread as a repository. I am just the type of tempers who goes around trying to help people shaking their value knowledge of the world. If you ain't got no problem then keep up the good work!
    I might add that your typing is impeccable, very nice.
     
    notimp likes this.
  10. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Stitched together another quick way to control an android device (f.e. TV box) from a Mac. This time with mouse and keyboard support. :)

    This relies on Synergy (https://symless.com/synergy) which is a paid app. (9 USD)

    You set up the Synergy server on your Macbook (/Linux Laptop), and on the android side you install this apk:
    https://github.com/dcerisano/synergy-android-7/blob/master/synergy.apk

    You specifically have to install it through adb (= command line), by using the parameters:

    adb install -g -t PATHTOSYNERGYAPK

    Because the package is packed with test keys - otherwise the install wont go through.

    That specific app is a fork of the synergy android beta client, which has the keyboard fixed for newer android versions (synergy beta app is quite old). See: https://members.symless.com/forums/topic/5577-synergy-for-android-l-m-n-o/

    Once done, you set up the server and the android client so they can see each other, and you can successfully control the android device using your laptop. (mouse and keyboard).

    Now comes the caveat. :)

    First, the synergy client app has to be allowed to stay in background without being killed, which can usually be achieved following this guide:
    https://www.quora.com/How-do-I-prevent-Android-OS-from-closing-a-background-app-for-memory (Settings can be named slightly different, depending on your android version.)

    Once thats done - there is another issue with the android app, namely - that it sometimes looses control to the synergy server, or doesnt like to connect. ;) Luckily all those issues can be entirely solved by automating the entire connection process (timing windows), which we do next. :)

    Create the following applescript (copy paste this into ScriptEditor on a mac, and save it as an app):
    Code:
    set x to isAppLoaded("Synergy")
    if x then
        do shell script "ps aux  |  grep -i Synergy  |  awk '{print $2}'  |  xargs kill -9 & $COMMAND & $EXIT"
        do shell script "/usr/local/bin/adb disconnect"
    else
        tell application "Synergy" to activate
        tell application "Terminal"
            do script "eval $(history | cut -c 8- | grep 'adb connect [0-9]' | tail -1)"
        end tell
        delay 0.5
        do shell script "ps aux  |  grep -i Terminal  |  awk '{print $2}'  |  xargs kill -9 & $COMMAND & $EXIT"
        do shell script "/usr/local/bin/adb shell am force-stop org.synergy && /usr/local/bin/adb shell monkey -p org.synergy 1 && sleep 0.5 && /usr/local/bin/adb shell input tap 1800 480 && /usr/local/bin/adb shell input keyevent KEYCODE_APP_SWITCH && /usr/local/bin/adb shell input keyevent 19 && /usr/local/bin/adb shell input keyevent 66 && /usr/local/bin/adb disconnect"
        delay 0.5
        tell application ((path to documents folder as text) & "FireRemote:mousetoandroid.app") to activate
    end if
    
    on isAppLoaded(app_name)
        tell application "System Events"
            set app_list to every application process whose name contains app_name
            if the (count of app_list) > 0 then
                return true
            else
                return false
            end if
        end tell
    end isAppLoaded
    prerequisites:
    - adb needs to be installed (see 'getting started' on the first page of this thread) and you have to have a recent entry in your terminal history where you adb connect 'ed to the ip address of your android device (ip gets looked up by the script based on the most recent connection made).

    The script does the following.

    It looks if Synergy on the Mac is running and if so kills it (and disconnects adb). This is for exiting it, when running it a second time.

    If Synergy is not running, it starts Synergy (server), connects to the android device via adb, force closes the Synergy android client - to get a clean state on that, then launches the Synergy android client and clicks on the connect button (because the client doesnt auto connect).

    In the script above, thats the /usr/local/bin/adb shell input tap 1800 480 part. 1800 and 480 are the x and y coordinates the script clicks on, which are correct for a 1080p output (1920x1080). If your android device outputs a different screen resolution, you have to change the coordinates.

    After doing that the script launches the app switch menu on the android device (recent apps), and then presses "up" (keyevent 19) and "enter" (keyevent 66), thereby getting back to the app that was on screen on the Android device, before the Synergy android client was launched.

    If your app switch menu doesnt switch to the previous app by pressing up and then enter (f.e. because the app cards are scrolled horizonally and not vertically), you can change those keyevent inputs, with other ones you can get from this posting:
    https://stackoverflow.com/questions/7789826/adb-shell-input-events
    Then the script disconnects adb.

    The last thing the script does is to launch an app named mousetoandroid.app - which we create as well. :) That app only consists of one line of code, namely:
    Code:
    do shell script "/usr/local/bin/MouseTools -x 1439 -y 700"
    Save this as an .app named mousetoandroid.app in your ~/Documents/FireRemote/ folder (must be that folder).

    What it does is to move the mouse cursor on the Macbook to the rightmost edge of the screen (horizontally) minus one pixel. (So horizontal screen resolution of the Macbook in my case is 1440 and the x value in the script is 1439.) The only thing that does is, that it hits the edge trigger where Synergy on the Mac (server) will hand over control to the android device. So once this app gets launched, since both Synergy server and client already are connected at this point, the focus of your mouse and keyboard switches over to the android device automatically - without you needing to move your mouse.

    Depending on how you set up Synergy - the edge where Synergy switches over might not be the right side one, so you might have to change your coordinates based on that and your laptops screen resolution.

    For some reason we need a second (helper) app for that, as it doesnt work, when MouseTools is called from the first app.

    Also - you need MouseTools for that, which you can get from: http://www.hamsoftengineering.com/codeSharing/MouseTools/MouseTools.html

    Simply put the binary in /usr/local/bin and sudo chmod +x the MouseTools file to make it executable on your system.

    Also you need to whitelist the mousetoandroid.app in your System Settings/Security/Accessibility - for MouseTools to be allowed to control your Mouse cursor.

    The entire process around mousetoandroid.app we go through, because the Synergy keyboard shortcuts on macOS dont work reliably in the current version, so we cant simply switch screen focus using a keyboard shortcut. ;)
    --

    All said and done - after you've set this up, it takes 9 seconds for your Macbook (/Linux laptop) to grab and be able to control your android device, after the script is launched. And if you (first move your mouse a little to the left (in my case, so the Mac desktop draws focus in Synergy again)) and launch it a second time, Synergy and all connections to your android box exit cleanly.

    There is one final caveat. There are no keyboard shortcuts for the home or back button, once you are controlling android. So your android device should have them accessible for your mousecursor - somehow. Luckily my android box does (by clicking on the bottom edge of the screen it pulls up software keys for back and home).

    Maybe you could set keyboard shortcuts up in android keyboard settings, but I didnt try it out, since I already had my software key overlay that provided me with those actions. (edit: Remapping could be done as indicated in this posting: https://superuser.com/questions/135...ooth-keyboards-in-android-without-pressing-fn)


    edit:

    && /usr/local/bin/adb shell input keyevent 19 && /usr/local/bin/adb shell input keyevent 66

    in the script above can be replaced with:

    && /usr/local/bin/adb shell input tap 1000 333

    which is faster, but only works on 1080p resolution output. (Instead of pressing up and then enter, it just clicks on the app to switch back directly). Also gives you less animations on screen while the script is running, which makes it look cleaner.
     
    Last edited by notimp, May 23, 2020
  11. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Found and fixed a common error in the url2kodi script today. I'll only post the fix in this posting and will not change the script itself, because I havent tested potentially adverse effects as of now.

    On OSX, create a new akodih.sh helper script (named slightly different) and a new launcher app (launching the differently named helper script) to test it yourself and keep the new fixed version separate from the default one.
    (Dont forget to also chmod +x the new helper script.)


    So here is the issue I've found and fixed/circumvented today. On some videourls, you'd hand over to kodi, if hosted on a https server, Kodi fails at the https handshake (certificate error). This is easily fixed by telling Kodi not to verify the handshake - which, with several videohosts results in Kodi playing videos from videohosts it previously wouldnt.

    The fix is pretty easy and straight forward:

    in acopyh.sh add the following line before the line containing sleep 0.7:

    Code:
    sed -i '' '$ s/$/|verifypeer=false/' ~/Documents/FireRemote/zwischenablage.m3u
    The rest can be left as is.

    This sed replacement just adds |verifypeer=false to the end of the movielink you are handing over to Kodi, which causes Kodi not to verify the https connection.

    Which apparently, solves videoplayback for several sources.

    (Dont use this in addition to handing over Kodi the referrer command for now (other 'non standard potential fix for some issues' I've posted in the past), two | in one link will not work. :) Commands after | would have to be chained with & - which in the sed replacement needs to be escaped (otherwise gets 'swallowed) which I didnt try as of now. You can. :) )

    This should open up compatibility to even more videohosts, but again - there could be detrimental side effects (f.e. youtube video casting breaks, because the youtube app doesnt expect that at the end of a video url.. ;) ).

    So writing a separate app (and a separate helper script (acopyh.sh named slightly different)), in addition to your main casting app is recommended for now. :)
     
    Last edited by notimp, Oct 4, 2020
  12. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Came across a source where I had to chain referer and veryfypeer=false commands at the end of the videolink to Kodi.

    sed in that case looks like this (MacOS example, in the Android case (automate app) you can still just write it in the append text step, without escaping _any_ characters) - so & simply had to be escaped using a \

    Code:
    sed -i '' '$ s/$/|referer=https\:\/\/mysite\.com\&verifypeer=false/' ~/Documents/FireRemote/zwischenablage.m3u
     
    Last edited by notimp, Nov 4, 2020
  13. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    I'm currently working on the Windows implementation of my url2kodi scripts, and wanted to give you a quick unenthusiastic preview. ;)



    So far I've got the direct videolinks playing on Kodi on the local windows machine - but the implementation to push them to any Android box running Kodi (within your home network), from a windows machine (ideally a laptop ;) ) - should be ready within the next couple of days.

    If you already want to get through all the prerequisites, simply set up windows subsystem for linux, as shown in the following video:


    When in the Windows store (following the video), simply download Debian instead of Ubuntu (its smaller (500MB installed on your harddisk)), launch it, set a username and a password, then wsl set version to 2, (set default version to 2 as well if you like to ;) ), all as seen in the video.
    Then launch it once more and execute (type in followed by enter)

    sudo apt-get update
    (type in the user password you just set followed by enter)

    sudo apt install curl
    sudo apt install android-tools-adb

    And thats all thats needed - until I publish the scripts. :)
     
    Last edited by notimp, Mar 12, 2021
  14. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    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.
     
    Last edited by notimp, Mar 12, 2021
  15. notimp

    OP notimp Well-Known Member
    Member

    Joined:
    Sep 18, 2007
    Messages:
    5,515
    Country:
    Laos
    Ok, here is the promised update on the three points at the bottom.

    1. How to uninstall wsl Debian Linux from Windows (in case you'd want to):
    Open Powershell, type in

    wsl -l -v

    to get the DistributionName - then type

    wsl --unregister DistributionName

    (all followed by enter)
    see: https://www.howtogeek.com/261188/how-to-uninstall-or-reinstall-windows-10s-ubuntu-bash-shell/

    After that rightclick on the Debian entry in your start bar and select uninstall.

    2. How to set up Kodi to play youtube videos in 1080p, 1440p or 4K.

    Install the VideoPlayer InputStream plugin from the official Kodi Addons repo.

    Make sure Ignore Display Resolution is set to enabled and Max. Resolution general decoder is set to Max. (In the plugins settings).

    Then in the Youtube Addon select YouTube addon settings > MPEG-DASH > Use MPEG-DASH: enabled, MPEG-DASH > Use for videos: enabled. Also on the same settings page there is an option where you can limit video quality (lets say to 1080p or 1440p), should you want to.

    Also - as a last step, also in the Youtube plugin settings under http server, set the port from 50152 to 52520.
    see: https://forum.kodi.tv/showthread.php?tid=353278&page=184

    Otherwise at least I got a 10013 error, and resolving hires videos would break after the first restart of Kodi. On Windows (Port change fixed it.). On Android, the port did not have to be changed.

    3. |referrer=somesite.com&verifypeer=false

    Ok here is a second and final attempt to get you familiar with those two settings. :)
    They are put after a direct videolink, in a m3u file (directly after the link, no new line, no space), to signal to Kodi, that it should handle the videolink using those properties.

    They are chained with & (which if you are editing the sed portion of the linux scripts to add those replacements will need to be escaped by putting a \ in front of the & (so \&).

    So valid arguments would be |referrer=somesite.com or |verifypeer=false or |referrer=somesite.com&verifypeer=false or |verifypeer=false&referrer=somesite.com

    verifypeer=false disables the https certificate verification, which (having it enabled) might cause some directurls (webvideos) fail to play in Kodi.

    referrer=somesite.com (somesite.com to be replaced with the (top) domain (so no /something/other/or.html) of the website your webvideo is embedded in) lets Kodi try to play back the directurl (webvideo) sending out the specified referrer (telling the site, that you came from it initially), which also leads to some videourls becoming playable in Kodi, that werent before -- but as with the first one - it depends on the site. Isnt needed on most of them, works with some -- though you'd have to try it.

    If you have a specific video site, where a direct videourl wont play back in Kodi - try to add those two, and see if you are lucky. :) It worked on two of the video sites I wanted it most to work with - so give it a try. ;)

    Now - setting those parameters isnt integrated in the linux script (.sh) by default - because, it breaks youtube compatibility. Simply put - youtube link isnt supposed to have a |referrer=somesite.com&verifypeer=false at the end so Kodi refuses to play it. :)

    So the idea is, that you duplicate all three scripts, give them a slightly different name (fe. lkopy), also replace the parts where they are launching each other with the different name - and then add a replacement that adds those parameters to the end of the link in your clipboard, before sending the link over to your Kodi installation.

    Then you'd have two .bat files - executing a set of other files, one where the youtube implementation isnt broken, and one that may maybe fix your 'favourite video site'.

    Here is what you replace in the .sh script.

    First, in the .sh script all commands are chained with && - that is space&&space - in the middle of the line you'll find the sed replacements for youtube (should be 4 in total), which you could take out or leave in, and then would basically place a
    Code:
     && sed -i '$ s/$/|referer=http:\/\/somesite\.com/' /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && 
    after them, or instead them. Only one set of && - before and after, and dont forget the spaces.

    Replace notimp with your username.

    This adds one of the arguments to the end of your videolink after you've executed the .bat (you can look at the result in the zwischenablage.m3u).

    If you want to add both of them add
    Code:
     && sed -i '$ s/$/|referer=http:\/\/somesite\.com\&verifypeer=false/' /mnt/c/Users/notimp/Documents/FireRemote/zwischenablage.m3u && 
    instead.

    Again, this might get the direct videourls of your favorite site working.

    In case some of you are wondering - videos that are drm encrypted, and where drm is linked to the player software - are not compatible. (99.9% of webvideos dont have that issue), also videos where you see, that they have been split into very small chunks in Video Downloadhelper (without them being listed in a playlist file), usually also dont work. HSL usually works, direct videolinks usually work, and a bunch of other stuff, usually works. Kodi handles a lot of videofiles without issues.
     
    Last edited by notimp, Mar 18, 2021
Draft saved Draft deleted
Loading...

Hide similar threads Similar threads with keywords - [Release], interface, scripts