]>
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
, "r")
11 self
.seen_list
= set()
13 self
.seen_list
.add(line
.strip())
15 self
.f
= open(filename
, "a")
17 def has_seen(self
, node
):
18 return node
.title
in self
.seen_list
20 def mark_seen(self
, node
):
21 self
.seen_list
.add(node
.title
)
22 self
.f
.write(node
.title
+ "\n")
26 def match(download_list
, node
, pattern
, count
=0):
28 if not download_list
.has_seen(node
):
29 print "Downloading:", node
.title
31 download_list
.mark_seen(node
)
33 print >>sys
.stderr
, "Failed to download!", node
.title
36 if count
>= len(pattern
):
37 print "No match found for pattern:", "/".join(pattern
)
40 for child
in node
.children
:
41 if fnmatch
.fnmatch(child
.title
, p
):
42 match(download_list
, child
, pattern
, count
+1)
46 node
= load_root_node()
47 download_list
= DownloadList("downloaded_auto.txt")
49 for search
in sys
.argv
[1:]:
50 search
= search
.split("/")
51 match(download_list
, node
, search
)
53 if __name__
== "__main__":
56 except (KeyboardInterrupt, EOFError):