Skip to content

Commit

Permalink
Merge pull request #32 from jasondilworth56/main
Browse files Browse the repository at this point in the history
Allow input of an author ID to download specific files.
  • Loading branch information
yashrathi-git authored Jul 26, 2024
2 parents cdd08e1 + 5f77c4f commit ddd54ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

/pyheadspace/test.html
/venv/
.idea
.idea

.env
launch.json
30 changes: 26 additions & 4 deletions pyheadspace/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ def get_pack_attributes(
no_techniques: bool,
no_meditation: bool,
all_: bool = False,
author: Optional[int] = None,
):
response = request_url(PACK_URL, id=pack_id)
attributes: dict = response["data"]["attributes"]
Expand All @@ -209,11 +210,13 @@ def get_pack_attributes(
if item["type"] == "orderedActivities":
if not no_meditation:
id = item["relationships"]["activity"]["data"]["id"]
download_pack_session(id, duration, _pack_name, out=out)
download_pack_session(id, duration, _pack_name, out=out, author=author)
elif item["type"] == "orderedTechniques":
if not no_techniques:
id = item["relationships"]["technique"]["data"]["id"]
download_pack_techniques(id, pack_name=_pack_name, out=out)
download_pack_techniques(
id, pack_name=_pack_name, out=out, author=author
)


def get_signed_url(response: dict, duration: List[int]) -> dict:
Expand Down Expand Up @@ -265,8 +268,10 @@ def download_pack_session(
pack_name: Optional[str],
out: str,
filename_suffix=None,
author: Optional[int] = None,
):
response = request_url(AUDIO_URL, id=id)
params = dict(authorId=author) if author else dict()
response = request_url(AUDIO_URL, id=id, params=params)

signed_url = get_signed_url(response, duration=duration)
for name, direct_url in signed_url.items():
Expand All @@ -281,8 +286,10 @@ def download_pack_techniques(
pack_name: Optional[str] = None,
out: str,
filename_suffix=None,
author: Optional[int] = None,
):
response = request_url(TECHNIQUE_URL, id=technique_id)
params = dict(authorId=author) if author else dict()
response = request_url(TECHNIQUE_URL, id=technique_id, params=params)
name = response["data"]["attributes"]["name"]
if filename_suffix:
name += filename_suffix
Expand Down Expand Up @@ -456,6 +463,16 @@ def get_legacy_id(new_id):
" links of packs to exclude downloading. Every link should be on separate line."
),
)
@click.option(
"--author",
"-a",
type=int,
default=0,
help=(
"Use to choose the author/narrator that you'd like to download the files of."
"NOTE: If the author ID is not found, the default will download."
),
)
@shared_cmd(COMMON_CMD)
@shared_cmd(URL_GROUP_CMD)
def pack(
Expand All @@ -467,6 +484,7 @@ def pack(
url: str,
all_: bool,
exclude: str,
author: int,
):
"""
Download headspace packs with techniques videos.
Expand All @@ -489,6 +507,7 @@ def pack(
out=out,
no_meditation=no_meditation,
no_techniques=no_techniques,
author=author,
)
else:
excluded = []
Expand Down Expand Up @@ -638,3 +657,6 @@ def login():


session.close()

if __name__ == "__main__":
cli()

0 comments on commit ddd54ba

Please sign in to comment.