]>
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
.seen_list
= set()
12 self
.f
= open(filename
, "r")
14 self
.seen_list
.add(line
.strip())
17 print >>sys
.stderr
, "Could not open:", filename
, e
18 self
.f
= open(filename
, "a")
20 def has_seen(self
, node
):
21 return node
.title
in self
.seen_list
23 def mark_seen(self
, node
):
24 self
.seen_list
.add(node
.title
)
25 self
.f
.write(node
.title
+ "\n")
29 def match(download_list
, node
, pattern
, count
=0):
31 if not download_list
.has_seen(node
):
33 download_list
.mark_seen(node
)
35 print >>sys
.stderr
, "Failed to download!", node
.title
38 if count
>= len(pattern
):
39 print "No match found for pattern:", "/".join(pattern
)
42 for child
in node
.get_children():
43 if fnmatch
.fnmatch(child
.title
, p
):
44 match(download_list
, child
, pattern
, count
+1)
48 node
= load_root_node()
49 download_list
= DownloadList("downloaded_auto.txt")
51 for search
in sys
.argv
[1:]:
52 search
= search
.split("/")
53 match(download_list
, node
, search
)
55 if __name__
== "__main__":
58 except (KeyboardInterrupt, EOFError):