TMU (Too Many Updates)

This commit is contained in:
Geoffrey Frogeye 2019-10-17 12:44:30 +02:00
parent 392dfed89a
commit 789f26d925
12 changed files with 147 additions and 76 deletions

25
config/scripts/diapo Executable file
View file

@ -0,0 +1,25 @@
#!/usr/bin/env bash
# Don't forget:
# --duration 15m # Specify expected duration of presentation
# --half-screen --geometry 2048x768+0+1 # If presenting with beamer notes on the right, and you have two screens with 1024x768 resolution
/home/geoffrey/Documents/Programmation/Impressive/OutOfTree/impressive.py \
--transition WipeRight \
--bind lmb:=box-zoom --bind lmb=zoom-exit \
--bind rmb:=box-add --bind rmb=box-clear \
--bind ctrl+p:=overview-enter --bind ctrl+a:=overview-confirm \
--bind escape:=time-reset \
--bind e:=goto-last \
--bind b-=fade-to-black \
--bind escape-=quit \
--cursor default \
--fontsize 26 \
--transtime 200 \
--mousedelay 1000 \
--page-progress \
--time-display \
--tracking \
--zoomdarkness 75 \
"$@"

View file

@ -1,11 +1,19 @@
#!/usr/bin/env python3
# pylint: disable=C0103
"""
Find the subjectively best software
to open the file given in arguments with.
Doesn't use that XDG mess (only in last resort).
"""
import os
import sys
import magic
import subprocess
import urllib.request
import sys
import tempfile
import urllib.request
import magic
# Getting what's needed
path = sys.argv[1]
@ -25,7 +33,7 @@ else:
mime = tuple(mime.split('/'))
assert len(mime) == 2
graphical = not not os.environ.get('DISPLAY')
graphical = os.environ.get('DISPLAY')
# Some energumens
if mime[0] == "application" and mime[1] in ("json", "javascript"):
@ -34,7 +42,7 @@ if mime[0] == "application" and mime[1] in ("json", "javascript"):
# Determine stuff
ex = None # Executable needed to open the file
forcelocal = False # If we need to copy the file locally before opening it
isterm = False # Executable should run in a terminal
isterm = False # Executable should run in a terminal
if mime[0] == "text":
if not ishttp:
@ -46,13 +54,14 @@ elif mime[0] in ("audio", "video"):
ex = "mpv"
isterm = True
elif mime == ("application", "pdf"):
ex = "llpp.inotify"
ex = "zathura"
forcelocal = True
# Open stuff
tmp = None
if ex:
if forcelocal and ishttp:
assert buf
tmp = tempfile.NamedTemporaryFile(prefix='o')
tmp.write(chunk)
tmp.write(buf.read())
@ -66,6 +75,7 @@ if buf:
# TODO Launch a new terminal window for some
assert ex
p = subprocess.run([ex, path])
if tmp:
tmp.close()

View file

@ -129,7 +129,7 @@ do
replace "$prog" "$image"
done <<< "$(find "$dir" -type f -iregex ".+.jpe?g$")"
done <<< "$(find "$dir/" -type f -iregex ".+.jpe?g$")"
# PNG (requires optipng)
while read image
@ -144,7 +144,7 @@ do
replace "$temp" "$image"
done <<< "$(find "$dir" -type f -iname "*.png")"
done <<< "$(find "$dir/" -type f -iname "*.png")"
# # SVG (requires scour)
# while read image
@ -158,7 +158,7 @@ done <<< "$(find "$dir" -type f -iname "*.png")"
#
# replaceImg "$temp" "$image"
#
# done <<< "$(find "$dir" -type f -iname "*.svg")"
# done <<< "$(find "$dir/" -type f -iname "*.svg")"
# NOTE Explicitely disabled since:
# - I only have ~50 MiB of SVG in TOTAL

View file

@ -3,11 +3,13 @@
# Normalisation is done at the default of each program,
# which is usually -89.0 dB
import os
import coloredlogs
import logging
import r128gain
import os
import sys
import typing
import coloredlogs
import r128gain
coloredlogs.install(level='DEBUG', fmt='%(levelname)s %(message)s')
log = logging.getLogger()
@ -18,51 +20,49 @@ log = logging.getLogger()
FORCE = '-f' in sys.argv
if FORCE:
sys.argv.remove('-f')
SOURCE_FOLDER = os.path.realpath(sys.argv[1]) if len(sys.argv) >= 2 else os.path.join(os.path.expanduser("~"), "Musiques")
if len(sys.argv) >= 2:
SOURCE_FOLDER = os.path.realpath(sys.argv[1])
else:
SOURCE_FOLDER = os.path.join(os.path.expanduser("~"), "Musiques")
def isMusic(f):
def isMusic(f: str) -> bool:
ext = os.path.splitext(f)[1][1:].lower()
return ext in r128gain.AUDIO_EXTENSIONS
# Get album paths
log.info("Listing albums and tracks")
albums = set()
singleFiles = set()
albums = list()
singleFiles = list()
for root, dirs, files in os.walk(SOURCE_FOLDER):
folder_has_music = False
for f in files:
if isMusic(f):
folder_has_music = True
fullPath = os.path.join(root, f)
singleFiles.append(fullPath)
relRoot = os.path.relpath(root, SOURCE_FOLDER)
if folder_has_music:
albums.append(root)
head, tail = os.path.split(relRoot)
# 1 component in the path: save files path as single
if not len(head):
for f in files:
if isMusic(f):
fullPath = os.path.join(root, f)
singleFiles.add(fullPath)
head, tail = os.path.split(head)
if len(head):
continue
# 2 components in the path: save album path
albums.add(root)
# log.info("Processing single files")
# r128gain.process(singleFiles, album_gain=False,
# skip_tagged=not FORCE, report=True)
log.info("Processing single files")
# r128gain.process(list(singleFiles), album_gain=False, skip_tagged=not FORCE, report=True)
for album in albums:
albumName = os.path.relpath(album, SOURCE_FOLDER)
log.info("Processing album {}".format(albumName))
musicFiles = set()
for root, dirs, files in os.walk(album):
for f in files:
if isMusic(f):
fullPath = os.path.join(root, f)
musicFiles.add(fullPath)
musicFiles = list()
for f in os.listdir(album):
if isMusic(f):
fullPath = os.path.join(album, f)
musicFiles.append(fullPath)
# print(musicFiles)
if not len(musicFiles):
if not musicFiles:
continue
r128gain.process(list(musicFiles), album_gain=True, skip_tagged=not FORCE, report=True)
r128gain.process(musicFiles, album_gain=True,
skip_tagged=not FORCE, report=True)
print("==============================")

