Compare commits

...

2 Commits
master ... dev

Author SHA1 Message Date
kageru 125d8f56d1
add ffmpeg recording 2018-04-13 21:19:50 +02:00
kageru 50e49edcb4
added method to get user selection rectangle 2018-04-13 20:36:24 +02:00

View File

@ -4,11 +4,12 @@ from string import ascii_letters, digits
from argparse import ArgumentParser from argparse import ArgumentParser
from pysftp import Connection from pysftp import Connection
from subprocess import call, check_output from subprocess import call, check_output
from collections import namedtuple
from random import choices from random import choices
from datetime import date from datetime import date
from PIL import Image from PIL import Image
import pyperclip import pyperclip
import config import config2 as config
import sys import sys
import os import os
import re import re
@ -52,12 +53,17 @@ def upload_local_file(path: str) -> None:
notify_user(url) notify_user(url)
def take_screenshot(edit=False) -> None: def prepare_file(ext: str) -> str:
"Generate a file name according to the config and create folder structure if necessary"
full_path = get_local_full_path() full_path = get_local_full_path()
if not os.path.exists(full_path): if not os.path.exists(full_path):
os.makedirs(full_path) os.makedirs(full_path)
tempname = generate_filename(config.length, 'png') tempname = generate_filename(config.length, ext)
file = os.path.join(get_local_full_path(), tempname) return os.path.join(get_local_full_path(), tempname)
def take_screenshot(edit=False) -> None:
file = prepare_file('png')
call(['maim', '-suk', file]) call(['maim', '-suk', file])
Image.open(file).convert('RGB').save(file) Image.open(file).convert('RGB').save(file)
if edit: if edit:
@ -67,6 +73,26 @@ def take_screenshot(edit=False) -> None:
os.remove(file) os.remove(file)
def get_selection_rectangle() -> namedtuple:
# TODO: let user cancel selection
raw_coords = check_output(['slop', '-f', '%x,%y,%w,%h']).decode()
x, y, w, h = [int(x) for x in raw_coords.split(',')]
Rectangle = namedtuple('Rectangle', ['x', 'y', 'w', 'h'])
return Rectangle(x, y, w, h)
def record_screen() -> None:
# ffmpeg -f x11grab -s "$W"x"$H" -i :0.0+$X,$Y ~/myfile.webm
# TODO: show rectangle during recording
# also TODO: find a way to end the capture
file = prepare_file('webm')
sel = get_selection_rectangle()
call(['ffmpeg', '-f', 'x11grab', '-i', f':0.0+{sel.x},{sel.y}', '-s', f'{sel.w}x{sel.h}', 'file'])
upload_local_file(file)
if not config.keep_local_copies:
os.remove(file)
def get_extension(filename: str) -> str: def get_extension(filename: str) -> str:
""" """
Returns the extension of a file/full path as a string. Returns the extension of a file/full path as a string.