Skip to content

Itunes fixes #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

Keeper-of-the-Keys
Copy link
Contributor

Signed-off-by: E.S. Rosenberg a.k.a. Keeper of the Keys <es.rosenberg+github@gmail.com>
Signed-off-by: E.S. Rosenberg a.k.a. Keeper of the Keys <es.rosenberg+github@gmail.com>
@Keeper-of-the-Keys
Copy link
Contributor Author

Also all strings were migrated to f-strings

Copy link
Member

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

Signed-off-by: E.S. Rosenberg a.k.a. Keeper of the Keys <es.rosenberg+github@gmail.com>
Signed-off-by: E.S. Rosenberg a.k.a. Keeper of the Keys <es.rosenberg+github@gmail.com>
Signed-off-by: E.S. Rosenberg a.k.a. Keeper of the Keys <es.rosenberg+github@gmail.com>
Comment on lines +98 to +123
if json_data['resultCount'] > 0:
for entry in json_data['results']:
if 'feedUrl' not in entry:
continue

title = entry['collectionName']
url = entry['feedUrl']
image = entry['artworkUrl100']

yield directory.DirectoryEntry(title, url, image)
returned_res += 1

offset += json_data['resultCount']
else:
# Unlike the podverse stop condition where we detect a resultCount
# smaller than the page size for apple we can only stop when 0
# results are returned because the API seems to consistently
# return more than the page size and does this in an inconsistent
# fasion, most often returning 210 results but based on my
# observartion any number between page size and page size + 10 is
# possible.
#
# With an API that does not obey its own rules the only valid stop
# condition is no results.

break
Copy link
Member

@thp thp Jun 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be simplified to (note I removed returned_res, because it doesn't seem to be used?):

Suggested change
if json_data['resultCount'] > 0:
for entry in json_data['results']:
if 'feedUrl' not in entry:
continue
title = entry['collectionName']
url = entry['feedUrl']
image = entry['artworkUrl100']
yield directory.DirectoryEntry(title, url, image)
returned_res += 1
offset += json_data['resultCount']
else:
# Unlike the podverse stop condition where we detect a resultCount
# smaller than the page size for apple we can only stop when 0
# results are returned because the API seems to consistently
# return more than the page size and does this in an inconsistent
# fasion, most often returning 210 results but based on my
# observartion any number between page size and page size + 10 is
# possible.
#
# With an API that does not obey its own rules the only valid stop
# condition is no results.
break
if json_data['resultCount'] <= 0:
return
for entry in json_data['results']:
if 'feedUrl' not in entry:
continue
title = entry['collectionName']
url = entry['feedUrl']
image = entry['artworkUrl100']
yield directory.DirectoryEntry(title, url, image)
offset += json_data['resultCount']

Comment on lines +40 to +43
expression = (
r'https?://(podcasts|itunes)\.apple\.com/(?:[^/]*/)?'
r'podcast/.*id(?P<podcast_id>[0-9]+).*$'
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we didn't do it before, we could move those to module-level pre-compiled regular expression objects, and then just use them here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that is for the current scope, it is a good idea but figuring that out and reorganizing everything would change this into a monster PR.

Comment on lines +92 to +94
f'https://itunes.apple.com/search?media=podcast&term='
f'{urllib.parse.quote(query)}&limit={PAGE_SIZE}&offset='
f'{offset}'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it would be fine if this wasn't split into 3 lines, and just a single f-string on one line.

Copy link
Member

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Apple] No result if there are multiple podcasts and one of them doesn't contain a feedUrl
2 participants