1010from .visitor import Visitor
1111from .utils import range_expand
1212from .__version__ import __version__
13+ from .models import dump_model
1314
1415logger = getLogger (__name__ )
1516
@@ -51,19 +52,19 @@ def main(ctx: click.Context, **argv):
5152def search (ctx : click .Context , ** argv ):
5253 visitor : Visitor = ctx .obj .visitor
5354 search_result_list = visitor .search (argv .pop ("keyword" ))
54- logger .debug (json .dumps (search_result_list , indent = 2 , ensure_ascii = False ))
55+ logger .debug (json .dumps ([ dump_model ( item ) for item in search_result_list ] , indent = 2 , ensure_ascii = False ))
5556
5657 table = []
5758 for item in search_result_list :
58- if item [ " data_type" ] != "content" :
59+ if item . data_type != "content" :
5960 continue
60- author = item [ " author" ]
61- if item [ " subtitle" ] :
62- title = "%s: %s" % ([item [ " title" ] , item [ " subtitle" ] ])
61+ author = item . author
62+ if item . subtitle :
63+ title = "%s: %s" % ([item . title , item . subtitle ])
6364 else :
64- title = item [ " title" ]
65- desc = item [ " share_desc" ]
66- content_id = item [ "id" ]
65+ title = item . title
66+ desc = item . share_desc
67+ content_id = item . id
6768 table .append ((content_id , author , title , desc ))
6869
6970 click .echo (tabulate (table ))
@@ -78,8 +79,8 @@ def subscriptions(ctx: click.Context):
7879
7980 table = []
8081 for show in visitor .get_user_subscriptions_list ():
81- title = ": " .join ([show [ " title" ] , show [ " subtitle" ] ])
82- content_id = show [ " content_id" ]
82+ title = ": " .join ([show . title , show . subtitle ])
83+ content_id = show . content_id
8384 table .append ((content_id , title ))
8485
8586 click .echo (tabulate (table ))
@@ -94,27 +95,27 @@ def show_content(ctx: click.Context, **argv):
9495 content_id = argv .pop ("id" )
9596 logger .debug (visitor .get_content_show (content_id ))
9697 logger .debug (
97- json .dumps (visitor .get_catalog (content_id ), indent = 2 , ensure_ascii = False )
98+ json .dumps (dump_model ( visitor .get_catalog (content_id ) ), indent = 2 , ensure_ascii = False )
9899 )
99100
100101 catalog = visitor .get_catalog (content_id )
101102
102- click .echo (f"{ catalog [ ' title' ] } " )
103+ click .echo (f"{ catalog . title } " )
103104 click .echo ()
104- click .echo (f"艺人: { catalog [ ' author' ] } " )
105- click .echo (f"类型: { catalog [ ' type' ] } " )
105+ click .echo (f"艺人: { catalog . author } " )
106+ click .echo (f"类型: { catalog . type } " )
106107 click .echo ()
107108
108- for part in catalog [ " catalog" ] :
109- click .echo (f"{ part [ ' catalog_number' ] } { part [ ' catalog_title' ] } " )
109+ for part in catalog . catalog :
110+ click .echo (f"{ part . catalog_number } { part . catalog_title } " )
110111 table = []
111- for article in part [ " part" ] :
112+ for article in part . part :
112113 table .append (
113114 (
114- article [ " sort_number" ] ,
115+ article . sort_number ,
115116 # article["article_id"],
116- article [ " title" ] ,
117- article [ " duration_str" ] ,
117+ article . title ,
118+ article . duration_str ,
118119 )
119120 )
120121 click .echo (tabulate (table ))
@@ -132,7 +133,7 @@ def save_show(ctx: click.Context, **argv):
132133
133134 logger .debug (
134135 json .dumps (
135- ctx .obj .visitor .get_catalog (content_id ), indent = 2 , ensure_ascii = False
136+ dump_model ( ctx .obj .visitor .get_catalog (content_id ) ), indent = 2 , ensure_ascii = False
136137 )
137138 )
138139
@@ -166,7 +167,7 @@ def save_transcript(ctx: click.Context, **argv):
166167
167168 logger .debug (
168169 json .dumps (
169- ctx .obj .visitor .get_catalog (content_id ), indent = 2 , ensure_ascii = False
170+ dump_model ( ctx .obj .visitor .get_catalog (content_id ) ), indent = 2 , ensure_ascii = False
170171 )
171172 )
172173
0 commit comments