aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2020-02-18 19:58:34 +0100
committerdec05eba <dec05eba@protonmail.com>2020-07-06 07:12:34 +0200
commit00935f29c204f51e84f350f7e2be7d32e971de48 (patch)
tree6b3cc4790dc261de883486e7934232b0fc133244
parent28c06c51a7c043fdc2226df92468540dcfd60724 (diff)
Fix previous torrent link used instead of new one when syncing rss
-rwxr-xr-xautomedia.py40
1 files changed, 9 insertions, 31 deletions
diff --git a/automedia.py b/automedia.py
index c0fa961..c7539e2 100755
--- a/automedia.py
+++ b/automedia.py
@@ -27,26 +27,22 @@ only_show_finished_notification = True
class TrackedRss:
title = None
- latest = None
link = None
json_data = None
- def __init__(self, title, latest, link, json_data):
+ def __init__(self, title, link, json_data):
self.title = title
- self.latest = latest
self.link = link
self.json_data = json_data
class TrackedHtml:
title = None
- latest = None
link = None
plugin = None
json_data = None
- def __init__(self, title, latest, link, plugin, json_data):
+ def __init__(self, title, link, plugin, json_data):
self.title = title
- self.latest = latest
self.link = link
self.plugin = plugin
self.json_data = json_data
@@ -94,7 +90,6 @@ def get_tracked_rss(rss_tracked_dir, existing_tracked_rss):
if in_progress:
print("Skipping in-progress rss %s" % title)
continue
- latest = get_file_content_or_none(os.path.join(rss_tracked_dir, title, "latest"))
link = get_file_content_or_none(os.path.join(rss_tracked_dir, title, "link"))
json_data = get_file_content_or_none(os.path.join(rss_tracked_dir, title, "data"))
if json_data:
@@ -106,20 +101,15 @@ def get_tracked_rss(rss_tracked_dir, existing_tracked_rss):
"updated": updated,
"downloaded": []
}
- if latest:
- json_data["downloaded"].append({ "title": latest, "time": updated })
if not link or not json_data:
print("Rss corrupt, link or data missing for rss %s" % title)
continue
- tracked_rss.append(TrackedRss(title, latest, link, json_data))
+ tracked_rss.append(TrackedRss(title, link, json_data))
return tracked_rss
except FileNotFoundError:
return []
def rss_update_latest(rss_tracked_dir, rss, latest, url, filename):
- with open(os.path.join(rss_tracked_dir, rss.title, "latest"), "w") as file:
- file.write(latest)
-
updated = str(time.time())
with open(os.path.join(rss_tracked_dir, rss.title, "updated"), "w") as file:
file.write(updated)
@@ -130,9 +120,6 @@ def rss_update_latest(rss_tracked_dir, rss, latest, url, filename):
json.dump(rss.json_data, file, indent=4)
def html_update_latest(html_tracked_dir, html, latest, url):
- with open(os.path.join(html_tracked_dir, html.title, "latest"), "w") as file:
- file.write(latest)
-
updated = str(time.time())
with open(os.path.join(html_tracked_dir, html.title, "updated"), "w") as file:
file.write(updated)
@@ -150,7 +137,6 @@ def get_tracked_html(html_tracked_dir):
if in_progress:
print("Skipping in-progress html %s" % title)
continue
- latest = get_file_content_or_none(os.path.join(html_tracked_dir, title, "latest"))
link = get_file_content_or_none(os.path.join(html_tracked_dir, title, "link"))
if not link:
print("html corrupt, link missing for html %s" % title)
@@ -167,12 +153,10 @@ def get_tracked_html(html_tracked_dir):
"updated": updated,
"downloaded": []
}
- if latest:
- json_data["downloaded"].append({ "title": latest, "time": updated })
if not plugin or not json_data:
print("html corrupt, plugin or data missing for html %s" % title)
continue
- tracked_html.append(TrackedHtml(title, latest, link, plugin, json_data))
+ tracked_html.append(TrackedHtml(title, link, plugin, json_data))
return tracked_html
except FileNotFoundError:
return []
@@ -299,10 +283,6 @@ def add_rss(name, url, rss_config_dir, start_after):
with open(os.path.join(rss_dir, "link"), "w") as file:
file.write(url)
-
- if start_after:
- with open(os.path.join(rss_dir, "latest"), "w") as file:
- file.write(start_after)
updated = str(time.time())
with open(os.path.join(rss_dir, "updated"), "w") as file:
@@ -376,10 +356,6 @@ def add_html(name, url, html_config_dir, start_after):
with open(os.path.join(html_dir, "plugin"), "w") as file:
file.write(os.path.basename(plugin_path))
-
- if start_after:
- with open(os.path.join(html_dir, "latest"), "w") as file:
- file.write(start_after)
updated = str(time.time())
with open(os.path.join(html_dir, "updated"), "w") as file:
@@ -436,15 +412,17 @@ def sync_rss(tracked_rss, tc):
# If it fails, there will be an attempt to add them again after next sync cycle.
latest = None
for item in reversed(items):
+ title = item["title"].replace("/", "_").strip()
+ link = item["link"]
+
torrent = add_torrent(link, tc)
if not torrent:
+ show_notification("RSS Sync failed", "Failed to add torrent: {}".format(link), urgency="critical")
return latest
- title = item["title"].replace("/", "_").strip()
- link = item["link"]
rss_update_latest(rss_tracked_dir, tracked_rss, title, link, torrent.name)
-
latest = title
+
if not only_show_finished_notification:
show_notification("Download started", latest)
return latest