Script to auto update a part of an addon

Hi,

the core of the youtube-dl addon seems to need manual update because it is not as frequently updated by the addon dev.

On the kodi forum I got some generic instructions to update the same, but I am facing some issues.

The part that needs to be updated is located at

/storage/.kodi/addons/script.module.youtube.dl/lib

On the kodi forum, this was the script I was given and asked to modify to suit my usage

#!/bin/sh
cd ~/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp
git clone https://github.com/rg3/youtube-dl.git
mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
ls -la
chown kodi.kodi youtube_dl
python -m youtube_dl --version

So, I changed the second line to match the path in coreelec, so my script looks as below

#!/bin/sh
cd /storage/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp
git clone https://github.com/rg3/youtube-dl.git
mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
ls -la
chown kodi.kodi youtube_dl
python -m youtube_dl --version

However when I run it, this is the output

/storage/scripts/youtubedl.sh: line 6: git: not found
mv: can't rename 'youtube-dl/youtube_dl': No such file or directory
total 46
drwxr-xr-x    4 root     root          1024 May 21 15:04 .
drwxr-xr-x    4 root     root          1024 May 21 14:44 ..
-rw-r--r--    1 root     root         16085 May 21 14:44 YDStreamExtractor.py
-rw-r--r--    1 root     root          9198 May 21 14:44 YDStreamUtils.py
-rw-r--r--    1 root     root         11448 May 21 14:44 YoutubeDLWrapper.py
-rw-r--r--    1 root     root            13 May 21 14:44 __init__.py
-rw-r--r--    1 root     root          3788 May 21 14:44 main.py
drwxr-xr-x    2 root     root          1024 May 21 14:44 yd_private_libs
drwxr-xr-x    5 root     root          1024 May 21 14:44 youtube_dl-old
chown: unknown user/group kodi:kodi
/usr/bin/python: No module named youtube_dl

Can someone help me correct this please?

And also lastly, I am trying to automate this by running it at a suitable interval. Any suggestions for the same?

This will not work because CE doesn’t have git program.
Instead of cloning the repo zip file should be downloaded, unpacked and moved appropriate files.

Like the file

https://github.com/ytdl-org/youtube-dl/archive/master.zip
1 Like

Thanks. Any suggestions on how to put that download command into a script?

Ok, try this:

#!/bin/sh
cd /storage/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp

#git clone https://github.com/rg3/youtube-dl.git
wget -O master.zip https://github.com/ytdl-org/youtube-dl/archive/master.zip
unzip -q master.zip
mv youtube-dl-master youtube-dl

mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
ls -la
#chown kodi.kodi youtube_dl
python -m youtube_dl --version
1 Like

Thats awesome. Ran the commands manually and it works. Thanks a lot @vpeter

If its not too much to ask, if you could please point me in the direction of how one would automate this? I can save this as a script, say ytupdate.sh and put it in a subfolder in .config directory. Not sure beyond that.

Thank you again!

1 Like

I assume you save this script somewhere.
Now just add line in /storage/.config/autoexec.sh and call this script. If this file doesn’t exists create it. But on Windows use some better editor like Notepad++ and save file in UNIX format.
The line should look like this

 /storage/some/path/your_script.sh &

Instead of /storage/some/path/your_script.sh use correct path to the file you created.

1 Like

Perfect buddy, thats do able. Thanks a lot!

1 Like

Hi, below is a script to update an addon part. I want this to run at startup. How should I go about it?

I tried pasting that into /storage/.config/autostart.sh but it didnt work.

#!/bin/sh
cd /storage/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp

#git clone https://github.com/rg3/youtube-dl.git
wget -O master.zip https://github.com/ytdl-org/youtube-dl/archive/master.zip
unzip -q master.zip
mv youtube-dl-master youtube-dl

mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
ls -la
#chown kodi.kodi youtube_dl
python -m youtube_dl --version

Put this content in autostart.sh

(
cd /storage/.kodi/addons/script.module.youtube.dl/lib
rm -rf youtube_dl-old
mkdir tmp
cd tmp

wget -O master.zip https://github.com/ytdl-org/youtube-dl/archive/master.zip
unzip -q master.zip
mv youtube-dl-master youtube-dl

mv ../youtube_dl ../youtube_dl-old
mv youtube-dl/youtube_dl ..
cd ..
rm -rf tmp
)&
1 Like

Yeah I sorta tried this and a few other permutations and combinations but no dice. So i added the

#!/bin/sh

at the start too.

Did a chmod +x autostart.sh also

But not getting it to work. Thanks for the help.

Before I made my last post I actually tried the script and it was working. And this script is started just before kodi is started. Did you even reboot the box?
Type this and post link you get

