def getEpisodeTitre(self, sTitle): string = re.search('(?i)(e(?:[a-z]+sode\s?)*([0-9]+))', str(sTitle)) if string: sTitle = sTitle.replace(string.group(1),'') sTitle = "%s [COLOR coral]E%02d[/COLOR]"%(sTitle, int(string.group(2))) self.addItemValues('Episode', string.group(2)) return sTitle, True return sTitle, False
def getEpisodeTitre(self, sTitle): string = re.search('(?i)(e(?:[a-z]+sode\s?)*([0-9]+))', sTitle) if string: sTitle = sTitle.replace(string.group(1), '') self.__Episode = ('%02d' % int(string.group(2))) sTitle = '%s [COLOR %s]E%s[/COLOR]' % (sTitle, self.__sDecoColor, self.__Episode) self.addItemValues('Episode', self.__Episode) return sTitle, True return sTitle, False
def getSaisonTitre(self, sTitle): string = re.search('(?i)(s(?:[a-z]+son\s?)*([0-9]+))', str(sTitle)) if string: sTitle = sTitle.replace(string.group(1),'') self.__Season = ("%02d" % int(string.group(2))) sTitle = "%s [COLOR coral]S%s[/COLOR]"%(sTitle, self.__Season) self.addItemValues('Season', self.__Season) return sTitle, True return sTitle, False
def getEpisodeTitre(self, sTitle): string = re.search('(?i)(e(?:[a-z]+sode\s?)*([0-9]+))', str(sTitle)) if string: sTitle = sTitle.replace(string.group(1), '') self.__Episode = ("%02d" % int(string.group(2))) sTitle = "%s [COLOR %s]E%s[/COLOR]" % (sTitle, self.__sDecoColor, self.__Episode) self.addItemValues('Episode', self.__Episode) return sTitle, True return sTitle, False
def strip_digits(string): old = string exp = re.compile("^\d* *([\w.,'\s]+)$") string = exp.search(string) if string == None: return old return string.group(1).strip()
def loop(self): readbuffer = "" while 1: # fetch message, parse it readbuffer = readbuffer+self.s.recv(1024).decode("UTF-8") temp = str.split(readbuffer, "\n") readbuffer = temp.pop( ) # print recieved messages print(temp[0]) # if chat message if(temp[0].find("PRIVMSG") > 0 and not temp[0].startswith(":" + self.host)): # parse it # 1:nick, 2:ident, 3:type, 4:destination, 5:message msgbuffer = re.search(':(.+)!.+@(.+) (\w+) (.+) :(.+)', temp[0]) try: sender = msgbuffer.group(1) # sender of message ident = msgbuffer.group(2) # used to verify nickname if registered to nickserv type = msgbuffer.group(3) # we already know this is PRIVMSG channel = msgbuffer.group(4) # destination, can also be nickname message = msgbuffer.group(5).replace("\r\n", "").replace("\r", "").replace("\n", "") # message string except Exception as e: sender = "" ident = "" type = "" channel = "" message = "" # if owner sends commands through private message if(ident == self.owner and channel == self.nick): if("join" in message): chan = message.split("#") vbot.send("JOIN", "#"+chan, "") elif("part" in message): chan = message.split("#") vbot.send("PART", "#"+chan, "") elif("quit" in message): vbot.quit() # if message seems to be a command if(message.startswith("-")): cmd = re.search("(-\w+)", message) cmd = cmd.group(1) try: string = re.search("-\w+\s+(.+)", message) string = string.group(1) except Exception as e: string = "" # if message corresponds to command then execute for command in commands: if(command.name == cmd): command.execute(string, channel, sender) # if nickserv complains and bot is a registered user elif("NickServ" in temp[0] and "registered" in temp[0] and self.nickserv): self.send("", "NickServ", "identify " + self.password) # if ping elif("PING" in temp[0]): self.send("PONG", "", temp[0])
def TraiteTitre(self, sTitle): # Format Obligatoire a traiter via le fichier site #------------------------------------------------- # Episode 7 a 9 > Episode 7-9 # Saison 1 à ? > Saison 1-? # Format de date > 11/22/3333 ou 11-22-3333 #convertion unicode ne fonctionne pas avec les accents try: sTitle = sTitle.decode("utf-8") #traitement du titre pour les caracteres speciaux sTitle = sTitle.replace('—', '-').replace( '’', '\'').replace('…', '...').replace('′', '\'').replace('‘', '\'') except: pass #recherche l'année, uniquement si entre caractere special a cause de 2001 odysse de l'espace ou k2000 string = re.search('([^\w ][0-9]{4}[^\w ])', sTitle) if string: sTitle = sTitle.replace(string.group(0), '') self.__Year = str(string.group(0)[1:5]) self.addItemValues('Year', self.__Year) #recherche une date string = re.search('([\d]{2}[\/|-]\d{2}[\/|-]\d{4})', sTitle) if string: sTitle = sTitle.replace(string.group(0), '') self.__Date = str(string.group(0)) sTitle = "%s (%s) " % (sTitle, self.__Date) #~ #recherche Lang #~ index = { ' vostfr' : ' [VOSTFR]', ' vf' : ' [VF]', ' truefrench' : ' [TrueFrench]' } #~ for cle in index: #~ sTitle=sTitle.replace(cle.upper(), index[cle]).replace(cle, index[cle]).replace('(%s)' % (cle), index[cle]) #~ #recherche Qualiter #~ index = { '1080i' : '(1080)', '1080p' : '(1080)', '1080I' : '(1080)', '1080P' : '(1080)', '720i' : '(720)', '720p' : '(720)', '720I' : '(720)', '720P' : '(720)' } #~ for cle in index: #~ sTitle=sTitle.replace(cle, index[cle]).replace('[%s]' % (cle), index[cle]) #Recherche saison et episode a faire pr serie uniquement if (True): SXEX = '' #m = re.search( ur'(?i)(\wpisode ([0-9\.\-\_]+))',sTitle,re.UNICODE) m = re.search( ur'(?i)(?:^|[^a-z])((?:E|(?:\wpisode\s?))([0-9]+(?:[\-\.][0-9\?]+)*))', sTitle, re.UNICODE) if m: #ok y a des episodes sTitle = sTitle.replace(m.group(1), '') ep = m.group(2) if len(ep) == 1: ep = '0' + ep self.__Episode = ep self.addItemValues('Episode', self.__Episode) #pr les saisons m = re.search(ur'(?i)(s(?:aison +)*([0-9]+(?:\-[0-9\?]+)*))', sTitle, re.UNICODE) if m: sTitle = sTitle.replace(m.group(1), '') sa = m.group(2) if len(sa) == 1: sa = '0' + sa self.__Season = sa self.addItemValues('Season', self.__Season) else: #pas d'episode mais y a t il des saisons ? #m = re.search('(?i)(s(?:aison +)*([0-9]+[0-9\-\?]*))(?:$| )', sTitle) m = re.search(ur'(?i)(s(?:aison +)*([0-9]+(?:\-[0-9\?]+)*))', sTitle, re.UNICODE) if m: sTitle = sTitle.replace(m.group(1), '') sa = m.group(2) if len(sa) == 1: sa = '0' + sa self.__Season = sa self.addItemValues('Season', self.__Season) #supr les - #sTitle = sTitle.replace('-',' ') # A gerer dans le fichier site plutot, car il peut etre utile dans certain cas #vire doubles espaces sTitle = re.sub(' +', ' ', sTitle) sTitle = sTitle.replace('()', '').replace('[]', '').replace('- -', '-') #vire espace a la fin et les - (attention, il y a 2 tirets differents meme si invisible a l'oeil nu et un est en unicode) sTitle = re.sub(ur'[- –]+$', '', sTitle) #et en debut if sTitle.startswith(' '): sTitle = sTitle[1:] #recherche les Tags restant : () ou [] sauf tag couleur sTitle = re.sub(ur'([\(|\[](?!\/*COLOR)[^\)\(\]\[]+?[\]|\)])', '[COLOR ' + self.__sDecoColor + ']\\1[/COLOR]', sTitle) #on reformate SXXEXX Titre [tag] (Annee) sTitle2 = '' if self.__Season: sTitle2 = sTitle2 + 'S' + self.__Season if self.__Episode: sTitle2 = sTitle2 + 'E' + self.__Episode if sTitle2: sTitle2 = "[COLOR %s]%s[/COLOR] " % (self.__sDecoColor, sTitle2) sTitle2 = sTitle2 + sTitle if self.__Year: sTitle2 = "%s [COLOR %s](%s)[/COLOR]" % ( sTitle2, self.__sDecoColor, self.__Year) #xbmc.log('>>' + sTitle2, xbmc.LOGNOTICE) #on repasse en utf-8 return sTitle2.encode('utf-8')
def TraiteTitre(self, sTitle): # Format Obligatoire a traiter via le fichier source # ------------------------------------------------- # Episode 7 a 9 > Episode 7-9 # Saison 1 à ? > Saison 1-? # Format de date > 11/22/3333 ou 11-22-3333 # convertion unicode ne fonctionne pas avec les accents try: # traitement du titre pour les caracteres spéciaux déplacé dans parser plus global # traitement du titre pour retirer le - quand c'est une Saison. Tiret, tiret moyen et cadratin sTitle = sTitle.replace(' - Saison', ' Saison').replace( ' – Saison', ' Saison').replace(' — Saison', ' Saison') sTitle = sTitle.decode('utf-8') except: pass # recherche l'année, uniquement si entre caractere special a cause de 2001 odysse de l'espace ou k2000 string = re.search('([^\w ][0-9]{4}[^\w ])', sTitle) if string: sTitle = sTitle.replace(string.group(0), '') self.__Year = str(string.group(0)[1:5]) self.addItemValues('year', self.__Year) # recherche une date string = re.search('([\d]{2}[\/|-]\d{2}[\/|-]\d{4})', sTitle) if string: sTitle = sTitle.replace(string.group(0), '') self.__Date = str(string.group(0)) sTitle = '%s (%s) ' % (sTitle, self.__Date) #~ #recherche Lang #~ index = {' vostfr': ' [VOSTFR]', ' vf': ' [VF]', ' truefrench': ' [TrueFrench]'} #~ for cle in index: #~ sTitle = sTitle.replace(cle.upper(), index[cle]).replace(cle, index[cle]).replace('(%s)' % (cle), index[cle]) #~ #recherche Qualité #~ index = {'1080i': '(1080)', '1080p': '(1080)', '1080I': '(1080)', '1080P': '(1080)', '720i': '(720)', '720p': '(720)', '720I': '(720)', '720P': '(720)'} #~ for cle in index: #~ sTitle = sTitle.replace(cle, index[cle]).replace('[%s]' % (cle), index[cle]) # Recherche saison et episode a faire pr serie uniquement if True: m = re.search( '(?i)(?:^|[^a-z])((?:E|(?:\wpisode\s?))([0-9]+(?:[\-\.][0-9\?]+)*))', sTitle, re.UNICODE) if m: # ok y a des episodes sTitle = sTitle.replace(m.group(1), '') ep = m.group(2) if len(ep) == 1: ep = '0' + ep self.__Episode = ep self.addItemValues('Episode', self.__Episode) # pour les saisons m = re.search('(?i)( s(?:aison +)*([0-9]+(?:\-[0-9\?]+)*))', sTitle, re.UNICODE) if m: sTitle = sTitle.replace(m.group(1), '') sa = m.group(2) if len(sa) == 1: sa = '0' + sa self.__Season = sa self.addItemValues('Season', self.__Season) else: # pas d'episode mais y a t il des saisons ? m = re.search('(?i)( s(?:aison +)*([0-9]+(?:\-[0-9\?]+)*))', sTitle, re.UNICODE) if m: sTitle = sTitle.replace(m.group(1), '') sa = m.group(2) if len(sa) == 1: sa = '0' + sa self.__Season = sa self.addItemValues('Season', self.__Season) # vire doubles espaces sTitle = re.sub(' +', ' ', sTitle) # enleve les crochets et les parentheses si elle sont vides sTitle = sTitle.replace('()', '').replace('[]', '').replace('- -', '-') # vire espace a la fin et les - (attention, il y a 2 tirets differents meme si invisible a l'oeil nu et un est en unicode) sTitle = re.sub('[- –]+$', '', sTitle) # et au debut if sTitle.startswith(' '): sTitle = sTitle[1:] # recherche les Tags restant : () ou [] sauf tag couleur sTitle = re.sub('([\(|\[](?!\/*COLOR)[^\)\(\]\[]+?[\]|\)])', '[COLOR ' + self.__sDecoColor + ']\\1[/COLOR]', sTitle) # on reformate SXXEXX Titre [tag] (Annee) sTitle2 = '' if self.__Season: sTitle2 = sTitle2 + 'S' + self.__Season if self.__Episode: sTitle2 = sTitle2 + 'E' + self.__Episode # Titre unique pour pour marquer VU (avec numéro de l'épisode pour les séries) self.__sTitleWatched = self.str_conv(sTitle).replace(' ', '') if sTitle2: self.__sTitleWatched += '_' + sTitle2 if sTitle2: sTitle2 = '[COLOR %s]%s[/COLOR] ' % (self.__sDecoColor, sTitle2) sTitle2 = sTitle2 + sTitle if self.__Year: sTitle2 = '%s [COLOR %s](%s)[/COLOR]' % ( sTitle2, self.__sDecoColor, self.__Year) #Py3 try: if "é" in sTitle2: sTitle2 = sTitle2.encode("iso-8859-1", 'ignore') sTitle2 = str(sTitle2, encoding="utf8", errors='ignore') except: pass # on repasse en utf-8 try: return sTitle2.encode('utf-8') except AttributeError: return sTitle2
def TraiteTitre(self, sTitle): # Format Obligatoire a traiter via le fichier site #------------------------------------------------- # Episode 7 a 9 > Episode 7-9 # Saison 1 à ? > Saison 1-? # Format de date > 11/22/3333 ou 11-22-3333 #convertion unicode ne fonctionne pas avec les accents try: sTitle = sTitle.decode("utf-8") #traitement du titre pour les caracteres speciaux sTitle = sTitle.replace('—', '-').replace('’', '\'').replace('…', '...').replace('′', '\'').replace('‘', '\'') except: pass #recherche l'année, uniquement si entre caractere special a cause de 2001 odysse de l'espace ou k2000 string = re.search('([^\w ][0-9]{4}[^\w ])', sTitle) if string: sTitle = sTitle.replace(string.group(0), '') self.__Year = str(string.group(0)[1:5]) self.addItemValues('Year', self.__Year) #recherche une date string = re.search('([\d]{2}[\/|-]\d{2}[\/|-]\d{4})', sTitle) if string: sTitle = sTitle.replace(string.group(0), '') self.__Date = str(string.group(0)) sTitle = "%s (%s) " % (sTitle, self.__Date) #~ #recherche Lang #~ index = { ' vostfr' : ' [VOSTFR]', ' vf' : ' [VF]', ' truefrench' : ' [TrueFrench]' } #~ for cle in index: #~ sTitle=sTitle.replace(cle.upper(), index[cle]).replace(cle, index[cle]).replace('(%s)' % (cle), index[cle]) #~ #recherche Qualiter #~ index = { '1080i' : '(1080)', '1080p' : '(1080)', '1080I' : '(1080)', '1080P' : '(1080)', '720i' : '(720)', '720p' : '(720)', '720I' : '(720)', '720P' : '(720)' } #~ for cle in index: #~ sTitle=sTitle.replace(cle, index[cle]).replace('[%s]' % (cle), index[cle]) #Recherche saison et episode a faire pr serie uniquement if (True): SXEX = '' #m = re.search( ur'(?i)(\wpisode ([0-9\.\-\_]+))',sTitle,re.UNICODE) m = re.search(ur'(?i)(?:^|[^a-z])((?:E|(?:\wpisode\s?))([0-9]+(?:[\-\.][0-9\?]+)*))', sTitle, re.UNICODE) if m: #ok y a des episodes sTitle = sTitle.replace(m.group(1),'') ep = m.group(2) if len(ep) == 1: ep = '0' + ep self.__Episode = ep self.addItemValues('Episode', self.__Episode) #pr les saisons m = re.search(ur'(?i)(s(?:aison +)*([0-9]+(?:\-[0-9\?]+)*))', sTitle, re.UNICODE) if m: sTitle = sTitle.replace(m.group(1), '') sa = m.group(2) if len(sa) == 1: sa = '0' + sa self.__Season = sa self.addItemValues('Season', self.__Season) else: #pas d'episode mais y a t il des saisons ? #m = re.search('(?i)(s(?:aison +)*([0-9]+[0-9\-\?]*))(?:$| )', sTitle) m = re.search(ur'(?i)(s(?:aison +)*([0-9]+(?:\-[0-9\?]+)*))', sTitle, re.UNICODE) if m: sTitle = sTitle.replace(m.group(1), '') sa = m.group(2) if len(sa) == 1: sa = '0' + sa self.__Season = sa self.addItemValues('Season', self.__Season) #supr les - #sTitle = sTitle.replace('-',' ') # A gerer dans le fichier site plutot, car il peut etre utile dans certain cas #vire doubles espaces sTitle = re.sub(' +', ' ', sTitle) sTitle = sTitle.replace('()', '').replace('[]', '').replace('- -', '-') #vire espace a la fin et les - (attention, il y a 2 tirets differents meme si invisible a l'oeil nu et un est en unicode) sTitle = re.sub(ur'[- –]+$', '', sTitle) #et en debut if sTitle.startswith(' '): sTitle = sTitle[1:] #recherche les Tags restant : () ou [] sauf tag couleur sTitle = re.sub(ur'([\(|\[](?!\/*COLOR)[^\)\(\]\[]+?[\]|\)])','[COLOR ' + self.__sDecoColor + ']\\1[/COLOR]', sTitle) #on reformate SXXEXX Titre [tag] (Annee) sTitle2 = '' if self.__Season: sTitle2 = sTitle2 + 'S' + self.__Season if self.__Episode: sTitle2 = sTitle2 + 'E' + self.__Episode if sTitle2: sTitle2 = "[COLOR %s]%s[/COLOR] " % (self.__sDecoColor, sTitle2) sTitle2 = sTitle2 + sTitle if self.__Year: sTitle2 = "%s [COLOR %s](%s)[/COLOR]" % (sTitle2, self.__sDecoColor, self.__Year) #xbmc.log('>>' + sTitle2, xbmc.LOGNOTICE) #on repasse en utf-8 return sTitle2.encode('utf-8')