def login(user_info): """ user login :param user_info: dict user info :return: dict user info """ user_info = get_user(user_info.get('name'), user_info.get('password')) if user_info is not None: user_info.pop("_id") log('info', 'user login: %s' % user_info.get('name')) return user_info return None
def update_password(user_info): """ update password :param user_info: :return: """ collection = get_collection("user") if user_info.get('password') and user_info.get('password') != '': user_info['password'] = get_password(user_info['name'], user_info['password']) log('info', 'password saved') return update(user_info)
def run_manual_scan(data, user_info): plugin = data.get("selectPlugin") result = [] plugin_model = import_string('app.plugins.%s.main' % plugin) plugin_config = import_string('app.plugins.%s.config' % plugin) user_setting = get_user_plugin_setting(plugin_config.get_info('en').get('name'), {'name': user_info.get('name')}) meta_data = {} try: meta_data = plugin_model.search(data, user_setting) except Exception as ex: log('error', repr(ex), plugin) result.extend(trans_to_dict(meta_data)) # save_pic_to_db(result) return result
def run_scan(data): result = [] user_info = get_user_by_token(data.get('token')) details = libraries_detail(user_info.get("name"), data.get("video_librarySectionTitle")) if details and details.get('libraries') and details.get('active'): for plugin in details.get('active'): plugin_model = import_string('app.plugins.%s.main' % plugin) plugin_config = import_string('app.plugins.%s.config' % plugin) user_setting = get_user_plugin_setting( plugin_config.get_info('en').get('name'), {'name': user_info.get('name')}) meta_data_list = [] try: # choice search method by node status node_status = get_node_info() # master role if node_status.get('role') == 'master': meta_data_list = run_master_scan(plugin, user_setting, data) # master&slave role if node_status.get('role') == 'master&slave': meta_data_list = run_master_slave_scan( plugin, user_setting, data) # slave roles if node_status.get('role') == 'slave': meta_data_list = trans_to_dict( plugin_model.search(data, user_setting)) meta_data_list = set_or_get_cache_id( meta_data_list, plugin_config.get_info('en').get('name')) except Exception as ex: log('error', repr(ex), plugin) result.extend(meta_data_list) save_pic_to_db(result) if data.get('autoFlag'): return result return result
def search(meta_info, user_setting): plugin_name = config.get_info('en').get('name') meta_data_list = [] video_title = meta_info.get('video_title') part_file = meta_info.get('part_file') movie_type = '' title_style = '' log('info', 'title:%s' % video_title, plugin_name) # code is the formatted media name which is used to check if it is already in cache code = 'formatted file name' cache_data = check_cache(code, get_info('en').get('name')) if cache_data: meta_data_list.append(cache_data) else: # search for meta data from internet meta_data = MetaData() meta_data_list.append(meta_data) return meta_data_list
def scheduler_check_modules_update(): """ scheduler task to check modules update and send message to user :return: """ user_setting = get_all_modules_setting_enable() course_modules_cache = {} log('info', 'scheduler task check modules update start') for modules_setting in user_setting: log('info', 'check modules update for user: %s' % modules_setting.get('user')) try: db_user = get_user_by_name(modules_setting.get('user')) check_result = check_canvas_setting(db_user) if not check_result.get('state'): raise Exception(check_result.get('message')) new_things = {} course_json = get_user_modules_from_canvas( modules_setting.get('user')) course_dict = transform_modules_json_to_dict(course_json) course_keys = list(course_dict.keys()) for course_id in course_keys: if course_modules_cache.get(course_id): course_canvas = course_modules_cache.get(course_id) else: course_canvas = course_dict.get(course_id) course_modules_cache.update( {course_id: course_dict.get(course_id)}) course_history = get_history_by_course_id(course_id) if not course_history: continue # check course modules modules_canvas_key = course_canvas.keys() for modules_canvas_id in modules_canvas_key: course_history.update({}) if not modules_canvas_id == 'course_id' and not modules_canvas_id == 'name': # check if modules is new modules_history = course_history.get(modules_canvas_id) modules_canvas = course_canvas.get(modules_canvas_id) item_keys = modules_canvas.keys() for item_id in item_keys: item_canvas = modules_canvas.get(item_id) if not item_id == 'name': if modules_history: item_history = modules_history.get(item_id) if item_canvas.get( 'type' ) == 'File' or item_canvas.get( 'type') == 'Page': if item_history: # check if item is updated canvas_update_time = datetime.datetime.strptime( item_canvas.get('update_at'), "%Y-%m-%dT%H:%M:%SZ") history_update_time = datetime.datetime.strptime( item_history.get('update_at'), "%Y-%m-%dT%H:%M:%SZ") if canvas_update_time > history_update_time: update_new_item_into_dict( course_canvas, modules_canvas, item_canvas, new_things) else: update_new_item_into_dict( course_canvas, modules_canvas, item_canvas, new_things) else: update_new_item_into_dict( course_canvas, modules_canvas, item_canvas, new_things) if not new_things == {}: notify_user_update(modules_setting.get('user'), new_things) log( 'info', 'updated modules for user: %s, updated course counts: %s' % (modules_setting.get('user'), len(new_things))) except Exception as e: log( 'info', 'check modules update fail for user: %s, error: %s' % (modules_setting.get('user'), e)) log('info', 'check modules update finish, clean history and save new cache') clear_history() save_modules_histories(list(course_modules_cache.values()))
def search(meta_info, user_setting): plugin_name = config.get_info('en').get('name') meta_data_list = [] video_title = meta_info.get('video_title') part_file = meta_info.get('part_file') movie_type = '' title_style = '' log('info', 'title:%s' % video_title, plugin_name) if not user_setting.get('japan_title_style') == '': title_style = user_setting.get('japan_title_style') if user_setting.get('japan_censored_directory_mark') in part_file: movie_type = 'censored' elif user_setting.get('japan_uncensored_directory_mark') in part_file: movie_type = 'uncensored' elif user_setting.get('japan_animation_directory_mark') in part_file: movie_type = 'animation' elif user_setting.get('europe_directory_mark') in part_file: movie_type = 'europe' if movie_type != '' or not spider_config.SOURCE_LIST[movie_type]: for template in spider_config.SOURCE_LIST[movie_type]: # 循环模板列表 code_list = [] re_list = re.finditer(template['pattern'], video_title, re.IGNORECASE) for item in re_list: code_list.append(item.group()) while '' in re_list: re_list.remove('') if len(code_list) == 0: continue # 对正则匹配结果进行搜索 for code in code_list: web_list = template['web_list'] code = template['formatter'].format(code) cache_data = check_cache(code, get_info('en').get('name')) if cache_data: meta_data_list.extend(cache_data) else: for webSiteClass in web_list: web_site = webSiteClass() items = web_site.search_with_img(code) for item in items: item['code'] = code item['original_title'] = item['title'] meta_data_list.extend(items) # 标题样式设定 for dict_item in meta_data_list: try: if title_style == 'number': dict_item['title'] = dict_item['number'] elif title_style == 'numbertitle': dict_item['title'] = '%s %s' % (dict_item['number'], dict_item['original_title']) except Exception as ex: log('error', ex, plugin_name) continue return meta_data_list
def search(meta_info, user_setting): score = MATCH_SCORE plugin_name = config.get_info('en').get('name') meta_data_list = [] if meta_info.get('media_type') == 'album': if meta_info.get('name'): file_name = meta_info.get('name') score = MATCH_ALBUM else: file_name = clear_file_name(meta_info.get('file_name')) elif meta_info.get('media_type') == 'artist': if meta_info.get('file_name'): file_name = clear_file_name(meta_info.get('file_name')) else: file_name = '' score = MATCH_ARTIST else: return meta_data_list log('info', 'title:%s' % file_name, plugin_name) code = get_code(file_name, meta_info) result = None cache_data = check_cache(code, get_info('en').get('name')) if cache_data: return cache_data else: # search for meta data from internet results = search_song_by_code(code) sort_result(results, code) highest_result = get_highest_result(results) if not highest_result: return meta_data_list if highest_result.get('score') >= score: result = highest_result if not result: return meta_data_list get_artist_info(result) get_album_info(result) get_hot_comment(result) meta_data = MetaData() # Album album = Album() album.title = result.get('album').get('name') if result.get('album').get('description'): album.summary = result.get('album').get('description') album.studio = result.get('album').get('company') album.tags = result.get('album').get('tags') album.collections = result.get('album').get('subType') album.poster = get_picture_base64(result.get('album').get('picUrl')) album.originally_available_at = datetime.datetime.fromtimestamp( result.get('album').get('publishTime') / 1000).strftime('%Y-%m-%d') for review in result['reviews'].get('topComments'): album.reviews.append( review.get('user').get('nickname') + ': ' + review.get('content')) for review in result['reviews'].get('hotComments'): album.reviews.append( review.get('user').get('nickname') + ': ' + review.get('content')) if user_setting.get('hotComment'): album.summary += '\n 网易云热门评论: ' for review in album.reviews: album.summary += '\n ' + review.replace('\n', '') meta_data.album = album # Artist for result_artist in result.get('artists'): artist = Artist() artist.poster = get_picture_base64(result_artist.get('cover')) artist.art = get_picture_base64(result_artist.get('cover')) title = result_artist.get('name') if title == 'Various Artists' or title == '[Unknown Artist]': title = '未知艺术家' artist.title = title if result_artist.get('identifyTag'): artist.tags = ','.join(result_artist.get('identifyTag')) artist.summary = '' if result_artist.get('briefDesc'): artist.summary = result_artist.get('briefDesc') if result_artist.get('rank'): rank = result_artist.get('rank') rank_type = ['', '华语', '欧美', '韩国', '日本'] rank_string = '\n歌手排行:' + str( rank_type[rank.get('type')]) + '地区:' + str(rank.get('rank')) artist.summary += rank_string if result_artist.get('albumSize'): artist.summary += '\n歌手专辑数:' + str(result_artist.get('albumSize')) if result_artist.get('musicSize'): artist.summary += '\n歌手音乐数:' + str(result_artist.get('musicSize')) if result_artist.get('mvSize'): artist.summary += '\n歌手MV数:' + str(result_artist.get('mvSize')) meta_data.artist.append(artist) meta_data.code = code meta_data_list.append(meta_data) return meta_data_list