]>
code.delx.au - webdl/blob - autograbber.py
2 # vim:ts=4:sts=4:sw=4:noet
4 from common
import load_root_node
8 class DownloadList(object):
9 def __init__(self
, filename
):
10 self
.f
= open(filename
, "a+")
11 self
.seen_list
= set()
13 self
.seen_list
.add(line
.strip())
15 def has_seen(self
, node
):
16 return node
.title
in self
.seen_list
18 def mark_seen(self
, node
):
19 self
.seen_list
.add(node
.title
)
20 self
.f
.write(node
.title
+ "\n")
23 def match(download_list
, node
, pattern
, count
=0):
25 if not download_list
.has_seen(node
):
26 print "Downloading", node
.title
28 download_list
.mark_seen(node
)
30 print >>sys
.stderr
, "Failed to download!", node
.title
33 if count
>= len(pattern
):
34 print "No match found for pattern:", "/".join(pattern
)
37 for child
in node
.children
:
38 if fnmatch
.fnmatch(child
.title
, p
):
39 match(download_list
, child
, pattern
, count
+1)
43 node
= load_root_node()
44 download_list
= DownloadList("downloaded_auto.txt")
46 for search
in sys
.argv
[1:]:
47 search
= search
.split("/")
48 match(download_list
, node
, search
)
50 if __name__
== "__main__":
53 except (KeyboardInterrupt, EOFError):