Finished up work with youtube raw link refreshing.
This commit is contained in:
parent
02c4d214fa
commit
366766d0a3
|
|
@ -67,20 +67,32 @@ module.exports.yankMedia = async function(url, title){
|
||||||
module.exports.refreshRawLink = async function(mediaObj){
|
module.exports.refreshRawLink = async function(mediaObj){
|
||||||
switch(mediaObj.type){
|
switch(mediaObj.type){
|
||||||
case 'yt':
|
case 'yt':
|
||||||
/* We're skipping this one for now...
|
//Create boolean to hold expired state
|
||||||
//Scrape expiration from query strings
|
let expired = false;
|
||||||
const expires = mediaObj.rawLink.match(/expire=([0-9]+)/);
|
//Create boolean to hold whether or not rawLink object is empty
|
||||||
//Went with regex for speed, but I figure I'd keep this around in case we want the accuracy of a battle-tested implementation
|
let empty = true;
|
||||||
//const expires = new URL(mediaObj.rawLink).searchParams.get("expire");
|
|
||||||
|
|
||||||
//If we have a valid raw file link that will be good by the end of the video
|
//For each link map in the rawLink object
|
||||||
if(expires != null && (expires * 1000) > mediaObj.getEndTime()){
|
for(const key of Object.keys(mediaObj.rawLink)){
|
||||||
//Return null to tell the calling function there is no refresh required for this video at this time
|
//Ignore da wombo-combo since it's probably just the fuckin regular URL
|
||||||
return null;
|
if(key != "combo"){
|
||||||
|
for(const link of mediaObj.rawLink[key]){
|
||||||
|
//Let it be known, this bitch got links
|
||||||
|
empty = false;
|
||||||
|
//Get expiration parameter from the link
|
||||||
|
const expires = new URL(link[1]).searchParams.get("expire") * 1000;
|
||||||
|
|
||||||
|
//If this shit's already expired
|
||||||
|
if(expires < Date.now()){
|
||||||
|
//Set expired to true, don't directly set the bool because we don't ever want to unset this flag
|
||||||
|
expired = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
//If the raw link object is empty or expired
|
||||||
|
if(empty || expired){
|
||||||
//Re-fetch media metadata
|
//Re-fetch media metadata
|
||||||
metadata = await ytdlpUtil.fetchYoutubeMetadata(mediaObj.id);
|
metadata = await ytdlpUtil.fetchYoutubeMetadata(mediaObj.id);
|
||||||
|
|
||||||
|
|
@ -90,6 +102,7 @@ module.exports.refreshRawLink = async function(mediaObj){
|
||||||
//return media object
|
//return media object
|
||||||
return mediaObj;
|
return mediaObj;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//Return null to tell the calling function there is no refresh required for this media type
|
//Return null to tell the calling function there is no refresh required for this media type
|
||||||
return null;
|
return null;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue