@@ -184,6 +184,7 @@ def get_pack_attributes(
184
184
no_techniques : bool ,
185
185
no_meditation : bool ,
186
186
all_ : bool = False ,
187
+ author : Optional [int ] = None ,
187
188
):
188
189
response = request_url (PACK_URL , id = pack_id )
189
190
attributes : dict = response ["data" ]["attributes" ]
@@ -209,11 +210,13 @@ def get_pack_attributes(
209
210
if item ["type" ] == "orderedActivities" :
210
211
if not no_meditation :
211
212
id = item ["relationships" ]["activity" ]["data" ]["id" ]
212
- download_pack_session (id , duration , _pack_name , out = out )
213
+ download_pack_session (id , duration , _pack_name , out = out , author = author )
213
214
elif item ["type" ] == "orderedTechniques" :
214
215
if not no_techniques :
215
216
id = item ["relationships" ]["technique" ]["data" ]["id" ]
216
- download_pack_techniques (id , pack_name = _pack_name , out = out )
217
+ download_pack_techniques (
218
+ id , pack_name = _pack_name , out = out , author = author
219
+ )
217
220
218
221
219
222
def get_signed_url (response : dict , duration : List [int ]) -> dict :
@@ -265,8 +268,10 @@ def download_pack_session(
265
268
pack_name : Optional [str ],
266
269
out : str ,
267
270
filename_suffix = None ,
271
+ author : Optional [int ] = None ,
268
272
):
269
- response = request_url (AUDIO_URL , id = id )
273
+ params = dict (authorId = author ) if author else dict ()
274
+ response = request_url (AUDIO_URL , id = id , params = params )
270
275
271
276
signed_url = get_signed_url (response , duration = duration )
272
277
for name , direct_url in signed_url .items ():
@@ -281,8 +286,10 @@ def download_pack_techniques(
281
286
pack_name : Optional [str ] = None ,
282
287
out : str ,
283
288
filename_suffix = None ,
289
+ author : Optional [int ] = None ,
284
290
):
285
- response = request_url (TECHNIQUE_URL , id = technique_id )
291
+ params = dict (authorId = author ) if author else dict ()
292
+ response = request_url (TECHNIQUE_URL , id = technique_id , params = params )
286
293
name = response ["data" ]["attributes" ]["name" ]
287
294
if filename_suffix :
288
295
name += filename_suffix
@@ -456,6 +463,16 @@ def get_legacy_id(new_id):
456
463
" links of packs to exclude downloading. Every link should be on separate line."
457
464
),
458
465
)
466
+ @click .option (
467
+ "--author" ,
468
+ "-a" ,
469
+ type = int ,
470
+ default = 0 ,
471
+ help = (
472
+ "Use to choose the author/narrator that you'd like to download the files of."
473
+ "NOTE: If the author ID is not found, the default will download."
474
+ ),
475
+ )
459
476
@shared_cmd (COMMON_CMD )
460
477
@shared_cmd (URL_GROUP_CMD )
461
478
def pack (
@@ -467,6 +484,7 @@ def pack(
467
484
url : str ,
468
485
all_ : bool ,
469
486
exclude : str ,
487
+ author : int ,
470
488
):
471
489
"""
472
490
Download headspace packs with techniques videos.
@@ -489,6 +507,7 @@ def pack(
489
507
out = out ,
490
508
no_meditation = no_meditation ,
491
509
no_techniques = no_techniques ,
510
+ author = author ,
492
511
)
493
512
else :
494
513
excluded = []
@@ -638,3 +657,6 @@ def login():
638
657
639
658
640
659
session .close ()
660
+
661
+ if __name__ == "__main__" :
662
+ cli ()
0 commit comments