Skip to content

Commit

Permalink
Add case for new CDN expiry format (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
jacksongoode authored Nov 12, 2024
1 parent 5fb8918 commit a497d93
Showing 1 changed file with 9 additions and 3 deletions.
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

0 comments on commit a497d93

Please sign in to comment.