add trackers etc to rss

This commit is contained in:
Plailect 2018-02-24 15:25:58 -05:00
parent 8238c1d005
commit 6d76d3c433
2 changed files with 6724 additions and 13 deletions

33
rss.py
View file

@ -1,5 +1,5 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
"""Python Script for generating a rss.xml for the A9LH Guide Plailect wrote. Requires bencodepy from pypy.""" """Python Script for generating an rss.xml for the Guide. Requires bencodepy from pypy."""
import os import os
import hashlib import hashlib
@ -17,7 +17,7 @@ with open(rss, "w") as xml:
xml.write("\t<channel>\n") xml.write("\t<channel>\n")
xml.write("\t\t<title>Plailect Guide Feed</title>\n") xml.write("\t\t<title>Plailect Guide Feed</title>\n")
xml.write("\t\t<lastBuildDate>{0}</lastBuildDate>\n".format(datetime.datetime.utcnow().strftime("%a, %d %b %Y %X +0000"))) xml.write("\t\t<lastBuildDate>{0}</lastBuildDate>\n".format(datetime.datetime.utcnow().strftime("%a, %d %b %Y %X +0000")))
xml.write("\t\t<link>https://github.com/Plailect/Guide/</link>\n") xml.write("\t\t<link>https://github.com/Plailect/Guide_3DS/</link>\n")
for filename in os.listdir(dir): for filename in os.listdir(dir):
if filename.endswith(".torrent"): if filename.endswith(".torrent"):
@ -26,22 +26,20 @@ with open(rss, "w") as xml:
with open(filepath, "rb") as a: with open(filepath, "rb") as a:
raw = a.read() raw = a.read()
tor = bencodepy.decode(raw) tor = bencodepy.decode(raw)
magnet = "" trackers = []
infohash = hashlib.sha1(bencodepy.encode(tor[b"info"])).hexdigest().upper() infohash = hashlib.sha1(bencodepy.encode(tor[b"info"])).hexdigest().upper()
magp = {"xt": "urn:btih:{0}".format(infohash), "dn": tor[b"info"][b"name"], "xl": tor[b"info"][b"length"]} magp = {"xt": "urn:btih:{0}".format(infohash), "dn": tor[b"info"][b"name"], "xl": tor[b"info"][b"length"]}
magstr = urllib.parse.urlencode(magp) magstr = urllib.parse.urlencode(magp)
magnet = "magnet:?{0}".format(magstr)
for anncl in tor[b"announce-list"]: for anncl in tor[b"announce-list"]:
if isinstance(anncl, list): if isinstance(anncl, list):
for annc in anncl: for annc in anncl:
magnet = "{0}{1}".format(magnet, "&tr={0}".format(annc.decode("utf-8"))) trackers.append(annc.decode("utf-8"))
else: else:
magnet = "{0}{1}".format(magnet, "&tr={0}".format(anncl.decode("utf-8"))) trackers.append(anncl.decode("utf-8"))
length = tor[b"info"][b"length"] length = tor[b"info"][b"length"]
name = tor[b"info"][b"name"].decode("utf-8") name = tor[b"info"][b"name"].decode("utf-8")
ts = tor[b"creation date"] ts = tor[b"creation date"]
magnet = urllib.parse.quote(magnet)
pubdate = datetime.datetime.utcfromtimestamp(int(ts)) pubdate = datetime.datetime.utcfromtimestamp(int(ts))
xml.write("\t\t<item>\n") xml.write("\t\t<item>\n")
xml.write("\t\t\t<title>{0}</title>\n".format(name)) xml.write("\t\t\t<title>{0}</title>\n".format(name))
@ -49,11 +47,24 @@ with open(rss, "w") as xml:
xml.write("\t\t\t<guid>{0}</guid>\n".format(infohash)) xml.write("\t\t\t<guid>{0}</guid>\n".format(infohash))
xml.write("\t\t\t<link>magnet:?xt=urn:btih:{0}</link>\n".format(infohash)) xml.write("\t\t\t<link>magnet:?xt=urn:btih:{0}</link>\n".format(infohash))
xml.write("\t\t\t<pubDate>{0}</pubDate>\n".format(pubdate.strftime("%a, %d %b %Y %X +0000"))) xml.write("\t\t\t<pubDate>{0}</pubDate>\n".format(pubdate.strftime("%a, %d %b %Y %X +0000")))
#xml.write("\t\t\t<torrent:contentLength>{0}</torrent:contentLength>\n".format(length)) xml.write("\t\t\t<contentLength>{0}</contentLength>\n".format(length))
#xml.write("\t\t\t<torrent:infoHash>{0}</torrent:infoHash>\n".format(infohash)) xml.write("\t\t\t<infoHash>{0}</infoHash>\n".format(infohash))
#xml.write("\t\t\t<torrent:magnetURI><![CDATA[{0}]]></torrent:magnetURI>\n".format(magnet)) xml.write("\t\t\t<magnetURI>magnet:?xt=urn:btih:{0}</magnetURI>\n".format(infohash))
#xml.write("\t\t\t<torrent:fileName>{0}</torrent:fileName><torrent:fileName>\n".format(name)) #xml.write("\t\t\t<fileName>{0}</fileName><fileName>\n".format(name))
xml.write("\t\t\t<enclosure url=\"magnet:?xt=urn:btih:{0}\" type=\"application/x-bittorent\" />\n".format(infohash)) xml.write("\t\t\t<enclosure url=\"magnet:?xt=urn:btih:{0}\" type=\"application/x-bittorent\" />\n".format(infohash))
if trackers:
xml.write("\t\t\t<trackers>\n")
xml.write("\t\t\t\t<group order=\"random\">\n")
for tracker in trackers:
xml.write("\t\t\t\t\t<tracker>\n")
xml.write("\t\t\t\t\t\t{0}\n".format(tracker))
xml.write("\t\t\t\t\t</tracker>\n")
xml.write("\t\t\t\t</group>\n")
xml.write("\t\t\t</trackers>\n")
xml.write("\t\t</item>\n") xml.write("\t\t</item>\n")
xml.write("\t</channel>\n") xml.write("\t</channel>\n")
xml.write("</rss>") xml.write("</rss>")

6704
rss.xml

File diff suppressed because it is too large Load diff