diff --git a/anime-rss.py b/anime-rss.py index b33c354..680bd0b 100644 --- a/anime-rss.py +++ b/anime-rss.py @@ -17,7 +17,15 @@ BOLD_GREEN = BOLD + GREEN feeds = [] config = [] -with open("shows.json", "r") as feeds: + +def build_target_folder(): + if config["dirPerAnime"]: + return config["animeDownloadDir"] + "/" + anime["Title"].replace(" ", "_"); + else: + return config["animeDownloadDir"] + + +with open("animes.json", "r") as feeds: feeds = json.load(feeds) with open("config.json", "r") as config: @@ -27,23 +35,23 @@ 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 anime in feed["Animes"]: + print("Checking anime: " + BOLD_RED + anime["Title"] + RESET) for entry in NewsFeed.entries: - if show["Title"] in entry.title: - regex = feed["Episode-Regex"].replace("$SHOWS$", show["Title"]) + if anime["Title"] in entry.title: + regex = feed["Episode-Regex"].replace("$SHOWS$", anime["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) + if int(episodeNumber[0]) > int(anime["Local"]): + print(BOLD_GREEN + "NEW NEW NEW " + anime["Title"] + " " + episodeNumber[0] + RESET) - subprocess.run(["transmission-remote", "-a", entry.link, "-w", config["showDownloadDir"]]) + subprocess.run(["transmission-remote", "-a", entry.link, "-w", build_target_folder()]) - show["Local"] = str(int(show["Local"]) + 1).zfill(2) + anime["Local"] = str(int(anime["Local"]) + 1).zfill(2) -with open("shows.json", "w") as new_feeds: +with open("animes.json", "w") as new_feeds: new_feeds.write(json.dumps(feeds, indent=3)) diff --git a/shows.json b/animes.json similarity index 94% rename from shows.json rename to animes.json index c56e365..a16de78 100644 --- a/shows.json +++ b/animes.json @@ -3,7 +3,7 @@ { "ID": "SubsPlease", "URL": "https://subsplease.org/rss/?t&r=1080", - "Shows": [ + "Animes": [ { "Title": "Go-toubun no Hanayome S2", "Local": "02" @@ -18,7 +18,7 @@ }, { "Title": "Ore dake Haireru Kakushi Dungeon", - "Local": "02" + "Local": "01" }, { "Title": "Tensei Shitara Slime Datta Ken", @@ -34,7 +34,7 @@ { "ID": "Nyaa Kaifuku Jutsushi no Yarinaoshi", "URL": "https://nyaa.si/?page=rss&q=%5Bjackie%5D+Kaifuku+Jutsushi+no+Yarinaoshi+-&c=0_0&f=0", - "Shows": [ + "Animes": [ { "Title": "Kaifuku Jutsushi no Yarinaoshi", "Local": "01" @@ -45,7 +45,7 @@ { "ID": "Nyaa Shingeki no Kyojin", "URL": "https://nyaa.si/?page=rss&q=%5BDameDesuYo%5D+Shingeki+no+Kyojin+%28The+Final+Season%29+-+&c=0_0&f=0", - "Shows": [ + "Animes": [ { "Title": "Shingeki no Kyojin", "Local": "64" diff --git a/config.json b/config.json index a6d8924..fdda36f 100644 --- a/config.json +++ b/config.json @@ -1,3 +1,4 @@ { - "showDownloadDir": "/media/ssd/temp/" + "animeDownloadDir": "/media/ssd/temp", + "dirPerAnime": true } \ No newline at end of file