260 print("-" * 80, file=l) |
260 print("-" * 80, file=l) |
261 |
261 |
262 import urllib.request |
262 import urllib.request |
263 urlfile = open('http-download.sh','w') |
263 urlfile = open('http-download.sh','w') |
264 opener = urllib.request.build_opener() |
264 opener = urllib.request.build_opener() |
|
265 cache = set(os.listdir(cachedir)) |
265 for dl in (dl for dl in downloads): |
266 for dl in (dl for dl in downloads): |
266 if dl.torrent: |
267 if dl.torrent: |
267 try: |
268 try: |
268 fn = os.path.basename(urllib.parse.urlsplit(dl.torrent).path) |
269 fn = os.path.basename(urllib.parse.urlsplit(dl.torrent).path) |
269 if os.path.exists(fn): |
270 if os.path.exists(fn): |
270 logging.info("Skipping existing torrent %s", fn) |
271 logging.info("Skipping existing torrent %s", fn) |
|
272 elif fn in cache: |
|
273 logging.info("Copying %s as %s from cache", dl.torrent, fn) |
|
274 os.link(os.path.join(cachedir, fn), fn) |
271 else: |
275 else: |
272 logging.info("Saving %s as %s", dl.torrent, fn) |
276 logging.info("Saving %s as %s", dl.torrent, fn) |
273 with opener.open(dl.torrent) as u: |
277 with opener.open(dl.torrent) as u: |
274 with open(fn,"wb") as f: |
278 with open(fn,"wb") as f: |
275 f.write(u.read()) |
279 f.write(u.read()) |