Started work on dailymotion implementation. Looks like HLS player will be required for this.

This commit is contained in:
rainbow napkin 2025-05-06 23:35:12 -04:00
parent 2a3740dece
commit 336c746ba7
3 changed files with 33 additions and 8 deletions

View file

@ -15,7 +15,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.*/ along with this program. If not, see <https://www.gnu.org/licenses/>.*/
//NPM Imports //NPM Imports
const url = require("node:url"); //const url = require("node:url");
const validator = require('validator');//No express here, so regular validator it is! const validator = require('validator');//No express here, so regular validator it is!
//local import //local import
@ -32,7 +32,11 @@ module.exports.yankMedia = async function(url, title){
//return media object list from IA module //return media object list from IA module
return await iaUtil.fetchMetadata(pullType.id, title); return await iaUtil.fetchMetadata(pullType.id, title);
case "yt": case "yt":
//return mediao object list from the YT-DLP module's youtube function
return await ytdlpUtil.fetchYoutubeVideoMetadata(pullType.id, title); return await ytdlpUtil.fetchYoutubeVideoMetadata(pullType.id, title);
case "dm":
//return mediao object list from the YT-DLP module's dailymotion function
return await ytdlpUtil.fetchDailymotionMetadata(pullType.id, title);
default: default:
//return null to signify a bad url //return null to signify a bad url
return null; return null;
@ -43,8 +47,9 @@ module.exports.refreshRawLink = async function(mediaObj){
switch(mediaObj.type){ switch(mediaObj.type){
case 'yt': case 'yt':
//Scrape expiration from query strings //Scrape expiration from query strings
//const expires = mediaObj.rawLink.match(/expire=([0-9]+)/); //Keeping this regex version I wrote at first in-case we need the speed const expires = mediaObj.rawLink.match(/expire=([0-9]+)/);
const expires = new URL(mediaObj.rawLink).searchParams.get("expire"); //Went with regex for speed, but I figure I'd keep this around in case we want the accuracy of a battle-tested implementation
//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 //If we have a valid raw file link that will be good by the end of the video
if(expires != null && (expires * 1000) > mediaObj.getEndTime()){ if(expires != null && (expires * 1000) > mediaObj.getEndTime()){
@ -96,6 +101,14 @@ module.exports.getMediaType = async function(url){
} }
} }
//If we have a match to a dailymotion video
if(match = url.match(/dailymotion\.com\/video\/([a-z0-9]{7})/)){
return {
type: "dm",
id: match[1]
}
}
//If we fell through all of our media types without a match //If we fell through all of our media types without a match
return{ return{
type: null, type: null,

View file

@ -29,10 +29,10 @@ const media = require('../../app/channel/media/media.js');
const regexUtils = require('../regexUtils.js'); const regexUtils = require('../regexUtils.js');
const loggerUtils = require('../loggerUtils.js') const loggerUtils = require('../loggerUtils.js')
module.exports.fetchYoutubeVideoMetadata = async function(id, title){ module.exports.fetchYoutubMetadata = async function(id, title){
try{ try{
//Try to pull media from youtube id //Try to pull media from youtube id
const media = await fetchMetadata(`https://youtu.be/${id}`, title,'yt'); const media = await fetchMetadata(`https://youtu.be/${id}`, title, 'yt');
//Return found media //Return found media
return media; return media;
@ -42,19 +42,31 @@ module.exports.fetchYoutubeVideoMetadata = async function(id, title){
if(err.message.match("Sign in to confirm youre not a bot.")){ if(err.message.match("Sign in to confirm youre not a bot.")){
//Make our own error with blackjack and hookers //Make our own error with blackjack and hookers
throw loggerUtils.exceptionSmith("The server's IP address has been banned by youtube. Please contact your server's administrator.", "queue"); throw loggerUtils.exceptionSmith("The server's IP address has been banned by youtube. Please contact your server's administrator.", "queue");
//Otherwise if we don't have a good way to handle it
}else{
//toss it back up
throw err;
} }
} }
} }
module.exports.fetchDailymotionMetadata = async function(id, title){
//Pull media from dailymotion link
const media = await fetchMetadata(`https://dailymotion.com/video/${id}`, title, 'dm');
//Return found media;
return media;
}
//Generic YTDLP function meant to be used by service-sepecific fetchers which will then be used to fetch video metadata //Generic YTDLP function meant to be used by service-sepecific fetchers which will then be used to fetch video metadata
async function fetchMetadata(link, title, type){ async function fetchMetadata(link, title, type, format = 'b'){
//Create media list //Create media list
const mediaList = []; const mediaList = [];
//Pull raw metadata //Pull raw metadata
const rawMetadata = await ytdlp(link, { const rawMetadata = await ytdlp(link, {
dumpSingleJson: true, dumpSingleJson: true,
format: 'b' format
}); });
//Pull data from rawMetadata, sanatizing title to prevent XSS //Pull data from rawMetadata, sanatizing title to prevent XSS

View file

@ -88,7 +88,7 @@ class player{
//Otherwise //Otherwise
}else{ }else{
//If we have a raw-file compatible source //If we have a raw-file compatible source
if(data.media.type == 'ia' || data.media.type == 'raw' || data.media.type == 'yt'){ if(data.media.type == 'ia' || data.media.type == 'raw' || data.media.type == 'yt' || data.media.type == 'dm'){
//Create a new raw file handler for it //Create a new raw file handler for it
this.mediaHandler = new rawFileHandler(client, this, data.media); this.mediaHandler = new rawFileHandler(client, this, data.media);
//Sync to time stamp //Sync to time stamp