Skip to content

Instantly share code, notes, and snippets.

@oldsharp
Last active May 27, 2018 11:40
Show Gist options
  • Save oldsharp/985312f0b92fa356c1f2 to your computer and use it in GitHub Desktop.
Save oldsharp/985312f0b92fa356c1f2 to your computer and use it in GitHub Desktop.
A collection of handy scripts that help me import tracks from CD images
in .WAV(.FLAC, .APE, etc.)/.CUE combination and build my music library.
#!/bin/sh
begin=1
end=7
suffix=flac
for i in $(seq $begin $end); do
if [ $i -lt 10 ]; then
mv 0$i*.$suffix 0$i.$suffix
else
mv $i*.$suffix $i.$suffix
fi
done
Capitalization Rules for Song Titles
1. The first and last words are always capitalized, and all except the
words listed below are capitalized.
2. These are lower-case, unless they are the first word or last word.
- articles: a, an, the
- conjunctions: and, but, or, nor
- prepositions that are less than five letters long: at, by, for,
from, in, into, of, off, on, onto, out, over, to, up, with
- as (only if it is followed by a noun)
3. Prepositions are sometimes capitalized.
- Prepositions are capitalized when they are the first or last word.
- Prepositions that are part of two-word "phrasal verbs" (Come On,
Hold On, ...) are capitalized.
- Prepositions that are over four letters long: across, after, among,
beyond, ...
4. These short words are capitalized.
Some people occasionally forget to capitalize these.
- also, be, if, than, that, thus, when
- as (if it is followed by a verb)
A List of Some "Phrasal Verbs":
These are some phrases in which the preposition needs to be capitalized.
Beat Up
Blow Out
Break Down
Break Into
Break Up
Bring Up
Call Off
Call On
Call Up
Carry On
Come Back
Come Down
Come On
Come Out
Come Over
Do Over
Fill In
Fill Out
Find Out
Get Along
Get Around
Get By
Get Over
Get Through
Get Up
Give Back
Give Up
Go Along
Go Away
Go On
Go Over
Hand In
Hang Up
Hold On
Keep On
Keep Up
Leave Out
Let Down
Look For
Look Into
Look Like
Look Out
Look Over
Look Up
Make Out
Make Up
Pack Up
Pass Out
Pick Out
Pick Up
Put Away
Put Off
Put On
Put Out
Put Up
Roll Over
Run Into
Run Out
Run Over
Show Up
Take After
Take Back
Take Off
Take On
Take Up
Talk Back
Talk Over
Throw Away
Try On
Turn Down
Turn In
Turn Off
Turn On
Use Up
Wait On
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Music library consolidator.
1. Find file not 644 chmod to 644
2. Report file type not .m4a .pdf
3. Report ffprobe artwork if not 640x640 PNG
"""
import os
import os.path
import re
import subprocess
def check_mode(path):
""" """
mode = oct(os.stat(path).st_mode)[4:]
return mode == "644"
def check_type(filename):
""" """
suffix = filename.split('.')[-1]
return suffix == "m4a"
def check_artwork(path, pattern):
""" """
out = subprocess.check_output(["ffprobe", path], stderr=subprocess.STDOUT)
for line in out.splitlines():
if pattern.match(line):
return True
return False
def main():
""" """
ptn = re.compile(r"\s*Stream #0:0: Video: png, .*640x640, .*")
for root, dirs, files in os.walk("/Users/mick/.tmp/rip/foo/jjlin"):
if files:
for filename in files:
path = os.path.join(root, filename)
if not check_mode(path):
print ">>> not 644: " + path
if not check_type(filename):
print ">>> not m4a: " + path
pass
else:
# We got a .m4a file.
if not check_artwork(path, ptn):
print ">>> bad artwork: " + path
if __name__ == "__main__":
main()
#!/usr/local/bin/python
TYPE = "wav"
BEGIN = 1
END = 7
STEP = 1
for i in range(BEGIN, END + 1, STEP):
print ('FILE "{0:0>2}.{1}" WAVE\n TRACK {0:0>2} AUDIO\n '
'INDEX 01 00:00:00').format(i, TYPE)
#!/bin/sh
begin=1
end=7
for i in $(seq $begin $end); do
if [ $i -lt 10 ]; then
flac -d 0$i.flac
ffmpeg -i 0$i.ape 0$i.wav
ffmpeg -i ./0$i-origin.wav -codec:a pcm_s16le -ar 44100 0$i.wav
else
flac -d $i.flac
ffmpeg -i $i.ape $i.wav
ffmpeg -i ./$i-origin.wav -codec:a pcm_s16le -ar 44100 $i.wav
fi
done
>>> from PIL import Image
>>> image = Image.open("~/Pictures/artwork/imagine-copy.jpg")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 2258, in open
fp = builtins.open(filename, "rb")
IOError: [Errno 2] No such file or directory: '~/Pictures/artwork/imagine-copy.jpg'
>>> image = Image.open("/home/ray/Pictures/artwork/imagine-copy.jpg")
>>> image
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=1300x1300 at 0x7F5FF5A42690>
>>> image.format
'JPEG'
>>> image.mode
'RGB'
>>> image.size
(1300, 1300)
>>> image.show()
>>> image.save("/home/ray/Pictures/artwork/imagine-copy.png")
>>> cropped = image.crop((1, 1, 1299, 1299))
>>> cropped.save("/home/ray/Pictures/artwork/imagine-copy-cropped.png")
>>> cropped.resize((640, 640), resample=PIL.Image.ANTIALIAS)
<PIL.Image.Image image mode=RGB size=640x640 at 0x7F5FF5A42E50>
>>> resized = cropped.resize((640, 640), resample=PIL.Image.ANTIALIAS)
>>> resized.save("/home/ray/Pictures/artwork/imagine-copy-cropped-resized.png")
Master:
Album Name:
Artist:
Multiple Release Versions:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment