Tools updated

This commit is contained in:
2022-10-22 22:44:05 +08:00
parent 1a6e763350
commit cfda93e022
4 changed files with 90 additions and 92 deletions

View File

@@ -1,4 +1,3 @@
#!/bin/bash
#################################################
@@ -20,41 +19,37 @@
#
#################################################
#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
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
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"
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