Example #1
0
    def __init__(self, bot, message):
        self.bot = bot
        text = message.text
        chat_id = message.chat_id
        user_id = message.from_user.id

        if text == '':
            self.bot.sendMessage(chat_id, telegram.Emoji.NEUTRAL_FACE)
            return

        self.bot.sendMessage(chat_id, "Searching for '{}'...".format(text))

        logging.debug('searching for: {}'.format(text))
        # 'Typing...'
        self.bot.sendChatAction(chat_id, telegram.ChatAction.TYPING)

        # find the film
        try:
            film = Subscene().search(text)
        except Exception as error:
            logging.error('error while searching: {}'.format(error))
            self.bot.sendMessage(chat_id, 'فیلم پیدا نشد.')
            return

        # if no film found, give up
        if film is None:
            self.bot.sendMessage(chat_id, 'فیلم پیدا نشد.')
            return

        # if film has a cover, send it
        # if film.cover != '':
        #  self.send_film_cover(chat_id, film.cover)

        # get user language
        language = DataBase.get_user_language(user_id)

        if language == '':
            bot.sendMessage(chat_id, 'Please set your language first: /lang')
            return

        if language is None:
            bot.sendMessage(chat_id, 'There was an error. come back later.')
            return

        # choose a subtitle
        subtitle_link = ''
        for subtitle in film.subtitles:
            if language in subtitle.language:
                subtitle_link = subtitle.get_zip_link()
                break

        # if no suitable subtitle found, give up
        if subtitle_link is '':
            logging.debug('no Persian subtitle found for {}'.format(text))
            self.bot.sendMessage(chat_id, 'این فیلم زیرنویس پارسی ندارد.')
        else:
            self.send_subtitle(chat_id, subtitle_link)
Example #2
0
class EasySub(object):
	def __init__(self):
		super(EasySub, self).__init__()
		self._file_parser = FileParser()
		self._subscene = Subscene()

	def _get_search_term(self, file):
		return u' '.join(self._file_parser.parse_filename(file.name))
		
	def process_file(self, file):
		search_term = self._get_search_term(file)
		try:
			results = self._subscene.search(search_term)
		except Exception, e:
			pass
		else:
Example #3
0
class EasySub(object):
    def __init__(self):
        super(EasySub, self).__init__()
        self._file_parser = FileParser()
        self._subscene = Subscene()

    def _get_search_term(self, file):
        return u' '.join(self._file_parser.parse_filename(file.name))

    def process_file(self, file):
        search_term = self._get_search_term(file)
        try:
            results = self._subscene.search(search_term)
        except Exception, e:
            pass
        else:
Example #4
0
	def __init__(self):
		super(EasySub, self).__init__()
		self._file_parser = FileParser()
		self._subscene = Subscene()
Example #5
0
 def __init__(self):
     super(EasySub, self).__init__()
     self._file_parser = FileParser()
     self._subscene = Subscene()