Skip to content

Instantly share code, notes, and snippets.

@guidocella
Last active June 7, 2024 13:38
Show Gist options
  • Save guidocella/0ca7777158747290742aa444db6da256 to your computer and use it in GitHub Desktop.
Save guidocella/0ca7777158747290742aa444db6da256 to your computer and use it in GitHub Desktop.
Download videos from avgle.com
#!/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
@chunlin-pan
Copy link

chunlin-pan commented Oct 20, 2021

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.

@guidocella
Copy link
Author

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.

@Tunied
Copy link

Tunied commented Nov 2, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment