Add run and thumbnails commands
This commit is contained in:
		
							parent
							
								
									257ec9301b
								
							
						
					
					
						commit
						ccbca5c79d
					
				| 
						 | 
					@ -8,7 +8,7 @@ from jinja2 import Environment, PackageLoader, select_autoescape
 | 
				
			||||||
from jinja2.utils import Markup
 | 
					from jinja2.utils import Markup
 | 
				
			||||||
import srt
 | 
					import srt
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from negromate.songs import load_songs
 | 
					from negromate.songs.loader import load_songs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
from .karaoke_templates import update_karaoke_songs
 | 
					from .karaoke_templates import update_karaoke_songs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +0,0 @@
 | 
				
			||||||
from pathlib import Path
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
from .builder import Builder
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
def build():
 | 
					 | 
				
			||||||
    builder = Builder(
 | 
					 | 
				
			||||||
        Path(sys.argv[1]),
 | 
					 | 
				
			||||||
        Path(sys.argv[2]),
 | 
					 | 
				
			||||||
    )
 | 
					 | 
				
			||||||
    builder.build()
 | 
					 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,38 @@
 | 
				
			||||||
 | 
					import argparse
 | 
				
			||||||
 | 
					import sys
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					from . import run, build, thumbnail
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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,
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    parser = argparse.ArgumentParser()
 | 
				
			||||||
 | 
					    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()
 | 
				
			||||||
 | 
					    for command in commands:
 | 
				
			||||||
 | 
					        if args.command == command.name:
 | 
				
			||||||
 | 
					            command.run(args)
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,21 @@
 | 
				
			||||||
 | 
					from pathlib import Path
 | 
				
			||||||
 | 
					from ..builder import Builder
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					name = 'build'
 | 
				
			||||||
 | 
					help_text = 'Generate static website'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def options(parser):
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        'song_folder', help="Folder with the song database.")
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        'lyrics_file', help="File with the lyrics of the songs.")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def run(args):
 | 
				
			||||||
 | 
					    builder = Builder(
 | 
				
			||||||
 | 
					        Path(args.song_folder),
 | 
				
			||||||
 | 
					        Path(args.lyrics_file),
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					    builder.build()
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,26 @@
 | 
				
			||||||
 | 
					from http.server import test, SimpleHTTPRequestHandler
 | 
				
			||||||
 | 
					from functools import partial
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					name = 'run'
 | 
				
			||||||
 | 
					help_text = 'Start web server to test the website'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def options(parser):
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        'song_folder', help="Folder with the song database.")
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        'port', action='store', default=8000, type=int, nargs='?',
 | 
				
			||||||
 | 
					        help='Specify alternate port [default: 8000]')
 | 
				
			||||||
 | 
					    parser.add_argument(
 | 
				
			||||||
 | 
					        '--bind', '-b', default='', metavar='ADDRESS',
 | 
				
			||||||
 | 
					        help='Specify alternate bind address [default: all interfaces]')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def run(args):
 | 
				
			||||||
 | 
					    Handler = partial(
 | 
				
			||||||
 | 
					        SimpleHTTPRequestHandler,
 | 
				
			||||||
 | 
					        directory=args.song_folder,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    test(HandlerClass=Handler, port=args.port, bind=args.bind)
 | 
				
			||||||
| 
						 | 
					@ -0,0 +1,23 @@
 | 
				
			||||||
 | 
					import subprocess
 | 
				
			||||||
 | 
					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)
 | 
				
			||||||
		Loading…
	
		Reference in New Issue