-
-
Save guidocella/0ca7777158747290742aa444db6da256 to your computer and use it in GitHub Desktop.
#!/bin/sh | |
if [ $# -lt 2 ]; then | |
echo Usage: avgle-download.sh video_title url_of_last_segment | |
exit 1 | |
fi | |
# Visit a video page, open the network tab of the dev tools, | |
# seek to the end of the video and copy the url of the last .ts segment | |
# (the .m3u8 playlist is encoded and therefore harder to get). | |
curl --remote-name --output-dir /tmp --referer https://avgle.com $(echo $2 | sed -E 's/seg-([0-9]*)/seg-[1-\1]/') && | |
ffmpeg -i concat:$(ls -tr /tmp/*.ts | paste -sd '|') -c copy "$1.mp4" && | |
rm /tmp/*.ts |
This is a shell script for Unix-like systems, so if you use Windows you have to run it in Windows Subsystem for Linux. You need to download it, make it executable from a terminal with chmod +x /path/to/avgle-download.sh
, then run it with /path/to/avgle-download.sh 'your video filename' https://last_segment_url.ts
.
Unbelievable, its still works! Thanks for making this script..
I also cannot believe how small the code is.
The javascript downloader didn't work for me, so I guess this is an example of simple code working better. ;)
This could be even smaller and avoid the temporary files by using the ts urls directly with ffmpeg's concat protocol or demuxer, but unfortunately in that case FFmpeg ignores the -referer option which is necessary for downloading from avgle (https://stackoverflow.com/questions/54272901/cant-set-ffmpeg-header-when-using-file-for-input)
hi, Guidocella. thank you for this amazing simple sh.
but I have a question about curl cmd.
's/seg-([0-9])/seg-[1-\1]/'
[0-9]
Is regular expression right?
[1-\1]
Not a regular expression but telling curl to download seg-1.ts, seg-2.ts, seg-3.ts ...
Is that what I thought?
Thank you.
Yes, \1 is the backreference to the first capture group, which is the number of the last segment [0-9]*. So curl sees something https://foo/seg-[1-70].ts which it interprets as downloading everything from 1 to 70. This is documented at the very start of man curl
.
not good at shell command. but author's code not working in my mac. if any one have the same issue my my code can help.
- save my code as run.sh
- put run.sh in some folder.ex: /Users/$YOUR_USER_NAME$/Downloads/tmp
- cd into the folder (as curl --output-dir not working in my mac)
- confirm you have already install ffmpeg, if not use
brew install ffmpeg
install it. - first time run the shell need call
chmod +x run.sh
#!/bin/sh
if [ $# -lt 2 ]; then
echo Usage: avgle-download.sh video_title url_of_last_segment
exit 1
fi
# Visit a video page, open the network tab of the dev tools,
# seek to the end of the video and copy the url of the last .ts segment
# (the .m3u8 playlist is encoded and therefore harder to get).
curl --remote-name --referer https://avgle.com $(echo $2 | sed -E 's/seg-([0-9]*)/seg-[1-\1]/')
ls *.ts | sed 's/^\([^0-9]*\)\([0-9]*\)/\1 \2/' | sort -k2,2n | tr -d ' ' |
while read f; do
echo "file '$f'" >> mylist.txt
done
ffmpeg -f concat -safe 0 -i mylist.txt -c copy $1.mp4
rm mylist.txt
rm *.ts
can u elaborate your method? I am quite newbies in this field. I have found the last .ts segment but don't know what to do next.