-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkahvisync.py
More file actions
128 lines (115 loc) · 3.48 KB
/
kahvisync.py
File metadata and controls
128 lines (115 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env python
#-*- coding: utf-8 -*-
"""
kahvisync.py
Simple python script to sync kahvi collective releases to a certain directory.
Supports several options and multi-threaded downloads by default.
by James Wordelman <[email protected]>
"""
import sys
from ftplib import FTP
try:
import thread as _thread
except ImportError:
import dummy_thread as _thread
# defaults
# you may want to alter these so you don't have to specify command line args
_threads = 5 # set to 1 or above; number of simaltanious downloads
_first = 0 # 0 = not set
_last = 0 # 0 = not set
_verbose = 0 # 0 = off, 1 = on
_quiet = 0 # 0 = show errors, 1 = supress errors
_outDir = './'
_format = 'ogg' # ogg or mp3
_temp_dir = '/tmp'
_cache_dir = True
# internal variables
_host = 'ftp://ftp.scene.org/'
_ftpdir = 'pub/music/groups/kahvicollective/'
_files = []
# parse parameters
def main(argv):
try:
opts, args = getopt.getopt(argv,"d:t:f:l:o:F:vqh",["download=", "threads=",
"first=", "last=", "out=","format=","verbose","quiet","help"])
except getopt.GetoptError:
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-d","--download"):
# this is either a single download or the spawn of itself
getRelease(arg)
sys.exit()
elif opt in ("-t","--threads"):
global _threads
_threads = arg
elif opt in ("-f","--first"):
global _first
_first = arg
elif opt in ("-l","--last"):
global _last
_last = arg
# removed rss support because it wouldn't actually help
# ftp listing is more accurate for releases anyway
#elif opt in ("-r","--rss"):
# global _rss
# _rss = arg
elif opt in ("-v","--verbose"):
global _verbose
_verbose = 1
elif opt in ("-q","--quiet"):
global _quiet
_quiet = 1
elif opt in ("-h","--help"):
fullUsage()
sys.exit()
elif opt in ("-o","--out"):
global _outDir
_outDir = arg
elif opt in ("-F","--format"):
if arg in ("mp3","ogg"):
global _format
_formt = arg
else:
usage()
sys.exit(2)
def usage():
print "Usage: %s [-d|--download releaseNumber] [-t|--threads threadCount]
[-f|--first releaseNumber] [-l|--last releaseNumber] [-v|--verbose] [-o|--out
outDir] [-F|--format mp3|ogg]"
def fullUsage():
usage()
print "releaseNumber \t The number of the release as a number (such as 1 or
202\n"
print "threadCount \t The number of simaltanious connections for downloading\n"
print "format is a preference; if only one exists, it will be downloaded"
def getFTPInDir():
global _host, _ftpdir
ftp = FTP(_host)
ftp.login()
ftp.cwd(_ftpdir)
return ftp
def getFileList():
global _cache_dir
data = []
if _cache_dir:
global _files
data = _files
# just return if we have a cache of something and are using it
if len(data) > 0:
return data
ftp = getFTPInDir()
ftp.dir(data.append)
if _cache_dir:
_files = data
return data
def getRelease(releaseNumber):
# we must find the release from the ftp directory and download the file
# for threading support, we are spawning a new ftp connection to get the file
# first figure out what full file name is for the number
# ex file:kahvi277_acrilic_colors-yves_klein_blue_(mp3).zip
for file in getFileList():
pass
global _tmpdir
ftp = getFTPInDir()
# vim: set sw=3 tw=80 :