Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # SPDX-License-Identifier: GPL-2.0
- # Copyright (C) 2020-present Dorik1972 aka Pepsik =)
- bytesToHumanReadable() {
- local i=${1:-0} d="" s=0 S=("B" "KiB" "MiB" "GiB" "TiB" "PiB" "EiB" "YiB" "ZiB")
- local YELLOW='\033[0;33m'
- local NC='\033[0m' # No Color
- printf -v i '%d' "$i" 2>/dev/null
- while ((i > 1024 && s < ${#S[@]}-1)); do
- printf -v d ".%02d" $((i % 1024 * 100 / 1024))
- i=$((i / 1024))
- s=$((s + 1))
- done
- echo " ${YELLOW}$i$d${NC} ${S[$s]}"
- }
- function process_pl {
- local URL="$1"
- local PLAYLIST="$2"
- local YELLOW='\033[0;33m'
- local LRED='\033[0;31m'
- local GREEN='\033[0;32m'
- local LGRAY='\033[0;37m'
- local NC='\033[0m' # No Color
- [ "$(whois $(curl -s ifconfig.me) | awk 'tolower($1) ~ /^country:/ { print $2 }')" == "RU" ] && { echo -e >&2 "${LRED}РУССКИЙ - ИДИ НАХУЙ!${NC}"; exit 1; }
- echo -e "${GREEN}Get and parse the playlist ...${NC}"
- response=$(curl --compressed --location --connect-timeout 10 --max-time 30 --fail --write-out '%{response_code} %{speed_download} %{size_download}' -H 'Cache-Control: no-cache' -R -s "$URL")
- [ $? -eq 1 ] && { echo -e >&2 "${LRED}Unexpected error in curl utility.\nCheck curl version it should be >= 7.64 and support --write-out and --compressed options${NC}"; exit 1; }
- read -r response_code speed_download size_download < <(tail -n1 <<<"$response")
- if [[ $response_code == 200 ]]; then
- echo -e "Download size : $(bytesToHumanReadable ${size_download})\nDownload speed: $(bytesToHumanReadable ${speed_download})ps"
- Count=$(<<<"$response" wc -l | xargs)
- ((--Count))
- echo "$response" | head -n $Count |
- awk '!a[$0]++' | awk 'substr($1,1,8)!=p{print;p=substr($1,1,8)}' |
- awk '{gsub("x-tvg-url","url-tvg");gsub("localhost",h);gsub("00000000000000",k);gsub("epg.xml.gz","epg2.xml.gz");gsub("/img/","/img2/");print}' h="${HOST}" k="${KEY}" > ${PLAYLIST}.m3u
- else
- echo -e "${LRED}HTTP response code: ${YELLOW}${response_code}${NC}"
- echo -e "${LRED}Failed to download playlist template. Perhaps the resource is not available or there was an error in the template url-link${NC}"
- exit 1
- fi
- echo -e "${GREEN}Processing the categories:${NC}"
- for CAT in "${!categories[@]}"; do
- [ ${categories[$CAT]} == 0 ] && sed -i'.bak' "/$CAT/,/^/d" ${PLAYLIST}.m3u || echo -e "\t${LGRAY}$CAT${NC}" # .bak is used for MacOS & BSD compatibility
- done
- find $ADDON -name "*.bak" -type f -delete
- echo -e "Done\n${GREEN}Sort the playlist alphabetically${NC}"
- tail -n +2 ${PLAYLIST}.m3u | sed "N;s/\n/,\t/g" | sort -fV -k 2 -t , | sed "s/,\t/\n/g" | sed -e $'1i\\\n'"$(head -n 1 ${PLAYLIST}.m3u)" > ${PLAYLIST}_sorted.m3u
- echo -e "Done\n${GREEN}Playlists created:${NC}\n\t${PLAYLIST}.m3u\n\t${PLAYLIST}_sorted.m3u"
- echo -e "${YELLOW}Processed ${Count} lines in ${SECONDS} seconds.${NC}"
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement