Skip to content

Commit ddd54ba

Browse files
Merge pull request #32 from jasondilworth56/main
Allow input of an author ID to download specific files.
2 parents cdd08e1 + 5f77c4f commit ddd54ba

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

Diff for: .gitignore

+4-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@
1313

1414
/pyheadspace/test.html
1515
/venv/
16-
.idea
16+
.idea
17+
18+
.env
19+
launch.json

Diff for: pyheadspace/__main__.py

+26-4
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def get_pack_attributes(
184184
no_techniques: bool,
185185
no_meditation: bool,
186186
all_: bool = False,
187+
author: Optional[int] = None,
187188
):
188189
response = request_url(PACK_URL, id=pack_id)
189190
attributes: dict = response["data"]["attributes"]
@@ -209,11 +210,13 @@ def get_pack_attributes(
209210
if item["type"] == "orderedActivities":
210211
if not no_meditation:
211212
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)
213214
elif item["type"] == "orderedTechniques":
214215
if not no_techniques:
215216
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+
)
217220

218221

219222
def get_signed_url(response: dict, duration: List[int]) -> dict:
@@ -265,8 +268,10 @@ def download_pack_session(
265268
pack_name: Optional[str],
266269
out: str,
267270
filename_suffix=None,
271+
author: Optional[int] = None,
268272
):
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)
270275

271276
signed_url = get_signed_url(response, duration=duration)
272277
for name, direct_url in signed_url.items():
@@ -281,8 +286,10 @@ def download_pack_techniques(
281286
pack_name: Optional[str] = None,
282287
out: str,
283288
filename_suffix=None,
289+
author: Optional[int] = None,
284290
):
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)
286293
name = response["data"]["attributes"]["name"]
287294
if filename_suffix:
288295
name += filename_suffix
@@ -456,6 +463,16 @@ def get_legacy_id(new_id):
456463
" links of packs to exclude downloading. Every link should be on separate line."
457464
),
458465
)
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+
)
459476
@shared_cmd(COMMON_CMD)
460477
@shared_cmd(URL_GROUP_CMD)
461478
def pack(
@@ -467,6 +484,7 @@ def pack(
467484
url: str,
468485
all_: bool,
469486
exclude: str,
487+
author: int,
470488
):
471489
"""
472490
Download headspace packs with techniques videos.
@@ -489,6 +507,7 @@ def pack(
489507
out=out,
490508
no_meditation=no_meditation,
491509
no_techniques=no_techniques,
510+
author=author,
492511
)
493512
else:
494513
excluded = []
@@ -638,3 +657,6 @@ def login():
638657

639658

640659
session.close()
660+
661+
if __name__ == "__main__":
662+
cli()

0 commit comments

Comments
 (0)