Пример #1
0
    def add_serial(cls, data: CommandData, db_manager: DbManager, config):
        session = db_manager.get_session()
        serial = db_manager.add_serial(
            data.client_id, data.command_data['kinopoisk_id'],
            data.command_data['title'],data.command_data['year'],
            data.command_data['season'], data.command_data['url'],
            data.command_data['series'], session=session,
            cover_url=data.command_data['cover_url']
        )

        message_text = 'Сериал {0} сезон {1} добавлен к поиску \n {2}'.format(
            data.command_data['title'],
            data.command_data['season'],
            data.command_data['url']
        )

        messages = [
            send_message(
                ComponentType.COMMAND_HANDLER,
                {'user_id': data.client_id, 'message_text': message_text, 'choices': []}
            ),
            crawler_message(
                ComponentType.COMMAND_HANDLER,
                data.client_id,
                {
                    'media_id': serial.kinopoisk_id,
                    'media_type': MediaType.SERIALS,
                    'season': data.command_data['season']
                }
            )
        ]
        session.close()
        return messages
Пример #2
0
    def test_download_crawler(self):
        return
        film_id = 12198
        self.test_context.add_test_film(
            session=self.db.get_session(),
            client_id=self.client_id,
            kinopoisk_id=film_id,
            label='Игра',
            year=1997,
            url='https://www.kinopoisk.ru/film/12198/',
        )

        self.test_context.db.update_media_params(
            media_id=film_id,
            upd_data={'download_url': 'http://d.rutor.info/download/193221'},
            media_type=MediaType.FILMS)

        message = crawler_message(ComponentType.CRAWLER, self.client_id, {
            'media_id': film_id,
            'media_type': MediaType.FILMS
        }, ActionType.DOWNLOAD_TORRENT)

        messages = []
        jobs = self.crawler.db_handler.get_job_list(message)
        for job in jobs:
            messages = self.exec_task(job)

        self.assertTrue(
            len(messages) > 0, 'Не получен результат поиска фильма')
Пример #3
0
    def add_film(cls, data: CommandData, db_manager: DbManager, config):
        session = db_manager.get_session()
        film = db_manager.add_film(
            data.client_id,
            data.command_data['kinopoisk_id'],
            data.command_data['title'],
            data.command_data['year'],
            data.command_data['url'],
            session=session,
            cover_url=data.command_data['cover_url']
        )

        message_text = 'Фильм {0} добавлен к поиску \n {1}'.format(
            data.command_data['title'],
            data.command_data['url']
        )

        messages = [send_message(
            ComponentType.COMMAND_HANDLER,
            {
                'user_id': data.client_id, 'message_text': message_text, 'choices': []
            }
        ), crawler_message(
            ComponentType.COMMAND_HANDLER,
            data.client_id,
            {
                'media_id': film.kinopoisk_id,
                'media_type': MediaType.FILMS
            }
        )]

        session.close()
        return messages
Пример #4
0
def reglament_work(mediator: AppMediator):

    while True:
        if not mediator.is_alive():
            return
        mediator.send_message(
            crawler_message(ComponentType.MAIN_APP,
                            config.TELEGRAMM_BOT_USER_ADMIN, {},
                            ActionType.CHECK))
        # time.sleep(60*60*3)
        time.sleep(60 * 60 * 3)
Пример #5
0
    def get_callback_message(cls, cache_data, update):
        message = None
        if 'force' in cache_data.keys():
            cache_data['key_board'] = False
            message = crawler_message(ComponentType.CLIENT,
                                      update.callback_query.from_user.id,
                                      cache_data,
                                      ActionType.ADD_TORRENT_WATCHER)
        elif 'action' in cache_data.keys():
            if cache_data['action'] == 'kinopoisk':
                message = parser_message(ComponentType.CLIENT, cache_data,
                                         update.callback_query.from_user.id)
            elif cache_data['action'] == 'select_torrent':
                client_id = update.callback_query.from_user.id
                command_data = {
                    'media_id': cache_data['media_id'],
                    'media_type': cache_data['media_type'],
                }
                upd_data = {
                    'download_url': cache_data['download_url'],
                    'theam_id': cache_data['theam_id'],
                    'torrent_tracker': cache_data['torrent_tracker'],
                }

                if cache_data['media_type'].value == MediaType.SERIALS.value:
                    season = {'season': cache_data['season']}
                    command_data.update(season)

                command_data.update({
                    'upd_data':
                    upd_data,
                    'next_messages': [
                        crawler_message(ComponentType.CRAWLER, client_id,
                                        cache_data,
                                        ActionType.DOWNLOAD_TORRENT)
                    ]
                })
                message = command_message(ComponentType.CRAWLER,
                                          ClientCommands.UPDATE_MEDIA,
                                          command_data, client_id)
        return message
