@@ -0,0 +1,705 @@
+#!/usr/bin/env python%0A%0A# Note, you need to pip install python-magic to use this.%0A%0Aimport magic%0Aimport os%0Aimport sys%0A%0Adef fix_with_magic(filename):%0A    base, ext = os.path.splitext(filename)%0A    if ext:%0A        print %22skipping %7B%7D%22.format(filename)%0A        return%0A%0A    result = magic.from_file(filename, mime=True)%0A    if result.startswith(%22text/%22):%0A        new_name = filename + %22.%22 + result%5B5:%5D%0A        if os.path.exists(new_name):%0A            print %22%7B%7D already exists!%22.format(new_name)%0A            raise SystemExit(1)%0A        os.rename(filename, new_name)%0A    else:%0A        print %22Unsupported! %7B%7D%22.format(filename)%0A        raise SystemExit(1)%0A%0Aif __name__ == '__main__':%0A    fix_with_magic(sys.argv%5B1%5D)%0A

Add script to add extension based on mimetype