journalctl -u kodi-autostart -l --no-pager | paste
1 Like
Jan 01 05:30:19 box systemd[1]: Starting Kodi user autostart script...
Jan 01 05:30:19 box sh[2877]: [51B blob data]
Jan 01 05:30:19 box systemd[1]: Started Kodi user autostart script.
Jan 01 05:30:19 box sh[2877]: [133B blob data]
Jan 01 05:30:19 box sh[2877]: [59B blob data]
Jan 01 05:30:19 box sh[2877]: [86B blob data]
Jan 01 05:30:19 box sh[2877]: [51B blob data]
May 23 21:10:09 box sh[2877]: Connecting to github.com (13.234.176.102:443)
May 23 21:10:09 box sh[2877]: wget: server returned error: HTTP/1.0 400 Bad Request
May 23 21:10:09 box sh[2877]: [76B blob data]
May 23 21:10:09 box sh[2877]: mv: can't rename 'youtube-dl-master': Read-only file system
May 23 21:10:09 box sh[2877]: [52B blob data]
May 23 21:10:09 box sh[2877]: mv: can't rename '../youtube_dl': Read-only file system
May 23 21:10:09 box sh[2877]: mv: can't rename 'youtube-dl/youtube_dl': No such file or directory
May 23 21:10:09 box sh[2877]: [86B blob data]

Seems you have problem with your filesystem because I see Read-only file system ?

Also this is strange wget: server returned error: HTTP/1.0 400 Bad Request.

Try to put sleep 20 before this line in script

sleep 20
cd /storage/.kodi/addons/script.module.youtube.dl/lib
1 Like

Its really weird. I tried the sleep line but no luck. Tried issuing the same commands manually and it works perfectly. No issues, neither read only nor server error. Its just the script which is throwing up errors!?!

-- Logs begin at Sat 2020-05-23 22:12:12 IST, end at Sat 2020-05-23 22:14:39 IST. --
May 23 22:12:16 box systemd[1]: Starting Kodi user autostart script...
May 23 22:12:16 box systemd[1]: Started Kodi user autostart script.
May 23 22:12:16 box sh[2879]: [51B blob data]
May 23 22:12:16 box sh[2879]: [27B blob data]
May 23 22:12:16 box sh[2879]: [133B blob data]
May 23 22:12:16 box sh[2879]: [59B blob data]
May 23 22:12:16 box sh[2879]: [86B blob data]
May 23 22:12:16 box sh[2879]: [51B blob data]
May 23 22:12:21 box sh[2879]: Connecting to github.com (13.234.210.38:443)
May 23 22:12:21 box sh[2879]: wget: server returned error: HTTP/1.0 400 Bad Request
May 23 22:12:21 box sh[2879]: [76B blob data]
May 23 22:12:21 box sh[2879]: mv: can't rename 'youtube-dl-master': Read-only file system
May 23 22:12:21 box sh[2879]: [52B blob data]
May 23 22:12:21 box sh[2879]: mv: can't rename '../youtube_dl': Read-only file system
May 23 22:12:21 box sh[2879]: mv: can't rename 'youtube-dl/youtube_dl': No such file or directory
May 23 22:12:21 box sh[2879]: [86B blob data]

and manually as below

box:~ # cd /storage/.kodi/addons/script.module.youtube.dl/lib
box:~/.kodi/addons/script.module.youtube.dl/lib # rm -rf youtube_dl-old
box:~/.kodi/addons/script.module.youtube.dl/lib # mkdir tmp
box:~/.kodi/addons/script.module.youtube.dl/lib # cd tmp
box:~/.kodi/addons/script.module.youtube.dl/lib/tmp # wget -O master.zip https:
//github.com/ytdl-org/youtube-dl/archive/master.zip
Connecting to github.com (13.234.210.38:443)
Connecting to codeload.github.com (13.233.43.20:443)
saving to 'master.zip'
master.zip           100% |********************************| 1954k  0:00:00 ETA
'master.zip' saved
box:~/.kodi/addons/script.module.youtube.dl/lib/tmp # unzip -q master.zip
box:~/.kodi/addons/script.module.youtube.dl/lib/tmp # mv youtube-dl-master yout
ube-dl
box:~/.kodi/addons/script.module.youtube.dl/lib/tmp # mv ../youtube_dl ../youtu
be_dl-old
box:~/.kodi/addons/script.module.youtube.dl/lib/tmp # mv youtube-dl/youtube_dl
..
box:~/.kodi/addons/script.module.youtube.dl/lib/tmp # cd ..
box:~/.kodi/addons/script.module.youtube.dl/lib # rm -rf tmp
box:~/.kodi/addons/script.module.youtube.dl/lib #

Try running this manually. Does it work or same error?

dos2unix /storage/.config/autostart.sh
sh /storage/.config/autostart.sh
1 Like

That did the trick. Perfect. Thank you! I guess the dos2unix command correctly formatted the autostart file, is that correct?

Yes, Your fault was editing using the wrong tool.
Better use vi or nano

I did wrote in my post

But on Windows use some better editor like Notepad++ and save file in UNIX format.

I was using Textpad. I thought thats a valid tool. Sorry.

1 Like