View Single Post
Old 02-07-2010, 06:19 AM   #352
krischik
Addict
krischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheesekrischik can extract oil from cheese
 
krischik's Avatar
 
Posts: 334
Karma: 1234
Join Date: Jul 2009
Location: Hindelbank, Switzerland
Device: P990i, PRS 505
Exclamation if not __name__ == "__main__":

Quote:
Originally Posted by primetime34 View Post
None of the new versions of mobidedrm work on my drm files. Just an old version of .02 does. Any help with compiling the calibre plugin with the old .02 version? Thanks.
The calibre plugin is not a different program. It is a different startup procedure inside the same program:

Code:
if not __name__ == "__main__":
	from calibre.customize import FileTypePlugin

	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              = 'The Dark Reverser' # The author of this plugin
		version             = (0, 0, 7)   # The version number of this plugin
		file_types          = set(['prc','mobi','awz']) # 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()
			ar = PID.split(',')
			for i in ar:
				try:
					file(of.name, 'wb').write(DrmStripper(data_file, i).getResult())
				except DrmException:
					# Hm, we should display an error dialog here.
					# Dunno how though.
					# Ignore the dirty hack behind the curtain.
#					strexcept = 'echo exception: %s > /dev/tty' % e
#					subprocess.call(strexcept,shell=True)
					print i + ": not PID for book"
				else:
					return of.name

		def customization_help(self, gui=False):
			return 'Enter PID (separate multiple PIDs with comma)'

if __name__ == "__main__":
	print "MobiDeDrm v0.07. 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" %
Question is: how much work would it be to patch the startup code into the older versions.

Martin
krischik is offline   Reply With Quote