--- f29c0eef0.txt 2009-11-24 12:48:23.000000000 +0000 +++ mobidedrm_plugin.py 2009-11-24 12:49:42.000000000 +0000 @@ -1,6 +1,6 @@ -# This is a python script. You need a Python interpreter to run it. -# For example, ActiveState Python, which exists for windows. -# +import os, subprocess +from calibre.customize import FileTypePlugin + # Changelog # 0.01 - Initial version # 0.02 - Huffdic compressed books were not properly decrypted @@ -169,17 +169,30 @@ class DrmStripper: def getResult(self): return self.data_file -print "MobiDeDrm v0.06. Copyright (c) 2008 The Dark Reverser" -if len(sys.argv)<4: - print "Removes protection from Mobipocket books" - print "Usage:" - print " mobidedrm infile.mobi outfile.mobi PID" -else: - infile = sys.argv[1] - outfile = sys.argv[2] - pid = sys.argv[3] - data_file = file(infile, 'rb').read() - try: - file(outfile, 'wb').write(DrmStripper(data_file, pid).getResult()) - except DrmException, e: - print "Error: %s" % e \ No newline at end of file + +class MobiDeDRM(FileTypePlugin): + + name = 'MobiDeDRM' # Name of the plugin + description = 'Removes DRM from secure Mobi files' + supported_platforms = ['linux', 'osx', 'windows'] # Platforms this plugin will run on + author = 'Who Says' # The author of this plugin + version = (0, 0, 6) # The version number of this plugin + file_types = set(['prc']) # The file types that this plugin will be applied to + on_import = True # Run this plugin during the import + + + def run(self, path_to_ebook): + of = self.temporary_file('.mobi') + PID = self.site_customization + data_file = file(path_to_ebook, 'rb').read() + try: + file(of.name, 'wb').write(DrmStripper(data_file, PID).getResult()) + except Exception, e: + strexcept = 'echo exception: %s > /dev/tty' % e + subprocess.call(strexcept,shell=True) + raise e + + return of.name + + def customization_help(self, gui=False): + return 'Enter PID'