#! /bin/bash

set -e

remote="${remote:-192.168.0.86}"

feeds='
https://mangadex.org/rss/follows/ryZGFkVgv9DAPqf45EsTHuQcxmteKBN6                manga                      na                                     na "1h"
https://siftrss.com/f/WXPo6AKQLX                                                 manga                      na                                     na "1h"
http://yaoi-blcd.tumblr.com/tagged/19-days/rss                                   manga                      "Old.Xian.update.of..19"               na "4h"
http://www.shanaproject.com/feeds/secure/user/5310/5MUGNU9B3I/                   anime                      na                                     na "24h"
http://www.manga.megchan.com/blog/?feed=rss2                                     manga                      na                                     na "12h"
https://siftrss.com/f/6Q8a0ZK0RmL                                                manga                      na                                     na "12h"
https://dropoutmanga.wordpress.com/feed/                                         manga                      "(Hatsukoi|Tomo.chan)"                 na "6h"
http://merakiscans.com/manga-rss/solo-leveling/                                  manga                      na                                     na "8h"
http://www.mangago.me/r/rsslink/a_man_like_you.xml                               manga                      na                                     na "24h"
http://www.mangago.me/r/rsslink/unriped_expression.xml                           manga                      na                                     na "24h"
http://www.mangago.me/r/rsslink/heesu_in_class_2.xml                             manga                      na                                     na "24h"
http://www.mangago.me/r/rsslink/bj_alex.xml                                      manga                      na                                     na "24h"
https://heroscans.tumblr.com/rss                                                 manga                      "(Saizu)"                              na "24h"
http://feeds.pinboard.in/rss/popular/                                            news                       ".*"                                   ".*" "24h"
https://www.vox.com/rss/index.xml                                                news                       "yeahrightnoway"                       ".*" "24h"
https://www.techdirt.com/techdirt_rss.xml                                        news                       ".*"                                   ".*" "24h"
http://hotdiggedydemon.com/                                                      comic                      ".*"                                   ".*"  "24h"
https://nyaa.si/?page=rss&u=Nauti                                                anime                      "(akegurui.*XX)"                       ".*Anime...English.translated.*" "3h"
https://tapas.io/rss/series/72832                                                manga                      na                                     na "24h"
https://tapas.io/rss/series/88570                                                manga                      na                                     na "24h"
https://nyaa.si/?page=rss&q=kakegurui&c=0_0&f=0&u=Nauti                          anime                      "(akegurui.XX)"                        ".*Anime...English.translated.*" "3h"
https://nyaa.si/?page=rss&q=horriblesubs+mob+psycho+720&c=0_0&f=0                anime                      ".*"                                   ".*Anime...English.translated.*" "3h"
https://www.youtube.com/feeds/videos.xml?channel_id=UC9CuvdOVfMPvKCiwdGKL3cQ     youtube","gampegrumps      ".*"                                   ".*" "6h"
https://www.youtube.com/feeds/videos.xml?channel_id=UCbGO1tCyjMlzqIT-tyrJNqQ     youtube","kshaway          ".*"                                   ".*" "6h"
https://www.youtube.com/feeds/videos.xml?channel_id=UC9YLd0REiXxLqQQH_CpJKZQ     youtube","instalok         ".*"                                   ".*" "6h"
https://www.youtube.com/feeds/videos.xml?channel_id=UCsvn_Po0SmunchJYOWpOxMg     youtube","videogamedunkey  ".*"                                   ".*" "6h"
https://www.youtube.com/feeds/videos.xml?channel_id=UCs-w7E2HZWwXmjt9RTvBB_A      youtube","settled         ".*"                                   ".*" "6h"
https://roosterteeth.com/show/rt-podcast/feed/mp3                                podcast                    ".*"                                   ".*" "6h"
http://lizclimo.tumblr.com/rss                                                   comic                      na                                     na "24h"
http://feeds.feedburner.com/blogspot/sBff                                        cooking                    ".*"                                   ".*" "24h"
https://jaiminisbox.com/reader/feeds/rss                                         manga                      "olo.*eveling"                         ".*" "6h"
https://xkcd.com/atom.xml                                                        comic                      na                                     na "24h"
https://matrix.org/blog/feed                                                     news                       ".*"                                   ".*"  "1h"
https://nyaa.si/?page=rss&f=0&c=0_0&q=shingeki+no+kyojin+final+season+720p       anime","torrent            ".*"                                   ".*"  "1h"     Anime-ShingekiNoKyojin
https://workchronicles.com/feed/                                                 comic                      na                                     na    "4h"
https://nyaa.si/?page=rss&f=0&c=0_0&q=re+zero+2nd+part+erai+raws+720             anime","torrent            ".*"                                   ".*"  "2h"     Anime-ReZero
https://www.webtoons.com/en/challenge/books-of-adam/rss?title_no=136637          comic                      na                                     na    "12h"
https://www.webtoons.com/en/romance/the-makeup-remover/rss?title_no=2186         comic                      na                                     na    "12h"
https://www.webtoons.com/en/romance/truebeauty/rss?title_no=1436                 comic                      na                                     na    "12h"
https://subsplease.org/rss/?r=720                                                anime","torrent            "^jfkaldsjfkldsjafd;sa"                "<a.*?href=.magnet:.*?</a>"              "2h"     Anime
https://eztv.ag/ezrss.xml?h=h                                                    torrent                    "^([Rr]ick.[Aa]nd.[Mm]orty)"                 "<a.*?href=.magnet:.*?</a>"  "2h"     RickAndMorty
https://eztv.ag/ezrss.xml?c=c                                                    momma","torrent            "^NOT(d.Rush.*720.*WEB|Gold.Rush.*S.*E.*720.*WEB)"  "<a.*?href=.magnet:.*?</a>"                                                     "2h"     GoldRush
https://eztv.ag/ezrss.xml?e=e                                                    momma","torrent            "^(Archer|The.Handmaids.Tale.*720.*WEB|Australian.Ninja.Warrior.*HDTV)"  "<a.*?href=.magnet:.*?</a>"                                "2h"
https://eztv.ag/ezrss.xml?b=b                                                    momma","torrent            "^(Survivor.S.*720p|[Ss]urvivor.*[AaSs][UuAa])"  "<a.*?href=.magnet:.*?</a>"                                                         "2h"     Survivor
https://eztv.ag/ezrss.xml?a=a                                                    momma","torrent            "^abc123(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal)"  "<a.*?href=.magnet:.*?</a>"  "2h"     GameShows
https://eztv.ag/ezrss.xml?d=d                                                    momma","torrent            "([Mm]andalorian)"                     "<a.*?href=.magnet:.*?</a>"                                              "2h"     Mandalorian
https://eztv.ag/ezrss.xml?f=f                                                    momma","torrent            "^([Vv]ikings.S)"                                  "<a.*?href=.magnet:.*?</a>"  "2h"     Vikings
https://eztv.ag/ezrss.xml?g=g                                                    torrent","news             "^([Ll]ast..eek..onight..ith..ohn..liver.*WEB)"                                        "<a.*?href=.magnet:.*?</a>"  "2h"     LastWeekTonight
https://eztv.ag/ezrss.xml?d=d                                                    cooking","torrent          "^([Mm]aster[cC]hef.*720p.WEB|[Mm]aster[cC]hef.Aus.*)"  "<a.*?href=.magnet:.*?</a>"                                              "2h"     MasterChef
http://rss.slashdot.org/Slashdot/slashdotMain?format=usm                         news                       ".*"                                   ".*"  "6h"
https://netflixtechblog.com/feed                                                 news                       ".*"                                   ".*"  "6h"
https://www.backblaze.com/blog/feed                                              news                       "zzzzzzzzzzzzzz.*"                                   "zzzzzzzzzzzzzzzzzz.*"  "6h"
https://hackernoon.com/feed                                                      news                       "zzzzzzzzzzzzzz.*"                                   "zzzzzzzzzzzzzzzzzz.*"  "6h"
https://github.com/jpochyla/psst/commits.atom                                    news                       ".*"                                   ".*"  "6h"
https://eztv.re/ezrss.xml?b=b                                                    momma","torrent            "^(Survivor.S.*720p|[Ss]urvivor.*[AaSs][UuAa])"  "<a.*?href=.magnet:.*?</a>"                                                         "2h"     Survivor
https://gitlab.com/famedly/conduit.atom                                          news                       "loljkcancelthisone"                   "loljkcancelpls"  "1288h"
https://gitlab.com/famedly/conduit/-/tags?format=atom                            news                       ".*"                                   ".*"  "6h"
'
#https://eztv.ag/ezrss.xml                                                        momma","torrent            "^(Wheel.[oO]f.Fortune.[S2]|Jeopardy.20|Gold.Rush.*720.*WEB|Survivor.S.*720p|Gold.Rush.*S.*E.*720.*WEB|Archer|[Mm]aster[cC]hef.US.*720p.WEB|[Mm]aster[cC]hef.Aus.*|[tT]he.[pP]rice.[iI]s.[rR]ight|[lL]et.*[mM]ake.[aA].[dD]eal|The.Handmaids.Tale.*720.*WEB|[Ss]urvivor.*[AaSs][UuAa]|Australian.Ninja.Warrior.*HDTV)"  "<a.*?href=.magnet:.*?</a>" "2h"
feedsB="$(printf "%s\n" "$feeds" | grep -v '^$' | tail -n 1)"
feeds="$feedsB"

