pandora-upload
This commit is contained in:
commit
e3adbbbbd0
6 changed files with 179 additions and 0 deletions
23
.editorconfig
Normal file
23
.editorconfig
Normal file
|
@ -0,0 +1,23 @@
|
|||
[*]
|
||||
end_of_line = lf
|
||||
insert_final_newline = true
|
||||
|
||||
[*.py]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.sass]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.scss]
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.html]
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
|
||||
[*.js]
|
||||
indent_style = space
|
||||
indent_size = 4
|
6
.gitignore
vendored
Normal file
6
.gitignore
vendored
Normal file
|
@ -0,0 +1,6 @@
|
|||
dist/
|
||||
pandora_upload.egg-info/
|
||||
*.pyc
|
||||
*.swp
|
||||
*.swo
|
||||
__pycache__
|
20
README.md
Normal file
20
README.md
Normal file
|
@ -0,0 +1,20 @@
|
|||
# pandora-upload
|
||||
|
||||
pandora_upload is a commandline client for pan.do/ra.
|
||||
You can use it to upload one or more files to your pandora instance.
|
||||
No conversion is done on the client side.
|
||||
To upload/sync large repositories use pandora_client
|
||||
|
||||
You can also use pandora-upload as a python script:
|
||||
|
||||
``` python
|
||||
import pandora_client
|
||||
item_id = pandora_client.upload(
|
||||
'http://pandora/api/',
|
||||
['/home/example/Videos/video.mp4',
|
||||
{
|
||||
'title': 'This is an example',
|
||||
'date': '2021-11-15'
|
||||
}
|
||||
)
|
||||
```
|
70
pandora_upload/__init__.py
Executable file
70
pandora_upload/__init__.py
Executable file
|
@ -0,0 +1,70 @@
|
|||
#!/usr/bin/python3
|
||||
|
||||
from argparse import ArgumentParser
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
import ox
|
||||
import ox.api
|
||||
|
||||
|
||||
def upload(api_url, files, metadata):
|
||||
'''
|
||||
create new item with metadata and upload all files to that item
|
||||
returns the item id of the new item
|
||||
|
||||
upload('https://pandora/api/', ['/home/pandora/Videos/example.mp4'], {'title': 'This is an example'})
|
||||
'''
|
||||
api = ox.api.signin(api_url)
|
||||
item_id = None
|
||||
if isinstance(files, str):
|
||||
files = [files]
|
||||
for path in files:
|
||||
oshash = ox.oshash(path)
|
||||
filename = os.path.basename(path)
|
||||
data = {
|
||||
'id': oshash,
|
||||
'filename': filename
|
||||
}
|
||||
if item_id:
|
||||
data['item'] = item_id
|
||||
r = api.addMedia(data)
|
||||
if not item_id:
|
||||
item_id = r['data']['item']
|
||||
|
||||
api.upload_chunks(api.url + 'upload/direct/', path, {'id': oshash})
|
||||
if item_id:
|
||||
data = metadata.copy()
|
||||
data['id'] = item_id
|
||||
api.edit(data)
|
||||
return item_id
|
||||
|
||||
def main():
|
||||
usage = "usage: %(prog)s [options] path"
|
||||
parser = ArgumentParser(usage=usage, prog='pandora-upload')
|
||||
parser.add_argument('-v', '--version', action="version", version="%(prog)s 1.0")
|
||||
parser.add_argument('-p', '--pandora', dest='api_url',
|
||||
help='pandora api url', default='http://127.0.0.1:2620/api/')
|
||||
parser.add_argument('-d', '--debug', dest='debug',
|
||||
help='output debug information', action="store_true")
|
||||
parser.add_argument('-m', '--meta', dest='meta', help='metadata key=value', action='append')
|
||||
parser.add_argument('files', metavar='path', type=str, nargs='*', help='file or files to upload')
|
||||
opts = parser.parse_args()
|
||||
meta = {}
|
||||
if opts.meta:
|
||||
for m in opts.meta:
|
||||
if '=' not in m:
|
||||
parser.print_help()
|
||||
print('\ninvalid metadata argument, format is -m "key=value"')
|
||||
sys.exit(1)
|
||||
k, v = m.split('=', 1)
|
||||
meta[k] = v
|
||||
files = opts.files
|
||||
if not files:
|
||||
parser.print_help()
|
||||
sys.exit(1)
|
||||
|
||||
id = upload(opts.api_url, files, meta)
|
||||
print(id)
|
||||
|
2
pandora_upload/__main__.py
Normal file
2
pandora_upload/__main__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
from . import main
|
||||
main()
|
58
setup.py
Normal file
58
setup.py
Normal file
|
@ -0,0 +1,58 @@
|
|||
#!/usr/bin/env python3
|
||||
from setuptools import setup
|
||||
|
||||
with open("README.md", "r", encoding="utf-8") as fh:
|
||||
long_description = fh.read()
|
||||
|
||||
|
||||
def get_version():
|
||||
import os
|
||||
import re
|
||||
import subprocess
|
||||
dot_git = os.path.join(os.path.dirname(__file__), '.git')
|
||||
changelog = os.path.join(os.path.dirname(__file__), 'debian/changelog')
|
||||
if os.path.exists(dot_git):
|
||||
cmd = ['git', 'rev-list', 'HEAD', '--count']
|
||||
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
stdout, stderr = p.communicate()
|
||||
rev = int(stdout)
|
||||
return u'%s' % rev
|
||||
elif os.path.exists(changelog):
|
||||
f = open(changelog)
|
||||
head = f.read().strip().split('\n')[0]
|
||||
f.close()
|
||||
rev = re.compile('\d+\.\d+\.(\d+)').findall(head)
|
||||
if rev:
|
||||
return "%s" % rev[0]
|
||||
return 'unknown'
|
||||
|
||||
|
||||
setup(
|
||||
name="pandora-upload",
|
||||
version="1.0.%s" % get_version(),
|
||||
description="pandora-upload is a commandline uploader for pan.do/ra",
|
||||
long_description=long_description,
|
||||
long_description_content_type="text/markdown",
|
||||
author="j",
|
||||
author_email="j@mailb.org",
|
||||
url="https://code.0x2620.org/0x2620/pandora-upload",
|
||||
license="GPLv3",
|
||||
packages=['pandora_upload'],
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'pandora-upload=pandora_upload:main'
|
||||
]
|
||||
},
|
||||
install_requires=[
|
||||
'ox >= 2.3.804,<3',
|
||||
'lxml',
|
||||
],
|
||||
keywords=[],
|
||||
classifiers=[
|
||||
'Development Status :: 5 - Production/Stable',
|
||||
'Environment :: Console',
|
||||
'Operating System :: OS Independent',
|
||||
'Programming Language :: Python :: 3',
|
||||
'License :: OSI Approved :: GNU General Public License (GPL)',
|
||||
],
|
||||
)
|
Loading…
Reference in a new issue