0
0
mirror of https://github.com/anthonyaxenov/iptv.git synced 2024-11-22 05:24:45 +00:00

Tools updated

This commit is contained in:
Anthony Axenov 2022-10-22 22:44:05 +08:00
parent 1a6e763350
commit cfda93e022
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC
4 changed files with 90 additions and 92 deletions

View File

@ -18,13 +18,12 @@
TOOLS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"; TOOLS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
DL_DIR="$TOOLS_DIR/downloaded" DL_DIR="$TOOLS_DIR/downloaded"
ROOT_DIR="`dirname "$TOOLS_DIR"`" INI_FILE="$(dirname "$TOOLS_DIR")/playlists.ini"
INI_FILE="$ROOT_DIR/playlists.ini"
rm -rf "$DL_DIR" && \ rm -rf "$DL_DIR" && \
mkdir -p "$DL_DIR" && \ mkdir -p "$DL_DIR" && \
cd "$DL_DIR" && \ cd "$DL_DIR" && \
cat "`dirname "$TOOLS_DIR"`/playlists.ini" \ cat "$INI_FILE" \
| grep -P "pls\s*=\s*'(.*)'" \ | grep -P "pls\s*=\s*'(.*)'" \
| sed "s#^pls\s*=\s*##g" \ | sed "s#^pls\s*=\s*##g" \
| sed "s#'##g" \ | sed "s#'##g" \

View File

@ -17,9 +17,9 @@
################################################# #################################################
TOOLS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"; TOOLS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
ROOT_DIR="`dirname "$TOOLS_DIR"`" DL_DIR="$TOOLS_DIR/downloaded"
[ ! -d "$TOOLS_DIR/downloaded" ] && echo "Error: 'tools/downloaded' directory does not exist. Run tools/download-all.sh" && exit 1 [ ! -d "$DL_DIR" ] && echo "Error: 'tools/downloaded' directory does not exist. Run tools/download-all.sh" && exit 1
[ ! "$(ls -A $TOOLS_DIR/downloaded)" ] && echo "Error: 'tools/downloaded' directory is empty. Run tools/download-all.sh" && exit 2 [ ! "$(ls -A "$DL_DIR")" ] && echo "Error: 'tools/downloaded' directory is empty. Run tools/download-all.sh" && exit 2
for file in $TOOLS_DIR/downloaded/*; do for file in $TOOLS_DIR/downloaded/*; do
$TOOLS_DIR/find-in-pls.sh "$1" "$file" $TOOLS_DIR/find-in-pls.sh "$1" "$file"
done done

View File

@ -22,59 +22,63 @@
# #
################################################# #################################################
awk ' channel="$1"
BEGIN { playlist="$2"
IGNORECASE=1 playlist_url="$playlist"
channel = ARGV[1] regex_ch="^#extinf:\s*-?[01]\s*.*,(.*${channel,,}.*)"
playlist = ARGV[2] regex_url="^https?:\/\/.*$"
found_count = 0
found_last = 0
regex_ch = tolower(sprintf("^#EXTINF:.+,\s*(.*%s.*)", channel))
regex_url = "^https?:\/\/.*$"
print "--------------------" is_downloaded=0
print "\033[20m\033[97mPlaylist:\033[0m " playlist download_dir="/tmp/$(date '+%s%N')"
print "\033[20m\033[97mChannel to find:\033[0m " channel
if (playlist ~ /^http(s)?:\/\/.*/) { found_count=0
parts_count = split(playlist, parts, "/") found_last=0
file_name = parts[parts_count] line_count=1
code = system("wget " playlist " -qO /tmp/" file_name " > /dev/null")
if (code == 0) { if [[ "$playlist" =~ $regex_url ]]; then
print "Saved in /tmp/" file_name mkdir -p "$download_dir"
} else { cd "$download_dir"
print "ERROR: cannot download playlist: " playlist wget "$playlist" -q > /dev/null
if [ $? -eq 0 ]; then
is_downloaded=1
playlist="$download_dir/$(ls -1 "$download_dir")"
cd -
else
echo "ERROR: cannot download playlist: $playlist"
exit 1 exit 1
} fi
playlist = "/tmp/" file_name fi
}
ARGV[1] = playlist echo "--------------------"
delete ARGV[2] echo -e "\033[20m\033[97mChannel:\033[0m $channel"
print "--------------------" echo -e "\033[20m\033[97mPlaylist:\033[0m $playlist_url"
} echo -e "\033[20m\033[97mRegex:\033[0m $regex_ch"
{ echo "--------------------"
sub("\r$", "", $0) # crlf -> lf
if (tolower($0) ~ tolower(regex_ch)) { while read line; do
found_count++ if [[ "${line,,}" =~ $regex_ch ]]; then
print "\n\033[32m" FNR " FOUND:\033[0m\t" $0 echo -e "\n\033[32m$line_count FOUND:\033[0m\t$line"
found_last = FNR ((found_count += 1))
} found_last=$found_count
if (found_last > 0) { fi
if (tolower($0) ~ tolower(regex_url)) { if [ $found_last -gt 0 ]; then
print "\t\t" $0 if [[ "${line,,}" =~ $regex_url ]]; then
found_last = 0 echo -e "\t\t$line"
} found_last=0
} fi
} fi
END { ((line_count += 1))
if (found_count == 0) { done < $playlist
print "\033[91mNothing found\033[0m"
} else { if [ $found_count -eq 0 ]; then
print "--------------------" echo -e "\033[91mNothing found\033[0m"
print "\033[20m\033[97mPlaylist:\033[0m " playlist else
print "\033[20m\033[97mChannel found:\033[0m " channel echo "--------------------"
print "\033[20m\033[97mFound:\033[0m\033[32m " found_count "\033[0m" echo -e "\033[20m\033[97mPlaylist:\033[0m $playlist_url"
} echo -e "\033[20m\033[97mChannel:\033[0m $channel"
} echo -e "\033[20m\033[97mFound:\033[0m\033[32m $found_count\033[0m"
' $1 $2 fi
if [ $is_downloaded -eq 1 ]; then
rm -rf "$download_dir"
fi

