def publishSubtitle(self, infohash, lang, pathToSrtSubtitle):
        channelid = bin2str(self.my_permid)
        base64infohash = bin2str(infohash)
        consinstent = self.channelcast_db.isItemInChannel(channelid, base64infohash)
        if not consinstent:
            msg = 'Infohash %s not found in my channel. Rejecting subtitle' % base64infohash
            if DEBUG:
                print >> sys.stderr, msg
            raise RichMetadataException(msg)
        try:
            filepath = self.subtitlesHandler.copyToSubtitlesFolder(pathToSrtSubtitle, self.my_permid, infohash, lang)
        except Exception as e:
            if DEBUG:
                print >> sys.stderr, 'Failed to read and copy subtitle to appropriate folder: %s' % str(e)

        metadataDTO = self.richMetadata_db.getMetadata(self.my_permid, infohash)
        if metadataDTO is None:
            metadataDTO = MetadataDTO(self.my_permid, infohash)
        else:
            metadataDTO.resetTimestamp()
        newSubtitle = SubtitleInfo(lang, filepath)
        if newSubtitle.subtitleExists():
            newSubtitle.computeChecksum()
        else:
            msg = 'Inconsistency found. The subtitle was not published'
            if DEBUG:
                print >> sys.stderr, msg
            raise RichMetadataException(msg)
        metadataDTO.addSubtitle(newSubtitle)
        metadataDTO.sign(self.my_keypair)
        self.richMetadata_db.insertMetadata(metadataDTO)
Esempio n. 2
0
def _createSubtitlesDict(bitmask, listOfChecksums):
    langList = _languagesUtil.maskToLangCodes(bitmask)
    if len(langList) != len(listOfChecksums):
        raise SerializationException('Unexpected num of checksums')
    subtitles = {}
    for i in range(0, len(langList)):
        sub = SubtitleInfo(langList[i])
        sub.checksum = listOfChecksums[i]
        subtitles[langList[i]] = sub

    return subtitles
def _createSubtitlesDict(bitmask, listOfChecksums):
    langList = _languagesUtil.maskToLangCodes(bitmask)
    if len(langList) != len(listOfChecksums):
        raise SerializationException('Unexpected num of checksums')
    subtitles = {}
    for i in range(0, len(langList)):
        sub = SubtitleInfo(langList[i])
        sub.checksum = listOfChecksums[i]
        subtitles[langList[i]] = sub

    return subtitles
 def _getSubtitleByKey(self, metadata_fk, lang):
     query = QUERIES['SELECT SUBS FK ONE']
     res = self._db.fetchall(query, (metadata_fk, lang))
     if len(res) == 0:
         return None
     if len(res) == 1:
         checksum = str2bin(res[0][3])
         return SubtitleInfo(res[0][1], res[0][2], checksum)
     raise MetadataDBException('Metadata DB Constraint violeted!')
    def _getAllSubtitlesByKey(self, metadataKey):
        query = QUERIES['SELECT SUBS FK ALL']
        results = self._db.fetchall(query, (metadataKey, ))
        subsDict = {}
        for entry in results:
            subsDict[entry[1]] = SubtitleInfo(entry[1], entry[2],
                                              str2bin(entry[3]))

        return subsDict
    def getAllSubtitles(self, channel, infohash):
        query = QUERIES['SELECT SUBS JOIN HASH ALL']
        infohash = bin2str(infohash)
        channel = bin2str(channel)
        results = self._db.fetchall(query, (infohash, channel))
        subsDict = {}
        for entry in results:
            subsDict[entry[1]] = SubtitleInfo(entry[1], entry[2], entry[3])

        return subsDict
 def getSubtitle(self, channel, infohash, lang):
     query = QUERIES['SELECT SUBS JOIN HASH ONE']
     infohash = bin2str(infohash)
     channel = bin2str(channel)
     res = self._db.fetchall(query, (infohash, channel, lang))
     if len(res) == 0:
         return None
     if len(res) == 1:
         checksum = str2bin(res[0][3])
         return SubtitleInfo(res[0][1], res[0][2], checksum)
     raise MetadataDBException('Metadata DB Constraint violeted!')
    def getLocalSubtitles(self, channel, infohash):
        query = QUERIES['SELECT SUBTITLES WITH PATH BY CHN INFO']
        channel = bin2str(channel)
        infohash = bin2str(infohash)
        res = self._db.fetchall(query, (channel, infohash))
        result = {}
        for entry in res:
            location = entry[0]
            language = entry[1]
            checksum = str2bin(entry[2])
            subInfo = SubtitleInfo(language, location, checksum)
            result[language] = subInfo

        return result
    def getAllLocalSubtitles(self):
        query = QUERIES['SELECT SUBTITLES WITH PATH']
        res = self._db.fetchall(query)
        result = {}
        for entry in res:
            path = entry[1]
            lang = entry[2]
            checksum = str2bin(entry[3])
            channel = str2bin(entry[4])
            infohash = str2bin(entry[5])
            s = SubtitleInfo(lang, path, checksum)
            if channel not in result:
                result[channel] = {}
            if infohash not in result[channel]:
                result[channel][infohash] = []
            result[channel][infohash].append(s)

        return result