enable offline extraction, use profile from config if provided
This commit is contained in:
parent
052fc40e1c
commit
ab00769f7d
3 changed files with 20 additions and 12 deletions
|
@ -31,6 +31,10 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
action = args[0]
|
action = args[0]
|
||||||
|
|
||||||
c = pandora_client.Client(opts.config)
|
if action == 'extract':
|
||||||
|
offline = True
|
||||||
|
else:
|
||||||
|
offline = False
|
||||||
|
c = pandora_client.Client(opts.config, offline)
|
||||||
getattr(c, action)()
|
getattr(c, action)()
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
{
|
{
|
||||||
"url": "http://pandora_url/api/",
|
"url": "http://pandora_url/api/",
|
||||||
|
"profile": "480p.webm",
|
||||||
"username": "username", "password": "password",
|
"username": "username", "password": "password",
|
||||||
"cache": "~/.ox/client.sqlite",
|
"cache": "~/.ox/client.sqlite",
|
||||||
"volumes": {
|
"volumes": {
|
||||||
|
|
|
@ -50,15 +50,17 @@ def encode(filename, prefix, profile, info=None):
|
||||||
}
|
}
|
||||||
|
|
||||||
class Client(object):
|
class Client(object):
|
||||||
def __init__(self, config):
|
def __init__(self, config, offline=False):
|
||||||
if isinstance(config, basestring):
|
if isinstance(config, basestring):
|
||||||
with open(config) as f:
|
with open(config) as f:
|
||||||
self._config = json.load(f)
|
self._config = json.load(f)
|
||||||
else:
|
else:
|
||||||
self._config = config
|
self._config = config
|
||||||
self.api = API(self._config['url'], media_cache=self.media_cache())
|
|
||||||
self.api.DEBUG = DEBUG
|
self.profile = self._config.get('profile', '480p.webm')
|
||||||
self.signin()
|
|
||||||
|
if not offline:
|
||||||
|
self.online()
|
||||||
|
|
||||||
conn, c = self._conn()
|
conn, c = self._conn()
|
||||||
|
|
||||||
|
@ -93,9 +95,6 @@ class Client(object):
|
||||||
conn.text_factory = sqlite3.OptimizedUnicode
|
conn.text_factory = sqlite3.OptimizedUnicode
|
||||||
return conn, conn.cursor()
|
return conn, conn.cursor()
|
||||||
|
|
||||||
def get_profile(self):
|
|
||||||
return "%sp.webm" % max(self.api._config['video']['resolutions'])
|
|
||||||
|
|
||||||
def media_cache(self):
|
def media_cache(self):
|
||||||
return os.path.expanduser(self._config.get('media-cache', default_media_cache))
|
return os.path.expanduser(self._config.get('media-cache', default_media_cache))
|
||||||
|
|
||||||
|
@ -126,6 +125,12 @@ class Client(object):
|
||||||
paths.append(row[0])
|
paths.append(row[0])
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
|
def online(self):
|
||||||
|
self.api = API(self._config['url'], media_cache=self.media_cache())
|
||||||
|
self.api.DEBUG = DEBUG
|
||||||
|
self.signin()
|
||||||
|
self.profile = "%sp.webm" % max(self.api._config['video']['resolutions'])
|
||||||
|
|
||||||
def signin(self):
|
def signin(self):
|
||||||
if 'username' in self._config:
|
if 'username' in self._config:
|
||||||
r = self.api.signin(username=self._config['username'], password=self._config['password'])
|
r = self.api.signin(username=self._config['username'], password=self._config['password'])
|
||||||
|
@ -213,7 +218,6 @@ class Client(object):
|
||||||
else:
|
else:
|
||||||
volumes[name]['available'] = False
|
volumes[name]['available'] = False
|
||||||
|
|
||||||
profile = self.get_profile()
|
|
||||||
for name in volumes:
|
for name in volumes:
|
||||||
if volumes[name]['available']:
|
if volumes[name]['available']:
|
||||||
prefix = volumes[name]['path']
|
prefix = volumes[name]['path']
|
||||||
|
@ -226,7 +230,7 @@ class Client(object):
|
||||||
'/extras' not in filename.lower() and \
|
'/extras' not in filename.lower() and \
|
||||||
'/versions' not in filename.lower():
|
'/versions' not in filename.lower():
|
||||||
print filename.encode('utf-8')
|
print filename.encode('utf-8')
|
||||||
i = encode(filename, self.media_cache(), profile, info)
|
i = encode(filename, self.media_cache(), self.profile, info)
|
||||||
|
|
||||||
def sync(self):
|
def sync(self):
|
||||||
if not self.user:
|
if not self.user:
|
||||||
|
@ -318,7 +322,6 @@ class Client(object):
|
||||||
else:
|
else:
|
||||||
volumes[name]['available'] = False
|
volumes[name]['available'] = False
|
||||||
|
|
||||||
profile = self.get_profile()
|
|
||||||
for name in volumes:
|
for name in volumes:
|
||||||
if volumes[name]['available']:
|
if volumes[name]['available']:
|
||||||
prefix = volumes[name]['path']
|
prefix = volumes[name]['path']
|
||||||
|
@ -346,7 +349,7 @@ class Client(object):
|
||||||
filename = filenames[oshash]
|
filename = filenames[oshash]
|
||||||
info = files['info'][oshash]
|
info = files['info'][oshash]
|
||||||
if not self.api.uploadVideo(os.path.join(prefix, filename),
|
if not self.api.uploadVideo(os.path.join(prefix, filename),
|
||||||
data, profile, info):
|
data, self.profile, info):
|
||||||
if not self.signin():
|
if not self.signin():
|
||||||
print "failed to login again"
|
print "failed to login again"
|
||||||
return
|
return
|
||||||
|
|
Loading…
Reference in a new issue