"""Return information from files like production-companies.data, keywords.data and so on.""" index = getFullIndex(indexF, movieID, kind='idx2idx') if index is None: return [] result = [] try: fdata = open(dataF, 'rb') except IOError, e: raise IMDbDataAccessError, str(e) fdata.seek(index) # Eat the first offset. if len(fdata.read(3)) != 3: fdata.close() return [] while 1: length = convBin(fdata.read(1), 'length') strval = latin2utf(fdata.read(length)) attrid = convBin(fdata.read(3), 'attrID') if attrid != 0xffffff: attr = getLabel(attrid, attrIF, attrKF) if attr: strval += ' %s' % attr result.append(strval) nextBin = fdata.read(3) # There can be multiple values. if not (len(nextBin) == 3 and \ convBin(nextBin, 'movieID') == movieID): break fdata.close() return result
def getMovieMisc(movieID, dataF, indexF, attrIF, attrKF): """Return information from files like production-companies.data, keywords.data and so on.""" index = getFullIndex(indexF, movieID, kind='idx2idx') if index is None: return [] result = [] try: fdata = open(dataF, 'rb') except IOError, e: raise IMDbDataAccessError, str(e) fdata.seek(index) # Eat the first offset. if len(fdata.read(3)) != 3: fdata.close() return [] while 1: length = convBin(fdata.read(1), 'length') strval = latin2utf(fdata.read(length)) attrid = convBin(fdata.read(3), 'attrID') if attrid != 0xffffff: attr = getLabel(attrid, attrIF, attrKF) if attr: strval += ' %s' % attr result.append(strval) nextBin = fdata.read(3) # There can be multiple values. if not (len(nextBin) == 3 and \ convBin(nextBin, 'movieID') == movieID): break fdata.close() return result
def _convChID(companyID): """Return a numeric value for the given string, or None.""" if companyID is None: return None return convBin(companyID, 'companyID')
def getCompanyName(companyID, compIF, compDF): """Return the company name for the specified companyID or None.""" try: ifptr = open(compIF, 'rb') except IOError, e: import warnings warnings.warn('Unable to access companies information, ' 'please run the companies4local.py script: %s' % e) return None ifptr.seek(4L * companyID) piddata = ifptr.read(4) ifptr.close() if len(piddata) != 4: return None idx = convBin(piddata, 'fulloffset') try: dfptr = open(compDF, 'rb') except IOError, e: import warnings warnings.warn('Unable to access companies information, ' 'please run the companies4local.py script: %s' % e) return None dfptr.seek(idx) # Check companyID. chID = dfptr.read(3) if companyID != convBin(chID, 'companyID'): return None length = convBin(dfptr.read(2), 'longlength') name = latin2utf(dfptr.read(length)) dfptr.close()
def _convChID(characterID): """Return a numeric value for the given string, or None.""" if characterID is None: return None return convBin(characterID, 'characterID')
def getCharacterName(characterID, charIF, charDF): """Return the character name for the specified characterID or None.""" try: ifptr = open(charIF, 'rb') except IOError, e: import warnings warnings.warn('Unable to access characters information, ' 'please run the characters4local.py script: %s' % e) return None ifptr.seek(4L*characterID) piddata = ifptr.read(4) ifptr.close() if len(piddata) != 4: return None idx = convBin(piddata, 'fulloffset') try: dfptr = open(charDF, 'rb') except IOError, e: import warnings warnings.warn('Unable to access characters information, ' 'please run the characters4local.py script: %s' % e) return None dfptr.seek(idx) # Check characterID. chID = dfptr.read(3) if characterID != convBin(chID, 'characterID'): return None length = convBin(dfptr.read(2), 'longlength') name = latin2utf(dfptr.read(length)) dfptr.close()
def getCompanyName(companyID, compIF, compDF): """Return the company name for the specified companyID or None.""" try: ifptr = open(compIF, 'rb') except IOError, e: import warnings warnings.warn('Unable to access companies information, ' 'please run the companies4local.py script: %s' % e) return None ifptr.seek(4L*companyID) piddata = ifptr.read(4) ifptr.close() if len(piddata) != 4: return None idx = convBin(piddata, 'fulloffset') try: dfptr = open(compDF, 'rb') except IOError, e: import warnings warnings.warn('Unable to access companies information, ' 'please run the companies4local.py script: %s' % e) return None dfptr.seek(idx) # Check companyID. chID = dfptr.read(3) if companyID != convBin(chID, 'companyID'): return None length = convBin(dfptr.read(2), 'longlength') name = latin2utf(dfptr.read(length)) dfptr.close()