Skip to content

Instantly share code, notes, and snippets.

View Pullusb's full-sized avatar
🐍
pythoning

Samuel Bernou Pullusb

🐍
pythoning
View GitHub Profile
## ****
# Merge cbz archives v1.3
# Group 'cbz' archive content into bigger cbz archive chunks (made to group chapters on e-reader)
# put in the same location of cbz and run
# below set: archive name, chucks size, folder containing cbz to groups (default same as script)
## ****
import re
import zipfile
from pathlib import Path
@Pullusb
Pullusb / color_auto_name.py
Created March 7, 2021 19:00
Get closest color name from rgb
#-# Find Approx closest color name from rgb/hex value - Standalone
#-# Just import/use get_color_name (check after line 1000)
def srgb_to_linearrgb(c):
if c < 0: return 0
elif c < 0.04045: return c/12.92
else: return ((c+0.055)/1.055)**2.4
def hex_to_rgb(h):
'''Convert a hexadecimal color value to a 3-tuple of integers
@Pullusb
Pullusb / animate_active_collection_objects_visibility.py
Last active September 7, 2021 14:08
Blender - Animate visibility of all active collection's objects
import bpy
def animate_visibility(ob, switch=-1):
'''
add 2 keys to keyframe visibility:
switch options:
nohting or -1 = auto (set the inverse of actual state)
0 = visible before
1 = visible after
'''
@Pullusb
Pullusb / generate_txt_image.py
Created February 25, 2019 12:58
generate text as images from list txt with python and image magick
import os, random
def quote(text):
return ('"' + text + '"')
texSize = 1024
fontloc = "FONTS/"
out = "out/"
typosize = "80"
doc = "Source_text_lines.txt"
@Pullusb
Pullusb / outputPathFromCamName.py
Created August 24, 2016 21:16
Blender script - set the filename after active camera name (keeping head path)
import bpy
from os.path import join, split
C = bpy.context
C.scene.render.filepath = join(split(C.scene.render.filepath)[0] + C.scene.camera.name)
@Pullusb
Pullusb / create_square_vector_from_another
Last active August 19, 2016 10:43
Blender python exemple how to create a 90 degree vector from a current vector
import bpy
from bpy import context as C
from bpy import data as D
from mathutils import Vector
from math import sqrt
def VectorLength(size, A, B):
'''
Calculate the vector lenght
return the coefficient to multiply this vector
@Pullusb
Pullusb / VSE_export_audio_by_selected_strips.py
Created August 12, 2016 15:00
blender script - export sound for each selected strip in VSE
import bpy
import os
C = bpy.context
scn = C.scene
dest_folder = os.path.dirname(scn.render.filepath)
if not os.path.exists(dest_folder):
print ("ERROR, destination folder must exist:\n", dest_folder, "not found")
else:
count = 0
@Pullusb
Pullusb / fix_images_datapath.py
Created July 19, 2016 12:46
blender script to replace images datapath to current blender folder and subfolder
import bpy
import os
corrected = []
print ("--------")
loc = bpy.path.abspath('//')
for i in bpy.data.images:
for root, folders, files in os.walk(loc):
for f in files:
@Pullusb
Pullusb / append_str_to_version_number.py
Last active July 19, 2016 10:15
python function, append name to version number in given path with regex (look for version format like '_V02_' or '.v02' )
def regplace(text, add, c=None):
'''
Get a path and return it with string appended :
Take a path containing a version number as first argument (parsed with the regex compiled passed as optional third arg)
Return it with string (given as second argument) suffixed to version
'''
if not c:
c = re.compile('([\.,_])([v,V]\d{2,3})([\.,_]?)')
head, tail = os.path.split (text)
@Pullusb
Pullusb / harsub_local_videos.py
Created July 18, 2016 20:42
python script to batch harsub video using ffmpeg
import os, time
start_time = time.time()
#good tuning for compromise quality/weight
tuning = '-c:v libx264 -x264opts keyint=60 -pix_fmt yuv420p -preset medium -crf 19 -c:a copy -y'
ext = 'srt'
cwd = os.getcwd()