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

Add case for new CDN expiry format #555

Merged
merged 1 commit into from
Nov 12, 2024
Merged
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
12 changes: 9 additions & 3 deletions psst-core/src/cdn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,16 +145,22 @@ fn parse_total_content_length(response: &ureq::Response) -> u64 {
/// 1. `exp` field after `__token__`:
/// .../...a35817ca410?__token__=exp=1629466995~hmac=df348...
/// ^========^
/// 2. or at the beginning of the first query parameter:
/// 2. `verify` parameter (spotifycdn.com):
/// .../...a23b4?verify=1731523536-a5v83c3W...
/// ^========^
/// 3. or at the beginning of the first query parameter:
/// .../59db919e18d6336461a0c71da051842ceef1b5af?1602319025_wu-SPeHxn...
/// ^========^
fn parse_expiration(url: &str) -> Option<Duration> {
let token_exp = url.split("__token__=exp=").nth(1);
let expires_millis = if let Some(token_exp) = token_exp {
// Parse from the expiration token param.
// Parse from the expiration token param
token_exp.split('~').next()?
} else if let Some(verify_exp) = url.split("verify=").nth(1) {
// Parse from verify parameter (new spotifycdn.com format)
verify_exp.split('-').next()?
} else {
// Parse from the first param.
// Parse from the first param
let first_param = url.split('?').nth(1)?;
first_param.split('_').next()?
};
Expand Down