@@ -46,13 +46,6 @@ async def init_api(
4646 return api
4747
4848
49- def abort_if_false (ctx : click .Context , param : Any , value : Any ) -> None :
50- """Abort operation."""
51-
52- if not value :
53- ctx .abort ()
54-
55-
5649@click .group ()
5750@click .option ("--api-url" , help = "Base URL of pyLoad" )
5851@click .option ("--username" , help = "Username for pyLoad" )
@@ -111,21 +104,19 @@ async def _status() -> None:
111104 f" - Active Downloads: { stat ['active' ]} \n "
112105 f" - Items in Queue: { stat ['queue' ]} \n "
113106 f" - Finished Downloads: { stat ['total' ]} \n "
114- f" - Download Speed: { ( stat ['speed' ] * 8 ) / 1000000 } Mbit/s\n "
107+ f" - Download Speed: { round (( stat ['speed' ] * 8 ) / 1000000 , 2 ) } Mbit/s\n "
115108 f" - Free space: { round (free_space / (1024 ** 3 ), 2 )} GiB\n "
116109 f" - Reconnect: { 'Enabled' if stat ['reconnect' ] else 'Disabled' } \n "
117110 f" - Queue : { 'Paused' if stat ['pause' ] else 'Running' } \n "
118111 )
119112 except CannotConnect as e :
120- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
113+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
121114 except InvalidAuth as e :
122115 raise click .ClickException (
123- "Error: Authentication failed, verify username and password"
116+ "Authentication failed, verify username and password"
124117 ) from e
125118 except ParserError as e :
126- raise click .ClickException (
127- "Error: Unable to parse response from pyLoad"
128- ) from e
119+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
129120
130121 asyncio .run (_status ())
131122
@@ -154,21 +145,18 @@ async def _queue(pause: bool, resume: bool) -> None:
154145 await api .toggle_pause ()
155146
156147 s = await api .get_status ()
157- if s .get ("pause" ) is True :
158- click .echo ("Paused download queue." )
159- else :
160- click .echo ("Resumed download queue." )
148+ click .echo (
149+ f"{ "Paused" if s .get ("pause" ) else "Resumed" } download queue."
150+ )
161151
162152 except CannotConnect as e :
163- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
153+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
164154 except InvalidAuth as e :
165155 raise click .ClickException (
166- "Error: Authentication failed, verify username and password"
156+ "Authentication failed, verify username and password"
167157 ) from e
168158 except ParserError as e :
169- raise click .ClickException (
170- "Error: Unable to parse response from pyLoad"
171- ) from e
159+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
172160
173161 asyncio .run (_queue (pause , resume ))
174162
@@ -191,15 +179,13 @@ async def _stop_all() -> None:
191179 await api .stop_all_downloads ()
192180 click .echo ("Aborted all running downloads." )
193181 except CannotConnect as e :
194- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
182+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
195183 except InvalidAuth as e :
196184 raise click .ClickException (
197- "Error: Authentication failed, verify username and password"
185+ "Authentication failed, verify username and password"
198186 ) from e
199187 except ParserError as e :
200- raise click .ClickException (
201- "Error: Unable to parse response from pyLoad"
202- ) from e
188+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
203189
204190 asyncio .run (_stop_all ())
205191
@@ -222,15 +208,13 @@ async def _retry() -> None:
222208 await api .restart_failed ()
223209 click .echo ("Retrying failed downloads." )
224210 except CannotConnect as e :
225- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
211+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
226212 except InvalidAuth as e :
227213 raise click .ClickException (
228- "Error: Authentication failed, verify username and password"
214+ "Authentication failed, verify username and password"
229215 ) from e
230216 except ParserError as e :
231- raise click .ClickException (
232- "Error: Unable to parse response from pyLoad"
233- ) from e
217+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
234218
235219 asyncio .run (_retry ())
236220
@@ -253,15 +237,13 @@ async def _delete_finished() -> None:
253237 await api .delete_finished ()
254238 click .echo ("Deleted finished files and packages." )
255239 except CannotConnect as e :
256- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
240+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
257241 except InvalidAuth as e :
258242 raise click .ClickException (
259- "Error: Authentication failed, verify username and password"
243+ "Authentication failed, verify username and password"
260244 ) from e
261245 except ParserError as e :
262- raise click .ClickException (
263- "Error: Unable to parse response from pyLoad"
264- ) from e
246+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
265247
266248 asyncio .run (_delete_finished ())
267249
@@ -284,15 +266,13 @@ async def _restart() -> None:
284266 await api .restart ()
285267 click .echo ("Restarting pyLoad..." )
286268 except CannotConnect as e :
287- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
269+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
288270 except InvalidAuth as e :
289271 raise click .ClickException (
290- "Error: Authentication failed, verify username and password"
272+ "Authentication failed, verify username and password"
291273 ) from e
292274 except ParserError as e :
293- raise click .ClickException (
294- "Error: Unable to parse response from pyLoad"
295- ) from e
275+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
296276
297277 asyncio .run (_restart ())
298278
@@ -318,18 +298,12 @@ async def _toggle_reconnect() -> None:
318298 f"{ "Enabled" if s .get ("reconnect" ) else "Disabled" } auto-reconnect"
319299 )
320300 except CannotConnect as e :
321- raise click .ClickException ("Error: Unable to connect to pyLoad" ) from e
301+ raise click .ClickException ("Unable to connect to pyLoad" ) from e
322302 except InvalidAuth as e :
323303 raise click .ClickException (
324- "Error: Authentication failed, verify username and password"
304+ "Authentication failed, verify username and password"
325305 ) from e
326306 except ParserError as e :
327- raise click .ClickException (
328- "Error: Unable to parse response from pyLoad"
329- ) from e
307+ raise click .ClickException ("Unable to parse response from pyLoad" ) from e
330308
331309 asyncio .run (_toggle_reconnect ())
332-
333-
334- if __name__ == "__main__" :
335- cli ()
0 commit comments