Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Special charset support #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Documentation
`cb` - The callback function to invoke when the tags are loaded.
`options` - Optional parameters.
`options.tags` - The array of tags and/or shortcuts to read from the ID3 block. Default value is: `["title", "artist", "album", "track"]`
`options.dataReader` - The function used to create the data reader out of a url. It receives (`url`, `success`: callback function that returns the data reader, `fail`: callback function to inform an error setting up the reader). By default it will be BufferedBinaryAjax.
`options.dataReader` - The function used to create the data reader out of a url. It receives (`url`, `success`: callback function that returns the data reader, `fail`: callback function to inform an error setting up the reader).

`ID3.getAllTags(url)`
`url` - The URL of the mp3 file to read, this must be the same value given to `ID3.loadTags()`.
Expand Down
91 changes: 91 additions & 0 deletions builder/JSBuilder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# python builder by Andrea Giammarchi
# Mit Style License
# Note: this is not "extreme performances oriented" Python code
# it should work on Python 2.6+ tho
import gzip, os, sys, string, re

# I know this sucks but it kinda worked cross .py version ...
def fullPath(file):
i = len(os.path.split(sys.argv[0])[-1:][0])
return os.path.realpath(os.path.join(os.getcwd(), sys.argv[0][:-i], file))

# this could be surely optimized ...
def getSize(file):
i = 0
sufix = ['bytes', 'Kb', 'Mb']
size = os.path.getsize(fullPath(file))
while 1023.0 < size:
size = size / 1024.0
i = i + 1
return str(round(size, 2)) + ' ' + sufix[i]

# this is a handy shortcut ...
def read(file):
f = open(fullPath(file), 'r')
content = f.read()
f.close()
return content

# ... as well as this one
def write(file, content):
f = open(fullPath(file), 'w')
f.write(content)
f.close()

# well ... this simply works as well :-D
def compile(copyright, fullName, minName, files, search=None, replace=None):

# create a copyright compatible with both YUICompressor and Google Closure Compiler
multiCopyright = "\n".join([
'/**'+ copyright+'*/\n'
])

#copy the list temporarely
files = files[:]

# read all files
for i in range(len(files)):
files[i] = read('../' + 'src/' + files[i])

# address the whole content
content = multiCopyright + "\n".join(files)
files = [] # just in case ...

# replace something if necessary
if search != None:
for i in range(len(search)):
content = string.replace(content, search[i], replace[i])

# strip out code that should not be in the minified version
cleanContent = re.sub(r'//\^[^\x00]*?//\$[^\n\r]+', '', content)

# write the whole (cleaned) content
write('../' + fullName, cleanContent)

# MINIFY!

# YUICompressor [faster, less greedy, bigger size]
# os.system('java -jar "' + fullPath('jar/yuicompressor-2.4.6.jar') + '" --type=js "' + fullPath('../' + fullName) + '" -o "' + fullPath('../' + minName) + '"')

# Uglify JS [good performances, mediumly greedy, medium size]
# os.system('java -jar "' + fullPath('jar/js.jar') + '" "' + fullPath('uglify-js/exec.js') + '" "' + fullPath('uglify-js/uglify.js') + '" "' + fullPath('../' + fullName) + '" "' + copyright + '" > "' + fullPath('../' + minName) + '"')

# Google Closure Compiler [slowest, more greedy, smaller size]
os.system('java -jar "' + fullPath('jar/compiler.jar') + '" --compilation_level=ADVANCED_OPTIMIZATIONS --language_in ECMASCRIPT5_STRICT --js "' + fullPath('../' + fullName) + '" --js_output_file "' + fullPath('../' + minName) + '"')

# put back code that should have not been included in the minified version
write('../' + fullName, content)

# create the gzip version
content = read('../' + minName)
tmp = gzip.open(fullPath('../' + minName + '.gz'), 'w')
tmp.write(content)
tmp.close()

# print out the result of all precedent operations
print('Full size: ' + getSize('../' + fullName))
print('Minified size: ' + getSize('../' + minName))
print('Min + Gzip size: ' + getSize('../' + minName + '.gz'))

# remove the gzipped version
os.remove(fullPath('../' + minName + '.gz'))
32 changes: 32 additions & 0 deletions builder/build.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# JSBuilder example

# project name (from the root folder)
copyright = ''
max_js = 'dist/id3.js'
min_js = 'dist/id3.min.js'

# file list (from the root/src folder)
files = [
"stringutils.js",
"binaryfile.js",
"filereader.js",
"base64.js",
"id3.js",
"id3v1.js",
"id3v2.js",
"id3v2frames.js",
"id4.js"
]

# execute the task
import JSBuilder
JSBuilder.compile(
copyright,
max_js,
min_js,
files
)

# let me read the result ...
import time
time.sleep(2)
Binary file added builder/jar/compiler.jar
Binary file not shown.
Binary file added builder/jar/js.jar
Binary file not shown.
Binary file added builder/jar/yuicompressor-2.4.6.jar
Binary file not shown.
3 changes: 3 additions & 0 deletions builder/uglify-js/exec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// readFile("tmp.js")
load(arguments[0]);
print("/*" + arguments[2] + "*/" + Uglify.uglify(readFile(arguments[1])))
Loading