Compare commits
No commits in common. "f06aef8c75fbbf1c6bb386c1eb8fc6f7bdcf38ba" and "376f8be080d84723004c14c1923ca534063267aa" have entirely different histories.
f06aef8c75
...
376f8be080
|
@ -0,0 +1,43 @@
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from . import run, build, thumbnail, rsync
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""
|
||||||
|
Build parser for all the commands and launch appropiate command.
|
||||||
|
|
||||||
|
Each command must be a module with at least the following members:
|
||||||
|
|
||||||
|
* name: String with the command name. Will be used for
|
||||||
|
argparse subcommand.
|
||||||
|
* help_text: String with the help text.
|
||||||
|
* options: Function to build the parser of the command. Takes
|
||||||
|
one parametter, the argparser parser instance for this
|
||||||
|
subcommand.
|
||||||
|
* run: Function that runs the actual command. Takes one
|
||||||
|
parametter, the Namespace with the arguments.
|
||||||
|
"""
|
||||||
|
commands = [
|
||||||
|
build,
|
||||||
|
run,
|
||||||
|
thumbnail,
|
||||||
|
rsync,
|
||||||
|
]
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.set_defaults(command=None)
|
||||||
|
subparsers = parser.add_subparsers()
|
||||||
|
for command in commands:
|
||||||
|
command_parser = subparsers.add_parser(command.name, help=command.help_text)
|
||||||
|
command_parser.set_defaults(command=command.name)
|
||||||
|
command.options(command_parser)
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
if args.command is None:
|
||||||
|
parser.print_usage()
|
||||||
|
else:
|
||||||
|
for command in commands:
|
||||||
|
if args.command == command.name:
|
||||||
|
command.run(args)
|
|
@ -1,67 +0,0 @@
|
||||||
from pathlib import Path
|
|
||||||
import subprocess
|
|
||||||
import urllib.request
|
|
||||||
|
|
||||||
|
|
||||||
name = 'ipfs'
|
|
||||||
help_text = 'Upload the web to IPFS'
|
|
||||||
|
|
||||||
|
|
||||||
def options(parser):
|
|
||||||
parser.add_argument(
|
|
||||||
'song_folder', type=Path,
|
|
||||||
help="Folder with the song database.")
|
|
||||||
parser.add_argument(
|
|
||||||
'-a', '--api', default='http://localhost:5001',
|
|
||||||
help="IPFS API server, defaults to http://localhost:5001.")
|
|
||||||
parser.add_argument(
|
|
||||||
'-p', '--pinfile', default='~/.negromate/ipfs.hash', type=Path,
|
|
||||||
help="file to store the current ipfs hash, defaults to ~/.negromate/ipfs.")
|
|
||||||
|
|
||||||
|
|
||||||
def run(args):
|
|
||||||
# add to local
|
|
||||||
command = [
|
|
||||||
"ipfs",
|
|
||||||
"add",
|
|
||||||
"--recursive",
|
|
||||||
"--quieter",
|
|
||||||
args.song_folder,
|
|
||||||
]
|
|
||||||
final_hash = subprocess.check_output(command).decode('utf-8').strip()
|
|
||||||
|
|
||||||
# pin in server
|
|
||||||
url = "{}/api/v0/pin/add?arg={}&progress=false".format(
|
|
||||||
args.api,
|
|
||||||
final_hash,
|
|
||||||
)
|
|
||||||
urllib.request.urlopen(url)
|
|
||||||
|
|
||||||
# read previous hash and update value
|
|
||||||
pinfile = args.pinfile.expanduser()
|
|
||||||
if pinfile.exists():
|
|
||||||
with pinfile.open() as f:
|
|
||||||
previous_hash = f.read()
|
|
||||||
else:
|
|
||||||
if not pinfile.parent.exists():
|
|
||||||
pinfile.parent.mkdir()
|
|
||||||
previous_hash = None
|
|
||||||
with pinfile.open('w') as f:
|
|
||||||
f.write(final_hash)
|
|
||||||
|
|
||||||
if previous_hash is not None:
|
|
||||||
# remove previous pin on local
|
|
||||||
command = [
|
|
||||||
'ipfs',
|
|
||||||
'pin',
|
|
||||||
'rm',
|
|
||||||
previous_hash,
|
|
||||||
]
|
|
||||||
subprocess.check_call(command)
|
|
||||||
|
|
||||||
# remove previous pin on server
|
|
||||||
url = "{}/api/v0/pin/rm?arg={}".format(
|
|
||||||
args.api,
|
|
||||||
previous_hash,
|
|
||||||
)
|
|
||||||
urllib.request.urlopen(url)
|
|
|
@ -0,0 +1,22 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from negromate.songs.utils import generate_cover, generate_thumbnail
|
||||||
|
|
||||||
|
name = 'thumbnail'
|
||||||
|
help_text = 'Generate cover and thumbnail for a video.'
|
||||||
|
|
||||||
|
|
||||||
|
def options(parser):
|
||||||
|
parser.add_argument(
|
||||||
|
'video', help="Video of the song.", type=Path)
|
||||||
|
parser.add_argument(
|
||||||
|
'second', type=int,
|
||||||
|
help='Take snapshot at this second.')
|
||||||
|
|
||||||
|
|
||||||
|
def run(args):
|
||||||
|
video = args.video
|
||||||
|
cover = video.parent / 'cover.jpg'
|
||||||
|
thumbnail = video.parent / 'thumb.jpg'
|
||||||
|
generate_cover(video, cover, args.second)
|
||||||
|
generate_thumbnail(cover, thumbnail)
|
|
@ -23,14 +23,11 @@ python_requires = >= 3.4
|
||||||
install_requires =
|
install_requires =
|
||||||
Jinja2
|
Jinja2
|
||||||
ass ==0.4.4
|
ass ==0.4.4
|
||||||
negromate.songs ==1.1
|
negromate.songs ==1.0
|
||||||
|
|
||||||
[options.entry_points]
|
[options.entry_points]
|
||||||
negromate.commands =
|
console_scripts =
|
||||||
build = negromate.web.commands.build
|
negromate-web = negromate.web.commands:main
|
||||||
run = negromate.web.commands.run
|
|
||||||
rsync = negromate.web.commands.rsync
|
|
||||||
ipfs = negromate.web.commands.ipfs
|
|
||||||
|
|
||||||
[bdist_wheel]
|
[bdist_wheel]
|
||||||
# This flag says to generate wheels that support both Python 2 and Python
|
# This flag says to generate wheels that support both Python 2 and Python
|
||||||
|
|
Loading…
Reference in New Issue