-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: master
Are you sure you want to change the base?
Itunes fixes #63
Conversation
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>
Also all strings were migrated to f-strings |
There was a problem hiding this 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>
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 |
There was a problem hiding this comment.
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?):
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'] |
expression = ( | ||
r'https?://(podcasts|itunes)\.apple\.com/(?:[^/]*/)?' | ||
r'podcast/.*id(?P<podcast_id>[0-9]+).*$' | ||
) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
f'https://itunes.apple.com/search?media=podcast&term=' | ||
f'{urllib.parse.quote(query)}&limit={PAGE_SIZE}&offset=' | ||
f'{offset}' |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See comments.
feedUrl
(resolves [Apple] No result if there are multiple podcasts and one of them doesn't contain a feedUrl gpodder-sailfish#225)