-
-
Save henrydatei/b85f2ffbe0390b2e8b069ab1e5765986 to your computer and use it in GitHub Desktop.
#file=$1 | |
#videoname=$(echo "$file" | cut -d "." -f1) | |
#echo "$videoname" | |
touch playlist.txt | |
touch urllist.txt | |
key=$1 | |
videoname=$2 | |
#keystring=$(cat $file | grep -o -E "key=[0-9,a-z]+") | |
#key=$(echo "$keystring" | cut -c 5-) | |
link="https://videocampus.sachsen.de/media/hlsMedium/key/$key/format/auto/ext/mp4/learning/0/path/m3u8" | |
playlist=$(curl -s "$link" | tail -n 1) | |
newLink="https://videocampus.sachsen.de/media/hlsMedium/key/$key/format/auto/ext/mp4/learning/0/path/$playlist" | |
wget -O playlist.m3u8 "$newLink" | |
for line in $(cat playlist.m3u8 | grep ".ts"); do | |
partLink="https://videocampus.sachsen.de/media/hlsMedium/key/$key/format/auto/ext/mp4/learning/0/path/$line" | |
echo "$partLink" >> urllist.txt | |
echo "file $line" >> playlist.txt | |
done | |
cat urllist.txt | parallel -j 50 'wget {}' | |
ffmpeg -f concat -i playlist.txt -c copy $videoname.mp4 | |
rm playlist.m3u8 | |
rm playlist.txt | |
rm urllist.txt | |
rm *.ts |
Ok, here's a short guide on how to use this tool:
- You need Linux or Mac since this tool is relying on Unix CLI software. You'll need especially
parallel
andffmpeg
. On Mac install Homebrew (https://brew.sh/index_de) and then run the following commands:
brew install wget
brew install parallel
brew install ffmpeg
On Linux this commands should work
sudo apt install parallel
sudo apt install ffmpeg
Parallel wants you to cite it properly when you use it, so simply run parallel
and follow the instructions on the screen.
- If you have now everything required installed you will need the video key. This is a 32 character alphanumeric string that can be sometimes found in the URL, for example in this video: https://videocampus.sachsen.de/category/video/InternationalPublicEconomics0506/095a5342c795f69f6f8aa8d8e65054f1/118. There the key is
095a5342c795f69f6f8aa8d8e65054f1
. When the key is not in the URL (sorry, no example at hand) then open the URL, rightclick → view page source and look for the following line (something around line 20 I think):
<meta property="og:video:url" content="https://videocampus.sachsen.de/category/118/getMedium/095a5342c795f69f6f8aa8d8e65054f1.m4v" />
And there is the key.
- With the key you can run the script:
sh vcs-downloader.sh key filename
where key
is replaced by the key and filename
should be the filename of the final video you want to save.
Thanks for this short guide. It works perfectly nice, but unfortunately I have some problems with some videos. I'm sure that i have the right key, but the download still fail. Is it possible that you could help me with this?
Yeah sure, no problem. Just send me the link and I will look whats wrong with it
Maybe is it a authorization problem. Here is one of the links that failed to download. https://videocampus.sachsen.de/video/KW22152BalancedTrees/bdd6b893aa93b6d327f74b608fe960d8
Yes, this is an authentication problem. A few months ago you were able to download such videos, but now they have implemented proper authentication.
This is more a workaround then a implementation of the authentication, I've simply added the PHPSESSID
-Cookie. You need the value of this cookie, you can find it somewhere in the development-tools of your browser.
#file=$1
#videoname=$(echo "$file" | cut -d "." -f1)
#echo "$videoname"
touch playlist.txt
touch urllist.txt
key=$1
videoname=$2
#keystring=$(cat $file | grep -o -E "key=[0-9,a-z]+")
#key=$(echo "$keystring" | cut -c 5-)
link="https://videocampus.sachsen.de/media/hlsMedium/key/$key/format/auto/ext/mp4/learning/0/path/m3u8"
playlist=$(curl -s -H 'Cookie: PHPSESSID=abcdefghi;' "$link" | tail -n 1)
newLink="https://videocampus.sachsen.de/media/hlsMedium/key/$key/format/auto/ext/mp4/learning/0/path/$playlist"
wget -O playlist.m3u8 --header 'Cookie: PHPSESSID=abcdefghi;' "$newLink"
for line in $(cat playlist.m3u8 | grep ".ts"); do
partLink="https://videocampus.sachsen.de/media/hlsMedium/key/$key/format/auto/ext/mp4/learning/0/path/$line"
echo "$partLink" >> urllist.txt
echo "file $line" >> playlist.txt
done
cat urllist.txt | parallel -j 50 'wget --header "Cookie: PHPSESSID=abcdefghi;" {}'
ffmpeg -f concat -i playlist.txt -c copy $videoname.mp4
rm playlist.m3u8
rm playlist.txt
rm urllist.txt
rm *.ts
You have to replace the string abcdefghi
with your value of PHPSESSID
. I have no idea how long this session id is valid, hopefully is lasts long...
It works. Thank you. 👍
I have no idea how long this session id is valid
At least 24 mins until it's picked up by the garbage collector IIRC (usually longer because the garbage collector doesn't run every time), unless they've configured sth else (which I'd doubt..).
BTW thanks for the update.
Despite being able to run the parallel
command without an error return, it was not installed on my system.
That is why at first the script failed.
So to make it work I still had to run:
sudo apt install parallel
Thank you for providing the script!
I get this return when running the script. What am I doing wrong?
zsh: command not found: #file=
zsh: command not found: #videoname=
zsh: command not found: #echo
I get this return when running the script. What am I doing wrong?
zsh: command not found: #file= zsh: command not found: #videoname= zsh: command not found: #echo
Seems like your shell doesn’t understand comments. Maybe this will help: https://apple.stackexchange.com/questions/405246/zsh-comment-character
First, thanks for this awesome script and your help- its working now.
Maybe you have a solution for this problem:
Some of the videos I wanted to get (~5%) stop in the middle of the download with this error:
[concat @ 0x11e7052a0] Impossible to open '113d39a418c4bb8ffeb44311077bcf99_1638267204_480p_mp4_187.ts' playlist.txt: No such file or directory
The video this error is from: key=113d39a418c4bb8ffeb44311077bcf99
Strangely, it still saves the video. When I retry the same script, the new downloaded video has a different length than the previous but still isn't complete and throws the error. Do you have any idea what the problem could be?
First, thanks for this awesome script and your help- its working now. Maybe you have a solution for this problem:
Some of the videos I wanted to get (~5%) stop in the middle of the download with this error:
[concat @ 0x11e7052a0] Impossible to open '113d39a418c4bb8ffeb44311077bcf99_1638267204_480p_mp4_187.ts' playlist.txt: No such file or directory
The video this error is from: key=113d39a418c4bb8ffeb44311077bcf99 Strangely, it still saves the video. When I retry the same script, the new downloaded video has a different length than the previous but still isn't complete and throws the error. Do you have any idea what the problem could be?
I can’t test this right now but have you removed all created files after the download failed? The script creates playlist.m3u8, playlist.txt, urllist.txt and a lot of .ts files. Maybe there are some problems when the files aren’t empty (the script appends lines to these files, so there are problems when leftovers are in this files)
I just retried it without deleting anything and it worked for all videos.
The only thing I changed, is that I worked from a different network. No clue, what the problem was :)
To download some videos today I wasn't succesful with the script but these steps worked:
- In Browser login to Videocampus
- Press Play on the video
- Open Developer Tools > Tab Network
- Use the XHR filter
- Right-Click on any of the files of type ocet-stream, copy as link (German "Wer kopieren" > "Als Link kopieren")
- Replace the string as follows:
# in
https://videocampus.sachsen.de/media/hlsMedium/key/[String A]/format/auto/ext/mp4/learning/0/path/[String A]_[String B]_480p_mp4_193.ts
# out
https://videocampus.sachsen.de/getMedium/[String A].mp4?[String B]&format=1080p
Example:
# in
https://videocampus.sachsen.de/media/hlsMedium/key/f5eo8eezg6n19eo53v74a3965ll5rs02r/format/auto/ext/mp4/learning/0/path/f5eo8eezg6n19eo53v74a3965ll5rs02r_1666077443_480p_mp4_193.ts
# out
https://videocampus.sachsen.de/getMedium/f5eo8eezg6n19eo53v74a3965ll5rs02r.mp4?1666077443&format=1080p
Nice one, cheers.
Might want to add some instructions or some sort of convenience script for nicht-so-computer-affine peeps though because I had to install parallel (not a big deal for me but may be for others).
😃