0
0
mirror of https://github.com/anthonyaxenov/iptv.git synced 2024-11-25 06:44:25 +00:00
iptv/tools/make-pls.sh

56 lines
1.5 KiB
Bash
Raw Normal View History

#!/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
#
#################################################
2022-10-22 14:44:05 +00:00
TOOLS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
DL_DIR="$TOOLS_DIR/downloaded"
[ ! -d "$DL_DIR" ] && echo "Error: 'tools/downloaded' directory does not exist. Run tools/download-all.sh" && exit 1
[ ! "$(ls -A "$DL_DIR")" ] && echo "Error: 'tools/downloaded' directory is empty. Run tools/download-all.sh" && exit 2
channel="$1"
playlist="$2"
regex_ch="^#extinf:\s*-?[01]\s*.*,(.*${channel,,}.*)"
regex_url="^https?:\/\/.*$"
found_count=0
found_last=0
echo "#EXTM3U"
echo "# Autogenerated at `date +%d.%m.%Y`"
echo "# https://github.com/anthonyaxenov/iptv"
echo
2022-10-22 14:44:05 +00:00
for file in ./downloaded/*; do
2022-10-22 14:44:05 +00:00
while read line; do
if [[ "${line,,}" =~ $regex_ch ]]; then
echo -e "$line"
((found_count += 1))
found_last=$found_count
fi
if [ $found_last -gt 0 ]; then
if [[ "${line,,}" =~ $regex_url ]]; then
echo -e "$line\n"
found_last=0
fi
fi
done < $file
done