Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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)
Exemplo n.º 3
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
Exemplo n.º 4
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