-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathdebug_api.py
More file actions
67 lines (60 loc) · 2.08 KB
/
Copy pathdebug_api.py
File metadata and controls
67 lines (60 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import sys
sys.path.insert(0, '.')
from app.infra.clients.media_server_client import media_api
import datetime
# 获取 admin_id
users = media_api.get('/Users', timeout=5).json()
admin_id = None
for u in users:
if u.get('Policy', {}).get('IsAdministrator'):
admin_id = u['Id']
break
if not admin_id and users:
admin_id = users[0]['Id']
print(f'Admin ID: {admin_id}')
# 获取媒体库
lib_res = media_api.get(f'/Users/{admin_id}/Views', timeout=10).json()
libraries = lib_res.get('Items', [])
print(f'媒体库数量: {len(libraries)}')
for lib in libraries:
print(f' - {lib.get("Name")}: {lib.get("Id")}')
# 测试第一个媒体库的分页查询
if libraries:
lib = libraries[0]
lib_id = lib.get('Id')
# 第一页
params = {
'ParentId': lib_id,
'SortBy': 'DateCreated',
'SortOrder': 'Descending',
'IncludeItemTypes': 'Movie,Series,Episode',
'Recursive': 'true',
'StartIndex': 0,
'Limit': 500,
'Fields': 'DateCreated'
}
res = media_api.get(f'/Users/{admin_id}/Items', params=params, timeout=20).json()
items = res.get('Items', [])
total = res.get('TotalRecordCount', 0)
print(f'\n媒体库 "{lib.get("Name")}" :')
print(f' TotalRecordCount: {total}')
print(f' 返回条数: {len(items)}')
if items:
print(f' 第一条: {items[0].get("Name")} - {items[0].get("DateCreated")}')
print(f' 最后一条: {items[-1].get("Name")} - {items[-1].get("DateCreated")}')
# 测试全局查询(无 ParentId)
print('\n=== 测试全局查询(无 ParentId)===')
params_global = {
'SortBy': 'DateCreated',
'SortOrder': 'Descending',
'IncludeItemTypes': 'Movie,Series,Episode',
'Recursive': 'true',
'StartIndex': 0,
'Limit': 500,
'Fields': 'DateCreated'
}
res_global = media_api.get(f'/Users/{admin_id}/Items', params=params_global, timeout=20).json()
items_global = res_global.get('Items', [])
total_global = res_global.get('TotalRecordCount', 0)
print(f' TotalRecordCount: {total_global}')
print(f' 返回条数: {len(items_global)}')