class SetDeliveryMechanismMonitor(IdentifierSweepMonitor): def __init__(self, _db, interval_seconds=None): super(SetDeliveryMechanismMonitor, self).__init__( _db, "20151002 migration - Correct medium of mislabeled audiobooks", interval_seconds, batch_size=100) self.overdrive = OverdriveAPI(_db) self.threem = ThreeMAPI(_db) types = [ Identifier.THREEM_ID, Identifier.OVERDRIVE_ID, Identifier.AXIS_360_ID ] content_types = [ "application/epub+zip", "application/pdf", "Kindle via Amazon", "Streaming Text" ] def identifier_query(self): qu = self._db.query(Identifier).join(Identifier.licensed_through).join( LicensePool.delivery_mechanisms).join( LicensePoolDeliveryMechanism.delivery_mechanism).filter( Identifier.type.in_( self.types)).filter(~DeliveryMechanism.content_type. in_(self.content_types)) return qu def process_identifier(self, identifier): # What is the correct medium? correct_medium = None lp = identifier.licensed_through for lpdm in lp.delivery_mechanisms: correct_medium = lpdm.delivery_mechanism.implicit_medium if correct_medium: break if not correct_medium and identifier.type == Identifier.OVERDRIVE_ID: content = self.overdrive.metadata_lookup(identifier) metadata = OverdriveRepresentationExtractor.book_info_to_metadata( content) correct_medium = metadata.medium if not correct_medium and identifier.type == Identifier.THREEM_ID: metadata = self.threem.bibliographic_lookup(identifier) correct_medium = metadata.medium if not correct_medium: set_trace() if lp.edition.medium != correct_medium: print "%s is actually %s, not %s" % ( lp.edition.title, correct_medium, lp.edition.medium) lp.edition.medium = correct_medium or Edition.BOOK_MEDIUM
class SetDeliveryMechanismMonitor(IdentifierSweepMonitor): def __init__(self, _db, interval_seconds=None): super(SetDeliveryMechanismMonitor, self).__init__( _db, "20151002 migration - Correct medium of mislabeled audiobooks", interval_seconds, batch_size=100) self.overdrive = OverdriveAPI(_db) self.threem = ThreeMAPI(_db) types = [Identifier.THREEM_ID, Identifier.OVERDRIVE_ID, Identifier.AXIS_360_ID] content_types = ["application/epub+zip", "application/pdf", "Kindle via Amazon", "Streaming Text"] def identifier_query(self): qu = self._db.query(Identifier).join( Identifier.licensed_through).join( LicensePool.delivery_mechanisms).join( LicensePoolDeliveryMechanism.delivery_mechanism).filter( Identifier.type.in_(self.types)).filter( ~DeliveryMechanism.content_type.in_(self.content_types) ) return qu def process_identifier(self, identifier): # What is the correct medium? correct_medium = None lp = identifier.licensed_through for lpdm in lp.delivery_mechanisms: correct_medium = lpdm.delivery_mechanism.implicit_medium if correct_medium: break if not correct_medium and identifier.type==Identifier.OVERDRIVE_ID: content = self.overdrive.metadata_lookup(identifier) metadata = OverdriveRepresentationExtractor.book_info_to_metadata(content) correct_medium = metadata.medium if not correct_medium and identifier.type==Identifier.THREEM_ID: metadata = self.threem.bibliographic_lookup(identifier) correct_medium = metadata.medium if not correct_medium: set_trace() if lp.edition.medium != correct_medium: print "%s is actually %s, not %s" % (lp.edition.title, correct_medium, lp.edition.medium) lp.edition.medium = correct_medium or Edition.BOOK_MEDIUM
class SetDeliveryMechanismMonitor(IdentifierSweepMonitor): def __init__(self, _db, interval_seconds=None): super(SetDeliveryMechanismMonitor, self).__init__( _db, "20150929 migration - Set delivery mechanism for 3M books", interval_seconds, batch_size=10) self.api = ThreeMAPI(_db) self.metadata_client = SimplifiedOPDSLookup( "http://metadata.alpha.librarysimplified.org/") def identifier_query(self): return self._db.query(Identifier).filter( Identifier.type == Identifier.THREEM_ID) def process_identifier(self, identifier): metadata = self.api.bibliographic_lookup(identifier) license_pool = identifier.licensed_through for format in metadata.formats: print "%s: %s - %s" % (identifier.identifier, format.content_type, format.drm_scheme) mech = license_pool.set_delivery_mechanism(format.content_type, format.drm_scheme, format.link)
lookup = SimplifiedOPDSLookup("http://metadata.alpha.librarysimplified.org/") _db = production_session() overdrive = OverdriveAPI(_db) threem = ThreeMAPI(_db) q = _db.query(Edition).join(Edition.data_source).filter( DataSource.name.in_([DataSource.OVERDRIVE])).filter(Edition.author == '') print "Fixing %s books." % q.count() for edition in q: if edition.data_source.name == DataSource.OVERDRIVE: data = overdrive.metadata_lookup(edition.primary_identifier) metadata = OverdriveRepresentationExtractor.book_info_to_metadata(data) else: metadata = threem.bibliographic_lookup(edition.primary_identifier) metadata.update_contributions(_db, edition, metadata_client=lookup, replace_contributions=True) if edition.work: edition.work.calculate_presentation() else: edition.calculate_presentation() for c in edition.contributions: print "%s = %s (%s)" % (c.role, c.contributor.display_name, c.contributor.name) print edition.author, edition.sort_author _db.commit()
) from threem import ThreeMAPI from core.opds_import import SimplifiedOPDSLookup lookup = SimplifiedOPDSLookup("http://metadata.alpha.librarysimplified.org/") _db = production_session() overdrive = OverdriveAPI(_db) threem = ThreeMAPI(_db) q = _db.query(Edition).join(Edition.data_source).filter(DataSource.name.in_([DataSource.OVERDRIVE])).filter(Edition.author=='') print "Fixing %s books." % q.count() for edition in q: if edition.data_source.name==DataSource.OVERDRIVE: data = overdrive.metadata_lookup(edition.primary_identifier) metadata = OverdriveRepresentationExtractor.book_info_to_metadata(data) else: metadata = threem.bibliographic_lookup(edition.primary_identifier) metadata.update_contributions(_db, edition, metadata_client=lookup, replace_contributions=True) if edition.work: edition.work.calculate_presentation() else: edition.calculate_presentation() for c in edition.contributions: print "%s = %s (%s)" % ( c.role, c.contributor.display_name, c.contributor.name ) print edition.author, edition.sort_author _db.commit()