View File

@ -1,4 +1,3 @@
#!/bin/bash #!/bin/bash
################################################# #################################################
@ -20,41 +19,37 @@
# #
################################################# #################################################
#SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )"; TOOLS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]:-$0}"; )" &> /dev/null && pwd 2> /dev/null; )";
SCRIPT_DIR="$(cd "$(dirname "$0")" >/dev/null 2>&1 && pwd)" DL_DIR="$TOOLS_DIR/downloaded"
[ ! -d ./downloaded ] && echo "Error: ./downloaded directory does not exist. Run $SCRIPT_DIR/tools/download-all.sh" && exit 1 [ ! -d "$DL_DIR" ] && echo "Error: 'tools/downloaded' directory does not exist. Run tools/download-all.sh" && exit 1
[ ! "$(ls -A ./downloaded)" ] && echo "Error: ./downloaded directory is empty. Run $SCRIPT_DIR/tools/download-all.sh" && exit 2 [ ! "$(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 "#EXTM3U"
echo "# Autogenerated at `date +%d.%m.%Y`" echo "# Autogenerated at `date +%d.%m.%Y`"
echo "# https://github.com/anthonyaxenov/iptv" echo "# https://github.com/anthonyaxenov/iptv"
echo echo
for file in ./downloaded/*; do for file in ./downloaded/*; do
awk ' while read line; do
BEGIN { if [[ "${line,,}" =~ $regex_ch ]]; then
IGNORECASE=1 echo -e "$line"
"date +%Y-%m-%d" | getline date ((found_count += 1))
channel = ARGV[1] found_last=$found_count
playlist = ARGV[2] fi
ARGV[1] = playlist if [ $found_last -gt 0 ]; then
delete ARGV[2] if [[ "${line,,}" =~ $regex_url ]]; then
found_count = 0 echo -e "$line\n"
found_last = 0 found_last=0
regex_ch = tolower(sprintf("^#EXTINF:.+,\s*(.*%s.*)", channel)) fi
regex_url = "^https?:\/\/.*$" fi
} done < $file
{
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 done