defaultIF='""'
defaultCF='"<img.*?/(img)?>"'
defaultIN='"6h"'

feeds="${feeds// /,,}"

for feed in $feeds; do
   feed="${feed//,,/ }"
   link="$(echo "$feed" | awk '{print $1}')"
   tag="$(echo "$feed" | awk '{print $2}')"
   if="$(echo "$feed" | awk '{print $3}')"
   cf="$(echo "$feed" | awk '{print $4}')"
   in="$(echo "$feed" | awk '{print $5}')"
   copyright="$(echo "$feed" | awk '{print $6}')"
   if [ "$if" == "na" ]; then
      if="$defaultIF"
   fi
   if [ "$cf" == "na" ]; then
      cf="$defaultCF"
   fi
   if [ "$in" == "na" ]; then
      in="$defaultIN"
   fi
   cmd="curl ${PROXY:-} -i ${remote}:33419/api/feed -X PUT --data '{\"url\":\"$link\", \"refresh\":$in, \"items\":$if, \"content\":$cf, \"tags\":[\"$tag\"], \"copyright\":\"$copyright\", \"headers\": {\"Cookie\": \"cf_chl_rc_ni=1; cf_clearance=fd4ce60270476e0a520dcde90c81d3d478fcecf9-1623375837-0-150\", \"User-Agent\": \"Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0\"}}'"
   echo "$cmd" >&2
   eval "$cmd"
done
