0
0
mirror of https://github.com/anthonyaxenov/iptv.git synced 2024-11-24 22:34:34 +00:00
iptv/tools/make-pls.sh
AnthonyAxenov 1a2bc188c6
Some new stuff
- MIT License
- new make-pls.sh
- some tools refactoring and documentation
2022-06-09 11:51:25 +08:00

61 lines
1.8 KiB
Bash
Executable File

#!/bin/bash
#################################################
#
# IPTV channel maker (all playlists)
#
# Usage:
# ./download-all.sh
# ./make-pls.sh "disney"
#
# 1st argument is channel name pattern.
#
# To save output in file use redirection:
# ./make-pls.sh "disney" > disney.m3u8
#
# Anthony Axenov (c) 2022
# The MIT License:
# https://github.com/anthonyaxenov/iptv/blob/master/LICENSE
#
#################################################
#SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
SCRIPT_DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)"
[ ! -d ./downloaded ] && echo "Error: ./downloaded directory does not exist. Run $SCRIPT_DIR/tools/download-all.sh" && exit 1
[ ! "$(ls -A ./downloaded)" ] && echo "Error: ./downloaded directory is empty. Run $SCRIPT_DIR/tools/download-all.sh" && exit 2
echo "#EXTM3U"
echo "# Autogenerated at `date +%d.%m.%Y`"
echo "# https://github.com/anthonyaxenov/iptv"
echo
for file in ./downloaded/*; do
awk '
BEGIN {
IGNORECASE=1
"date +%Y-%m-%d" | getline date
channel = ARGV[1]
playlist = ARGV[2]
ARGV[1] = playlist
delete ARGV[2]
found_count = 0
found_last = 0
regex_ch = tolower(sprintf("^#EXTINF:.+,\s*(.*%s.*)", channel))
regex_url = "^https?:\/\/.*$"
}
{
sub("\r$", "", $0) # crlf -> lf
if (tolower($0) ~ tolower(regex_ch)) {
print $0
found_count++
found_last = FNR
}
if (found_last > 0) {
if (tolower($0) ~ tolower(regex_url)) {
print $0 "\n"
found_last = 0
}
}
}
' "$1" "$file"
done