1
0
Files
anime-rss/anime-rss.py

48 lines
1.4 KiB
Python

import feedparser
import json
import re
import subprocess
# ANSI escape sequence coloring
CSI = "\x1B["
BOLD = CSI + "1;49m"
RESET = CSI + "0;0m"
RED = CSI + "91;49m"
GREEN = CSI + "92;49m"
BOLD_RED = BOLD + RED
BOLD_GREEN = BOLD + GREEN
feeds = []
config = []
with open("shows.json", "r") as feeds:
feeds = json.load(feeds)
with open("config.json", "r") as config:
config = json.load(config)
for feed in feeds["Feeds"]:
print(BOLD + "Checking feed: " + feed["ID"] + RESET)
NewsFeed = feedparser.parse(feed["URL"])
for show in feed["Shows"]:
print("Checking show: " + BOLD_RED + show["Title"] + RESET)
for entry in NewsFeed.entries:
if show["Title"] in entry.title:
regex = feed["Episode-Regex"].replace("$SHOWS$", show["Title"])
match = re.match(regex, entry.title)
if match:
episodeNumber = match.groups()
if int(episodeNumber[0]) > int(show["Local"]):
print(BOLD_GREEN + "NEW NEW NEW " + show["Title"] + " " + episodeNumber[0] + RESET)
subprocess.run(["transmission-remote", "-a", entry.link, "-w", config["showDownloadDir"]])
show["Local"] = str(int(show["Local"]) + 1).zfill(2)
with open("shows.json", "w") as new_feeds:
new_feeds.write(json.dumps(feeds, indent=3))