def ajax_listvideo_do(rd, data, user): order = getDefaultJSON(data, 'order', 'latest') additional_constraint = getDefaultJSON(data, 'additional_constraint', '') hide_placeholder = getDefaultJSON(data, 'hide_placeholder', True) lang = getDefaultJSON(data, 'lang', 'CHS') if order not in ['latest', 'oldest', 'video_latest', 'video_oldest']: raise AttributeError() videos, video_count, related_tags, related_tags_popularity = listVideo( data.page - 1, data.page_size, user, order, hide_placeholder=hide_placeholder, user_language=lang, additional_constraint=additional_constraint) tag_category_map = getTagCategoryMap(related_tags) ret = makeResponseSuccess({ "videos": videos, "count": video_count, "page_count": (video_count - 1) // data.page_size + 1, "tags": tag_category_map, "tag_pops": related_tags_popularity }) return "json", ret
def ajax_postvideo_batch_do(rd, user, data): dst_copy = getDefaultJSON(data, 'copy', '') dst_playlist = getDefaultJSON(data, 'pid', '') dst_rank = getDefaultJSON(data, 'rank', -1) as_copies = getDefaultJSON(data, 'as_copies', False) task_ids = postVideoBatch(user, data.videos, data.tags, dst_copy, dst_playlist, dst_rank, as_copies) return "json", makeResponseSuccess({"task_ids": task_ids})
def ajax_videos_edittags(rd, user, data): user_lang = getDefaultJSON(data, 'user_language', 'ENG') edit_behaviour = getDefaultJSON(data, 'edit_behaviour', 'replace') not_found_behaviour = getDefaultJSON(data, 'not_found_behaviour', 'ignore') new_tagids = editVideoTags(data.video_id, data.tags, user, edit_behaviour, not_found_behaviour, user_lang) return "json", makeResponseSuccess({'tagids': new_tagids})
def ajax_listvideo_do(rd, data, user): start = time.time() order = getDefaultJSON(data, 'order', 'latest') additional_constraint = getDefaultJSON(data, 'additional_constraint', '') hide_placeholder = getDefaultJSON(data, 'hide_placeholder', True) lang = getDefaultJSON(data, 'lang', 'CHS') human_readable_tag = getDefaultJSON(data, 'human_readable_tag', False) offset, limit = getOffsetLimitJSON(data) videos, video_count, related_tags, related_tags_popularity, query_obj, pop_tagid_map, exStats1, exStats2 = listVideo( offset, limit, user, order, hide_placeholder=hide_placeholder, user_language=lang, additional_constraint=additional_constraint, human_readable_tag=human_readable_tag) tag_category_map = getTagCategoryMap(related_tags) end = time.time() ret = makeResponseSuccess({ "videos": videos, "count": video_count, "page_count": (video_count - 1) // limit + 1, "tags": tag_category_map, "tagid_popmap": pop_tagid_map, "tag_pops": related_tags_popularity, 'time_used_ms': int((end - start) * 1000), "query_obj": query_obj #, # "ex_stats_1": exStats1, # "ex_stats_2": exStats2 }) return "json", ret
def ajax_subs_list_do(rd, data, user): order = getDefaultJSON(data, 'order', 'video_latest') hide_placeholder = getDefaultJSON(data, 'hide_placeholder', True) lang = getDefaultJSON(data, 'lang', 'CHS') visible = getDefaultJSON(data, 'visible', ['']) additional_constraint = getDefaultJSON(data, 'additional_constraint', '') if order not in ['latest', 'oldest', 'video_latest', 'video_oldest', 'last_modified'] : raise AttributeError() offset, limit = getOffsetLimitJSON(data) videos, sub_objs, tags, tagids, count = listSubscriptedItems( user, offset, limit, lang, hide_placeholder, order, visible, additional_constraint ) return "json", makeResponseSuccess({ 'videos': videos, 'objs': sub_objs, 'related_tags': tags, 'related_tagids': tagids, 'total': count })
def ajax_queryvideo_do(rd, data, user): start = time.time() if len(data.query) > QueryConfig.MAX_QUERY_LENGTH: raise UserError('QUERY_TOO_LONG') order = getDefaultJSON(data, 'order', 'latest') hide_placeholder = getDefaultJSON(data, 'hide_placeholder', True) if order not in ['latest', 'oldest', 'video_latest', 'video_oldest']: raise AttributeError() videos, related_tags, video_count = listVideoQuery( user, data.query, data.page - 1, data.page_size, order, hide_placeholder=hide_placeholder) tag_category_map = getTagCategoryMap(related_tags) end = time.time() ret = makeResponseSuccess({ "videos": [i for i in videos], "count": video_count, "page_count": (video_count - 1) // data.page_size + 1, "tags": tag_category_map, 'time_used_ms': int((end - start) * 1000) }) return "json", ret
def ajax_autotag_do(rd, user, data): title = getDefaultJSON(data, 'title', '') desc = getDefaultJSON(data, 'desc', '') video_url = getDefaultJSON(data, 'url', '') user_urls = getDefaultJSON(data, 'user_urls', []) tags = inferTagsFromVideo(data.utags, title, desc, data.lang, video_url, user_urls) return "json", makeResponseSuccess({'tags': tags})
def ajax_popular_tags_do(rd, user, data): lang = getDefaultJSON(data, 'lang', 'ENG') count = getDefaultJSON(data, 'count', 20) tags, tags_popmap, tagids_popmap = getPopularTags(lang, count) return "json", makeResponseSuccess({ 'tags': tags, 'tags_popmap': tags_popmap, 'tagids_popmap': tagids_popmap })
def ajax_postvideo_do(rd, user, data): dst_copy = getDefaultJSON(data, 'copy', '') dst_playlist = getDefaultJSON(data, 'pid', '') dst_rank = getDefaultJSON(data, 'rank', -1) repost_type = getDefaultJSON(data, 'repost_type', 'repost') if repost_type not in ['official', 'official_repost', 'authorized_translation', 'authorized_repost', 'translation', 'repost', 'unknown'] : raise UserError('INCORRECT_REPOST_TYPE') task_id = postVideo(user, data.url, data.tags, dst_copy, dst_playlist, dst_rank, repost_type) return "json", makeResponseSuccess({"task_id": task_id})
def ajax_post_list_failed_do(rd, user, data): page_size = getDefaultJSON(data, 'page_size', 20) page = getDefaultJSON(data, 'page', 1) - 1 result, counts = listFailedPosts(user, page, page_size) return "json", makeResponseSuccess({ "posts": result, "count": counts, "page": page + 1, "page_count": (counts - 1) // page_size + 1, })
def ajax_user_list_users(rd, user, data): offset, limit = getOffsetLimitJSON(data) query = getDefaultJSON(data, 'query', '') order = getDefaultJSON(data, 'order', 'latest') users, count = listUsers(user, offset, limit, query, order) ret = makeResponseSuccess({ "users": users, "count": count, "page_count": (count - 1) // limit + 1 }) return "json", ret
def ajax_lists_new_do(rd, user, data): private = getDefaultJSON(data, 'private', False) privateEdit = getDefaultJSON(data, 'privateEdit', True) if hasattr(data, 'pid') and data.pid: updatePlaylistInfo(data.pid, data.title, data.desc, data.cover, user, private, privateEdit) return "json", makeResponseSuccess({"pid": data.pid}) else: pid = createPlaylist(data.title, data.desc, data.cover, user, private, privateEdit) return "json", makeResponseSuccess({"pid": str(pid)})
def ajax_query_tags_regex(rd, user, data): order = getDefaultJSON(data, 'order', 'latest') category = getDefaultJSON(data, 'category', '') offset, limit = getOffsetLimitJSON(data) tags, tag_count = queryTagsRegex(data.query, category, offset, limit, order, user) ret = makeResponseSuccess({ "tags": tags, "count": tag_count, "page_count": (tag_count - 1) // limit + 1 }) return "json", ret
def ajax_user_list_users(rd, user, data): page_idx = getDefaultJSON(data, 'page', 1) - 1 page_size = getDefaultJSON(data, 'page_size', 20) query = getDefaultJSON(data, 'query', '') order = getDefaultJSON(data, 'order', 'latest') users, count = listUsers(user, page_idx, page_size, query, order) ret = makeResponseSuccess({ "users": users, "count": count, "page_count": (count - 1) // page_size + 1 }) return "json", ret
def ajax_get_related_tags_do(rd, user, data): max_count = getDefaultJSON(data, 'max_count', 10) exclude = getDefaultJSON(data, 'exclude', []) start = time.time() ret = getRelatedTagsExperimental('CHS', data.tags, exclude, max_count) end = time.time() return "json", makeResponseSuccess({ 'tags': ret, 'time_used_ms': int((end - start) * 1000) })
def ajax_admin_viewlogs_aggregated_do(rd, data, user): filterOperation('viewlogs', user) order = getDefaultJSON(data, 'order', 'latest') date_from = getDefaultJSON(data, 'date_from', '') date_to = getDefaultJSON(data, 'date_to', '') page = getDefaultJSON(data, 'page', 1) - 1 page_size = getDefaultJSON(data, 'page_size', 100) if date_from: date_from = parse(date_from).astimezone(timezone.utc) if date_to: date_to = parse(date_to).astimezone(timezone.utc) ret = viewLogsAggregated(page, page_size, date_from, date_to, order) return "json", makeResponseSuccess(ret)
def ajax_lists_myplaylists_vid(rd, user, data): offset, limit = getOffsetLimitJSON(data) order = getDefaultJSON(data, 'order', 'last_modified') query = getDefaultJSON(data, 'query', '') additional_constraint = getDefaultJSON(data, 'additional_constraint', '') playlists, playlists_count = listMyPlaylistsAgainstSingleVideo( user, data.vid, offset, limit, query, additional_constraint, order) return "json", makeResponseSuccess({ "playlists": playlists, "count": playlists_count, "page_count": (playlists_count - 1) // limit + 1 })
def ajax_admin_viewlogs_do(rd, data, user): filterOperation('viewlogs', user) order = getDefaultJSON(data, 'order', 'latest') date_from = getDefaultJSON(data, 'date_from', '') date_to = getDefaultJSON(data, 'date_to', '') offset, limit = getOffsetLimitJSON(data) levels = getDefaultJSON(data, 'levels', ['SEC', 'MSG', 'WARN', 'ERR']) op = getDefaultJSON(data, 'op', '') if date_from: date_from = parse(date_from).astimezone(timezone.utc) if date_to: date_to = parse(date_to).astimezone(timezone.utc) ret = viewLogs(offset, limit, date_from, date_to, order, op, levels) return "json", makeResponseSuccess(ret)
def ajax_query_tags_wildcard(rd, user, data): order = getDefaultJSON(data, 'order', 'latest') if order not in ['latest', 'oldest', 'count', 'count_inv']: raise AttributeError() category = getDefaultJSON(data, 'category', '') offset, limit = getOffsetLimitJSON(data) tags, tag_count = queryTagsWildcard(data.query, category, offset, limit, order, user) ret = makeResponseSuccess({ "tags": tags, "count": tag_count, "page_count": (tag_count - 1) // limit + 1 }) return "json", ret
def ajax_lists_all_do(rd, user, data): page_size = getDefaultJSON(data, 'page_size', 20) page = getDefaultJSON(data, 'page', 1) - 1 order = getDefaultJSON(data, 'order', 'last_modified') playlists, playlists_count = listPlaylists(user, page, page_size, {}, order) result = [item for item in playlists] return "json", makeResponseSuccess({ "playlists": result, "count": playlists_count, "page_count": (playlists_count - 1) // page_size + 1 })
def ajax_subs_list_do(rd, data, user): order = getDefaultJSON(data, 'order', 'video_latest') hide_placeholder = getDefaultJSON(data, 'hide_placeholder', True) lang = getDefaultJSON(data, 'lang', 'CHS') if order not in ['latest', 'oldest', 'video_latest', 'video_oldest']: raise AttributeError() videos, sub_objs, tags, count = listSubscriptedItems( user, data.page - 1, data.page_size, lang, hide_placeholder, order) return "json", makeResponseSuccess({ 'videos': videos, 'objs': sub_objs, 'related_tags': tags, 'total': count })
def ajax_lists_myplaylists_vid(rd, user, data): page_size = getDefaultJSON(data, 'page_size', 20) page = getDefaultJSON(data, 'page', 1) - 1 order = getDefaultJSON(data, 'order', 'last_modified') query = getDefaultJSON(data, 'query', '') query_obj = _buildQueryObj(query) playlists, playlists_count = listMyPlaylistsAgainstSingleVideo( user, data.vid, page, page_size, query_obj, order) return "json", makeResponseSuccess({ "playlists": playlists, "count": playlists_count, "page_count": (playlists_count - 1) // page_size + 1 })
def ajax_lists_search_do(rd, user, data): offset, limit = getOffsetLimitJSON(data) order = getDefaultJSON(data, 'order', 'last_modified') query = getDefaultJSON(data, 'query', '') additional_constraint = getDefaultJSON(data, 'additional_constraint', '') assert isinstance(query, str) playlists, playlists_count = listPlaylists(user, offset, limit, query, order, 'text', additional_constraint) return "json", makeResponseSuccess({ "playlists": playlists, "count": playlists_count, "page_count": (playlists_count - 1) // limit + 1 })
def ajax_lists_get_playlist_do(rd, user, data): offset, limit = getOffsetLimitJSON(data) lang = getDefaultJSON(data, 'lang', 'CHS') playlist = getPlaylist(data.pid, lang) if playlist["item"]["private"] and str( playlist["meta"]["created_by"]) != str( user['_id']) and user['access_control']['status'] != 'admin': abort(404) playlist_editable = False playlist_owner = False if user: videos, video_count, playlist_editable, playlist_owner = listPlaylistVideosWithAuthorizationInfo( data.pid, offset, limit, user) else: videos, video_count = listPlaylistVideos(data.pid, offset, limit, user) tags = playlist_db.retrive_item_with_tag_category_map( playlist['_id'], lang) return "json", makeResponseSuccess({ "editable": playlist_editable, "owner": playlist_owner, "playlist": playlist, "tags": tags, "videos": [item for item in videos], "count": video_count, "page_count": (video_count - 1) // limit + 1 })
def ajax_lists_search_do(rd, user, data): page_size = getDefaultJSON(data, 'page_size', 20) page = getDefaultJSON(data, 'page', 1) - 1 order = getDefaultJSON(data, 'order', 'last_modified') query = getDefaultJSON(data, 'query', '') query_obj = _buildQueryObj(query) playlists, playlists_count = listPlaylists(user, page, page_size, query_obj, order) result = [item for item in playlists] return "json", makeResponseSuccess({ "playlists": result, "count": playlists_count, "page_count": (playlists_count - 1) // page_size + 1 })
def ajax_listmyvideo_do(rd, data, user): order = getDefaultJSON(data, 'order', 'latest') lang = getDefaultJSON(data, 'lang', 'CHS') offset, limit = getOffsetLimitJSON(data) videos, video_count = listMyVideo(offset, limit, user, order, user_language=lang) ret = makeResponseSuccess({ "videos": videos, "count": video_count, "tags": getCommonTagsWithCount(lang, videos), "page_count": (video_count - 1) // limit + 1, }) return "json", ret
def ajax_lists_create_from_existing_playlists(rd, user, data): use_autotag = getDefaultJSON(data, 'use_autotag', False) new_playlist_id, task_id = createPlaylistFromExistingPlaylist( data.url, user, data.lang, use_autotag=use_autotag) return "json", makeResponseSuccess({ 'pid': str(new_playlist_id), 'task_id': task_id })
def ajax_folder_view(rd, data, user) : if user is None : return "json", makeResponseSuccess(listFolder(user, data.uid, data.path)) else : uid = getDefaultJSON(data, 'uid', user['_id']) if uid == 'me' : uid = user['_id'] return "json", makeResponseSuccess(listFolder(user, uid, data.path))
def ajax_subs_list_randomized_do(rd, data, user): lang = getDefaultJSON(data, 'lang', 'CHS') visible = getDefaultJSON(data, 'visible', ['']) offset, limit = getOffsetLimitJSON(data) additional_constraint = getDefaultJSON(data, 'additional_constraint', '') videos, sub_objs, tags, tagids = listSubscriptedItemsRandomized( user, limit, lang, visible, additional_constraint ) return "json", makeResponseSuccess({ 'videos': videos, 'objs': sub_objs, 'related_tags': tags, 'related_tagids': tagids })
def ajax_listvideo_randomized_do(rd, data, user): query = getDefaultJSON(data, 'query', '') if len(query) > QueryConfig.MAX_QUERY_LENGTH: raise UserError('QUERY_TOO_LONG') additional_constraint = getDefaultJSON(data, 'additional_constraint', '') human_readable_tag = getDefaultJSON(data, 'human_readable_tag', False) qtype = getDefaultJSON(data, 'qtype', 'tag') lang = getDefaultJSON(data, 'lang', 'CHS') _, limit = getOffsetLimitJSON(data) videos, related_tags, related_tagids = listVideoRandimzied( user, limit, query, lang, qtype, additional_constraint, human_readable_tag) tag_category_map = getTagCategoryMap(related_tags) ret = makeResponseSuccess({ "videos": videos, "tags": tag_category_map, "related_tagids": related_tagids }) return "json", ret