View file

@ -1,8 +1,11 @@
#!/usr/bin/env python3
# pylint: disable=C0103
import logging
import os
import subprocess
import typing
import re
import coloredlogs
import progressbar
@ -18,6 +21,9 @@ FORBIDDEN_EXTENSIONS = ["jpg", "png", "pdf", "ffs_db"]
FORGIVEN_FILENAMES = ["cover.jpg", "front.jpg", "folder.jpg",
"cover.png", "front.png", "folder.png"]
IGNORED_EMPTY_FOLDER = [".stfolder"]
RESTRICT_CHARACTERS = '[\0\\/:*"<>|]' # FAT32, NTFS
# RESTRICT_CHARACTERS = '[:/]' # HFS, HFS+
# RESTRICT_CHARACTERS = '[\0/]' # ext2-4, linux-based?
# TODO FEAT Make the directory structure the same as the base one and
# remove IGNORED_EMPTY_FOLDER variable
@ -43,16 +49,20 @@ remainingConversions = dict()
extraFiles = set(outputFiles.keys())
def convertPath(path):
def convertPath(path: str) -> typing.Optional[str]:
filename, extension = os.path.splitext(path)
extension = extension[1:].lower()
# Remove unwanted characters from filename
filename_parts = os.path.normpath(filename).split(os.path.sep)
filename_parts = [re.sub(RESTRICT_CHARACTERS, '_', part) for part in filename_parts]
filename = os.path.sep.join(filename_parts)
# If the extension isn't allowed
if extension in FORBIDDEN_EXTENSIONS:
basename = os.path.basename(path)
# And the filename is not an exception
if basename not in FORGIVEN_FILENAMES:
# This file shouldn't be copied nor converted
return False
return None
# If this needs a conversion
elif extension in CONVERSIONS:
extension = CONVERSIONS[extension]
@ -61,11 +71,11 @@ def convertPath(path):
return path
log.info("Determining action over {} files".format(len(sourceFiles)))
log.info("Determining action over %d files", len(sourceFiles))
for sourceFile in sourceFiles:
outputFile = convertPath(sourceFile)
# If the file should not be converted, do nothing
if outputFile == False:
if not outputFile:
continue
# If the file already has something as an output
elif outputFile in outputFiles:
@ -77,7 +87,7 @@ for sourceFile in sourceFiles:
# If the file needs to be converted, do it
remainingConversions[sourceFile] = outputFile
log.debug("{} actions will need to be taken".format(len(remainingConversions)))
log.debug("%d actions will need to be taken", len(remainingConversions))
log.info("Copying files that do not require a conversion")
conversions = set()
for sourceFile in remainingConversions:
@ -91,7 +101,7 @@ for sourceFile in remainingConversions:
# Converting
fullSourceFile = os.path.join(SOURCE_FOLDER, sourceFile)
if sourceFile == outputFile:
log.debug('{} → {}'.format(fullSourceFile, fullOutputFile))
log.debug('%s → %s', fullSourceFile, fullOutputFile)
if os.path.isfile(fullOutputFile):
os.remove(fullOutputFile)
os.link(fullSourceFile, fullOutputFile)
@ -101,12 +111,12 @@ for sourceFile in remainingConversions:
log.info("Removing extra files")
for extraFile in extraFiles:
fullExtraFile = os.path.join(OUTPUT_FOLDER, extraFile)
log.debug('× {}'.format(fullExtraFile))
log.debug('× %s', fullExtraFile)
os.remove(fullExtraFile)
log.info("Listing files that will be converted")
for fullSourceFile, fullOutputFile in conversions:
log.debug('{} ⇒ {}'.format(fullSourceFile, fullOutputFile))
log.debug('%s ⇒ %s', fullSourceFile, fullOutputFile)
log.info("Converting files")
for fullSourceFile, fullOutputFile in progressbar.progressbar(conversions):