category.dcgi - gophercgis - Collection of gopher CGI/DCGI for geomyidae
 (HTM) hg clone https://bitbucket.org/iamleot/gophercgis
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
       category.dcgi
       ---
            1 #!/bin/sh
            2 
            3 . ../common/config.sh
            4 
            5 CGI="${CGI_BASEDIR}/mediasetplay/category.dcgi"
            6 
            7 case "$2" in
            8 */*)
            9         category=${2%%/*}
           10         start_index=${2##*/}
           11         ;;
           12 *)
           13         category=$2
           14         start_index=1
           15         ;;
           16 esac
           17 
           18 url="https://feed.entertainment.tv.theplatform.eu/f/PR1GhC/mediaset-prod-all-programs?byTags=category:${category}&startIndex=${start_index}"
           19 
           20 echo ""
           21 echo "MEDIASET"
           22 echo "play"
           23 echo ""
           24 
           25 curl -Lgs "${url}" |
           26 jq -r '
           27         ( .entries[] |
           28                 .title + "\t" +
           29                 "https:\(."mediasetprogram$videoPageUrl")" + "\t" +
           30                 .description
           31         ),
           32         if .entryCount == .itemsPerPage then
           33                 "Next" + "\t" + "'"${CGI}?${category}/"'" + ((.startIndex + .entryCount) | tostring)
           34         else
           35                 empty
           36         end
           37 ' |
           38 awk -F "\t" '
           39 
           40 function print_description(text)
           41 {
           42         cmd = "par -d 0 -B=. -w 72"
           43         cmd = cmd " | sed -e \"s/^/t/\""
           44 
           45         print text | cmd
           46         close(cmd)
           47 }
           48 
           49 # entries
           50 NF == 3 {
           51         title = $1
           52         url = $2
           53         description = $3
           54 
           55         gsub("\\|", "\\|", title)
           56 
           57         printf("[h|%s|URL:%s|server|port]\n", title, url)
           58         print_description(description)
           59         printf("t\n")
           60 }
           61 
           62 # pagination
           63 NF == 2 {
           64         printf("[1|%s|%s|server|port]\n", $1, $2)
           65 }
           66 '