Skip to content
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

Support new format for Expires url parameter in CDN Manager #736

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lib/src/main/java/xyz/gianlu/librespot/audio/cdn/CdnManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,10 @@ void setUrl(@NotNull HttpUrl url) {

if (fileId != null) {
String tokenStr = url.queryParameter("__token__");
// Existing format: https://aud...bcf?__token__=exp=1697904087~hmac=80...99
String expiresStr = url.queryParameter("Expires");
// New https://aud...bcf?Expires=1697904086~FullPath~hmac=fT...Q=

if (tokenStr != null && !tokenStr.isEmpty()) {
Long expireAt = null;
String[] split = tokenStr.split("~");
Expand All @@ -178,6 +182,18 @@ void setUrl(@NotNull HttpUrl url) {
}

expiration = expireAt * 1000;

} else if ( expiresStr != null && !expiresStr.isEmpty()) {

Choose a reason for hiding this comment

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

You can never get expiresAt==null. But you can get a NumberFormatException.
I would replace this else if-block with

                } else if (expiresStr != null && !expiresStr.isEmpty()) {
                    String expiresStrVal = expiresStr.split("~")[0];
                    try {
                        expiration = Long.parseLong(expiresStrVal) * 1000;
                        LOGGER.info("Expires-based expiration {} ms", expiration);
                    } catch (NumberFormatException e) {
                        expiration = -1;
                        LOGGER.warn("Invalid Expires param in CDN url: {}", url);
                    }

                 } else {

Long expireAt = null;
String expiresStrVal = expiresStr.split("~")[0];
expireAt = Long.parseLong(expiresStrVal);
if (expireAt == null) {
expiration = -1;
LOGGER.warn("Invalid Expires param in CDN url: " + url);
}

expiration = expireAt * 1000;

} else {
String param = url.queryParameterName(0);
int i = param.indexOf('_');
Expand Down