make media-cache config option

This commit is contained in:
j 2010-11-27 12:35:56 +01:00
parent 149d6bf47b
commit ce7c309e81
2 changed files with 16 additions and 8 deletions

1
README
View File

@ -11,6 +11,7 @@ pandora client example:
"username": "username",
"password": "password",
"cache": "~/.ox/client.sqlite",
"media-cache": "~/.ox/media",
"volumes": {
"volumename": "/media/2010/Movies"
}

View File

@ -20,9 +20,9 @@ import utils
__version__ = '0.1'
DEBUG = True
prefix = os.environ.get('oxMEDIA', os.path.expanduser('~/.ox/media'))
default_media_cache = os.environ.get('oxMEDIA', os.path.expanduser('~/.ox/media'))
def encode(filename, profile):
def encode(filename, prefix, profile):
info = utils.avinfo(filename)
oshash = info['oshash']
frames = []
@ -49,10 +49,10 @@ class Client(object):
def __init__(self, config):
if isinstance(config, basestring):
with open(config) as f:
self._config = json.loads(f.read())
self._config = json.load(f)
else:
self.config = config
self.api = API(self._config['url'])
self.api = API(self._config['url'], media_cache=self.media_cache())
if 'username' in self._config:
r = self.api.login({'username':self._config['username'], 'password':self._config['password']})
@ -92,6 +92,9 @@ class Client(object):
conn.text_factory = sqlite3.OptimizedUnicode
return conn, conn.cursor()
def media_cache(self):
return os.path.expanduser(self._config.get('media-cache', default_media_cache))
def get(self, key, default=None):
conn, c = self._conn()
c.execute('SELECT value FROM setting WHERE key = ?', (key, ))
@ -231,11 +234,11 @@ class Client(object):
def clean(self):
print "remove temp videos and stills"
if os.path.exists(prefix):
shutil.rmtree(prefix)
if os.path.exists(self.prefix()):
shutil.rmtree(self.prefix())
class API(object):
def __init__(self, url, cj=None):
def __init__(self, url, cj=None, media_cache=None):
if cj:
self._cj = cj
else:
@ -243,6 +246,10 @@ class API(object):
self._opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(self._cj))
urllib2.install_opener(self._opener)
self.media_cache = media_cache
if not self.media_cache:
self.media_cache = default_media_cache
self.url = url
r = self._request('api', {})
self._actions = r['data']['actions']
@ -297,7 +304,7 @@ class API(object):
return self._json_request(self.url, form)
def uploadVideo(self, filename, data, profile):
i = encode(filename, profile)
i = encode(filename, self.media_cache, profile)
#upload frames
form = ox.MultiPartForm()