Last active
July 13, 2020 01:10
-
-
Save lcrs/ea781c216c6c69c209c21c279a8431f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# Pass year and month e.g. python monthly.py 2020 02 | |
# ...will transcode or symlink everything found into /works/monthlies/monthlies202002/rushes/ | |
import subprocess, sys, os | |
def find(folder, pattern, year, month): | |
firstofmonth = '%s-%s-01' % (year, month) | |
firstnextmonth = '%s-%d-01' % (year, int(month)+1) | |
c = ['find', folder, '-iname', pattern, '-type', 'f', '-newermt', firstofmonth, '!', '-newermt', firstnextmonth] | |
o = subprocess.Popen(c, stdout=subprocess.PIPE).communicate()[0].decode('utf8') | |
return o.split('\n') | |
year = sys.argv[1] | |
month = sys.argv[2] | |
m = '/works/monthlies/monthlies%s%s/rushes/' % (year, month) | |
if not os.path.exists(m): | |
os.makedirs(m) | |
pdfs = [] | |
pdfs.extend(find('/works/archive/archive%s%s' % (year, month), '*.pdf', year, month)) | |
pdfs.extend(find('/works/read', '*.pdf', year, month)) | |
pdfs.extend(find('/Users/lewis/Downloads', '*.pdf', year, month)) | |
pdfs.extend(find('/Users/lewis/Desktop', '*.pdf', year, month)) | |
for p in pdfs: | |
if p == '': | |
continue | |
o = subprocess.Popen(('gm', 'identify', p), stdout=subprocess.PIPE).communicate()[0].decode('utf8') | |
pagecount = len(o.split('\n')) | |
for i in range(10): | |
page = i * float(pagecount) / 10 | |
png = '%s/%s-%04d.png' % (m, os.path.basename(p), page) | |
subprocess.call(('gm', 'convert', '-density', '300', '%s[%d]' % (p, page), png)) | |
for ext in ('webp', 'svg'): | |
files = [] | |
files.extend(find('/works/archive/archive%s%s' % (year, month), '*.%s' % (ext), year, month)) | |
files.extend(find('/works/i', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Downloads', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Desktop', '*.%s' % (ext), year, month)) | |
for f in files: | |
if f == '': | |
continue | |
png = '%s/%s.png' % (m, os.path.basename(f)) | |
subprocess.call(('gm', 'convert', '-density', '300', f, png)) | |
for ext in ('gif', 'webm', 'mkv'): | |
files = [] | |
files.extend(find('/works/archive/archive%s%s' % (year, month), '*.%s' % (ext), year, month)) | |
files.extend(find('/works/i', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Downloads', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Desktop', '*.%s' % (ext), year, month)) | |
for f in files: | |
if f == '': | |
continue | |
mov = '%s/%s.mov' % (m, os.path.basename(f)) | |
subprocess.call(('ffmpeg', '-i', f, '-vf', 'scale=1280:-1', '-pix_fmt', 'yuv422p10', '-c:v', 'prores', mov)) | |
for ext in ('png', 'jpg', 'tif', 'exr', 'mov', 'mp4'): | |
files = [] | |
files.extend(find('/works/archive/archive%s%s' % (year, month), '*.%s' % (ext), year, month)) | |
files.extend(find('/works/i', '*.%s' % (ext), year, month)) | |
files.extend(find('/works/watch', '*.%s' % (ext), year, month)) | |
files.extend(find('/works/accidents', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Downloads', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Desktop', '*.%s' % (ext), year, month)) | |
files.extend(find('/Users/lewis/Pictures', '*.%s' % (ext), year, month)) | |
for f in files: | |
if f == '': | |
continue | |
link = '%s/%s' % (m, os.path.basename(f)) | |
while os.path.exists(link): | |
link = link.replace(".", "_.") | |
os.symlink(f, link) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment