def __init__(self, metadataDbHandler, voteCastDBHandler, myPermId, subSupport=None, peerHaveManager = None, notifier = None): ''' Builds an instance of RichMetadataInterceptor. @param metadataDbHandler: an registered instance of L{MetadataDBHandler} @param voteCastDBHandler: a registered instance of VoteCastDBHandler @param myPermId: the PermId of the client. @param subSupport: a registered instance of L{SubtitlesSupport} @param peerHaveManager: an instance of L{PeerHaveManager} @param notifier: an instance of Notifier ''' # assert isinstance(metadataDbHandler, MetadataDBHandler), \ # "Invalid RichMetadata DB Handler" # assert isinstance(voteCastDBHandler, VoteCastDBHandler), \ # "Invalid Votecast DB Handler" #hack to make a fast test DELETE THIS CONDITION # if subSupp != None: # assert isinstance(subSupp, SubtitlesSupport) assert isValidPermid(myPermId), "Invalid Permid" self.rmdDb = metadataDbHandler self.votecastDB = voteCastDBHandler self.my_permid = myPermId self.subSupport = subSupport self.peerHaveManager = peerHaveManager self.notifier = notifier
def __init__(self, metadataDbHandler, voteCastDBHandler, myPermId, subSupport=None, peerHaveManager=None, notifier=None): ''' Builds an instance of RichMetadataInterceptor. @param metadataDbHandler: an registered instance of L{MetadataDBHandler} @param voteCastDBHandler: a registered instance of VoteCastDBHandler @param myPermId: the PermId of the client. @param subSupport: a registered instance of L{SubtitlesSupport} @param peerHaveManager: an instance of L{PeerHaveManager} @param notifier: an instance of Notifier ''' # assert isinstance(metadataDbHandler, MetadataDBHandler), \ # "Invalid RichMetadata DB Handler" # assert isinstance(voteCastDBHandler, VoteCastDBHandler), \ # "Invalid Votecast DB Handler" #hack to make a fast test DELETE THIS CONDITION # if subSupp != None: # assert isinstance(subSupp, SubtitlesSupport) assert isValidPermid(myPermId), "Invalid Permid" self.rmdDb = metadataDbHandler self.votecastDB = voteCastDBHandler self.my_permid = myPermId self.subSupport = subSupport self.peerHaveManager = peerHaveManager self.notifier = notifier
def sendSubtitleRequest(self, permid, channel_id, infohash, languages, callback=None, selversion= -1): """ Send a request for subtitle files. Only called by the OLThread Send a GET_SUBS request to the peer identified by permid. The request asks for several subtitles file, for a given channel_id and torrent infohash. The subtitles file to request are specified by the languages parameter that is a list of 3 characters language codes. The contents of a GET_SUBS request are: - channel_id: the identifier of the channel for which the subtitles were added. (a permid). Binary. - infohash: the infohash of the torrent, the subtitles refer to. Binary. - bitmask: a 32 bit bitmask (an integer) which specifies the languages requested @param permid: the destination of the request (binary) @param channel_id: the identifier of the channel for which the subtitle was added (binary) @param infohash: the infohash of a torrent the subtitles refers to (binary). @param languages: a list of 3-characters language codes. It must be on of the supported language codes (see Languages) @param callback: a function that will be called WHENEVER some of the requested subtitles are received. It must have exactly one parameter that will be bound to a list of the languages that were received @param selversion: the protocol version of the peer whe are sending the request to @raise SubtitleMsgHandlerException: if the message failed its attempt to be sent. Notice that also if the method returns without raising any exception it doesn't mean that the message has been sent. """ assert utilities.isValidInfohash(infohash), SUBS_LOG_PREFIX + "Invalid infohash %s" % infohash assert utilities.isValidPermid(permid), SUBS_LOG_PREFIX + "Invlaid destination permid %s" % permid assert self.languagesUtility.isLangListSupported(languages), SUBS_LOG_PREFIX + "Some of the languages where not supported" if DEBUG: print >> sys.stderr, SUBS_LOG_PREFIX + "preparing to send GET_SUBS to " + utilities.show_permid_short(permid) if len(languages) == 0: if DEBUG: print >> sys.stderr, SUBS_LOG_PREFIX + " no subtitles to request." return requestDetails = dict() requestDetails['channel_id'] = channel_id requestDetails['infohash'] = infohash requestDetails['languages'] = languages self._subsMsgHndlr.sendSubtitleRequest(permid, requestDetails, lambda e,d,c,i,b : \ self._subsRequestSent(e,d,c,i,b), callback, selversion)
def __init__(self, publisher, infohash, timestamp=None, description=u"", subtitles=None, signature=None): """ Create a MetataDTO instance. publisher and infohash are mandatory to be not null @param publisher: the permid of the owner of the channel this instance refers to @param infohash: the infohash of the item in the channel this instance refers to @param timestamp: the timestamp of the creation of this metadata instance. This can be later reset with resetTimestamp() @param description: an optional utf-8 string description for the item. Defaults to an empty string @param subtitles: a dictionary of type {langCode : SubtitleInfo} @param signature: signature of the packed version of this metadataDTO. Defaults to None. It can be later signed with sign() """ assert publisher is not None assert infohash is not None assert isValidPermid(publisher) assert isValidInfohash(infohash) #stringified permid of the owner of the channel self.channel = publisher #stringified infohash (bin2str) of the torrent self.infohash = infohash if timestamp is not None: timestring = int(floor(timestamp)) else: timestring = int(floor(time.time())) #integer timestamp of the creation of this content #(the content, not the MetadataDTO instance) self.timestamp = timestring #utf-8 string description if isinstance(description, str): description = unicode(description, "utf-8") self.description = description if subtitles is None: subtitles = {} self._subtitles = subtitles self.signature = signature
def __init__(self, publisher,infohash,timestamp = None, description=u"", subtitles=None,signature=None): """ Create a MetataDTO instance. publisher and infohash are mandatory to be not null @param publisher: the permid of the owner of the channel this instance refers to @param infohash: the infohash of the item in the channel this instance refers to @param timestamp: the timestamp of the creation of this metadata instance. This can be later reset with resetTimestamp() @param description: an optional utf-8 string description for the item. Defaults to an empty string @param subtitles: a dictionary of type {langCode : SubtitleInfo} @param signature: signature of the packed version of this metadataDTO. Defaults to None. It can be later signed with sign() """ assert publisher is not None assert infohash is not None assert isValidPermid(publisher) assert isValidInfohash(infohash) #stringified permid of the owner of the channel self.channel = publisher #stringified infohash (bin2str) of the torrent self.infohash = infohash if timestamp is not None: timestring = int(floor(timestamp)) else: timestring = int(floor(time.time())) #integer timestamp of the creation of this content #(the content, not the MetadataDTO instance) self.timestamp = timestring #utf-8 string description if isinstance(description, str): description = unicode(description, "utf-8") self.description = description if subtitles is None: subtitles = {} self._subtitles = subtitles self.signature = signature
def _register(self, richMetadataDBHandler, subtitlesHandler, channelcast_db, my_permid, my_keypair, peersHaveManger, ol_bridge): assert richMetadataDBHandler is not None assert subtitlesHandler is not None assert channelcast_db is not None assert peersHaveManger is not None assert ol_bridge is not None assert isValidPermid(my_permid) self.richMetadata_db = richMetadataDBHandler self.subtitlesHandler = subtitlesHandler self.channelcast_db = channelcast_db self.my_permid = my_permid self.my_keypair = my_keypair self._peersHaveManager = peersHaveManger #used to decouple calls to SubtitleHandler self._ol_bridge = ol_bridge self._registered = True