Пример #6
0
    def test_find_film_crawler(self):

        # film_id = 4199
        # self.test_context.add_test_film(
        #     session=self.db.get_session(),
        #     client_id=self.client_id,
        #     kinopoisk_id=film_id,
        #     label='Лучше не бывает',
        #     year=1997,
        #     url='https://www.kinopoisk.ru/film/4199/',
        # )

        film_id = 1053352
        self.test_context.add_test_film(
            session=self.db.get_session(),
            client_id=self.client_id,
            kinopoisk_id=film_id,
            label='Мальчик, который обуздал ветер',
            year=2019,
            url='https://www.kinopoisk.ru/film/1053352/',
        )

        message = crawler_message(ComponentType.CRAWLER, self.client_id, {
            'media_id': film_id,
            'media_type': MediaType.FILMS,
        }, ActionType.CHECK)

        messages = []
        jobs = self.crawler.db_handler.get_job_list(message)
        for job in jobs:
            messages += self.exec_task(job)

        self.assertTrue(
            len(messages) > 0, 'Не получен результат поиска фильма')

        upd_message = messages[0]

        upd_data_key = 'upd_data'
        dwld_url_key = 'download_url'

        self.assertTrue(
            upd_message.data.command == ClientCommands.UPDATE_MEDIA
            and upd_data_key in upd_message.data.command_data
            and dwld_url_key in upd_message.data.command_data[upd_data_key],
            'Не верный результат поиска.')

        download_url = upd_message.data.command_data[upd_data_key][
            dwld_url_key]

        self.assertFalse(download_url == '', 'Не обновился url для фильма.')
Пример #7
0
def start_torrent_watcher_message(job, data) -> MediatorMessage:

    upd_data = {'torrent_id': data['torrent_id']}
    command_data = construct_upd_data(job, upd_data)
    data = {}
    add_media_keys(job, data)
    command_data.update({
        'next_messages': [
            crawler_message(ComponentType.COMMAND_HANDLER, job.client_id, data,
                            ActionType.ADD_TORRENT_WATCHER)
        ]
    })
    return command_message(ComponentType.CRAWLER, ClientCommands.UPDATE_MEDIA,
                           command_data, job.client_id)
Пример #8
0
    def test_find_serial_crawler(self):
        return
        serial_id = 915196
        self.test_context.add_test_serial(
            session=self.db.get_session(),
            client_id=self.client_id,
            kinopoisk_id=serial_id,
            label='Очень странные дела',
            year=2016,
            season=1,
            series=8,
            url='https://www.kinopoisk.ru/film/915196/')

        message = crawler_message(ComponentType.CRAWLER, self.client_id, {
            'media_id': serial_id,
            'season': 1,
            'media_type': MediaType.SERIALS
        }, ActionType.CHECK)

        messages = []
        jobs = self.crawler.db_handler.get_job_list(message)
        for job in jobs:
            messages += self.exec_task(job)

        self.assertTrue(
            len(messages) > 0, 'Не получен результат поиска сериала')

        bot_message = messages[0]

        key = 'choices'

        ch_keys = [
            'message_text',
            'button_text',
            'call_back_data',
        ]

        self.assertTrue(
            bot_message.data.user_id == self.client_id
            and key in bot_message.data
            and bot_message.data[key]['action'] == 'select_torrent'
            and len(bot_message.data[key]['data']) > 0
            and all(ch_key in bot_message.data[key]['data'][0]
                    for ch_key in ch_keys), 'Не верный результат поиска.')
Пример #9
0
def film_success_message(data, job):

    dwld_data = {}
    add_media_keys(job, dwld_data)

    upd_data = {
        'download_url': data.url,
        'theam_id': data.theam_url,
        'torrent_tracker': data.tracker,
    }
    command_data = construct_upd_data(job, upd_data)

    command_data.update({
        'next_messages': [
            crawler_message(ComponentType.CRAWLER, job.client_id, dwld_data,
                            ActionType.DOWNLOAD_TORRENT)
        ],
    })

    return command_message(ComponentType.CRAWLER, ClientCommands.UPDATE_MEDIA,
                           command_data, job.client_id)
Пример #10
0
    def construct_messages(self, data):
        messages = []
        for torrent_data in data:
            media = self.job

            if media.media_type.value == MediaType.FILMS.value:
                message_text = 'Фильм "{0}" будет скачан, через несколько минут. \n {1}'.format(
                    media.text_query,
                    media.kinopoisk_url
                )
                status = LockingStatus.ENDED
            else:
                message_text = 'Новая серия "{0}" будет скачана, через несколько минут. \n {1}'.format(
                    media.text_query,
                    media.kinopoisk_url
                )

                if self.job.current_series == torrent_data['file_amount']:
                    return []

                if self.job.series != 0 and torrent_data['file_amount'] >= self.job.series:
                    status = LockingStatus.ENDED
                else:
                    status = LockingStatus.FIND_TORRENT

            upd_data = {
                'status': status,
                'exsists_in_plex': True,
                'current_series': 0 if media.season == '' else torrent_data['file_amount']
            }
            command_data = construct_upd_data(media, upd_data)

            send_data = {
                'choices': [],
                'message_text': message_text
            }
            add_media_keys(media, send_data)

            add_torrent_data = {
                'torrent_id': torrent_data['id'],
                'torrent_data': torrent_data['data'],
            }
            add_media_keys(media, add_torrent_data)

            messages += [
                command_message(
                    ComponentType.CRAWLER,
                    ClientCommands.UPDATE_MEDIA,
                    command_data,
                    self.job.client_id
                ),
                crawler_message(
                    ComponentType.CRAWLER,
                    media.client_id,
                    add_torrent_data,
                    ActionType.ADD_TORRENT_TO_TORRENT_CLIENT
                ),
                command_message(
                    ComponentType.CRAWLER,
                    ClientCommands.SEND_MESSAGES_BY_MEDIA,
                    send_data,
                    self.job.client_id
                )
            ]
        return messages