@ -1252,7 +1252,7 @@ async function downloadFileByURL_exec(url, type, options, sessionID = null) {
&& config . getConfigItem ( 'ytdl_use_twitch_api' ) && config . getConfigItem ( 'ytdl_twitch_auto_download_chat' ) ) {
let vodId = url . split ( 'twitch.tv/videos/' ) [ 1 ] ;
vodId = vodId . split ( '?' ) [ 0 ] ;
downloadTwitchChatByVODID( vodId , file _name , type , options . user ) ;
twitch_api . downloadTwitchChatByVODID( vodId , file _name , type , options . user ) ;
}
// renames file if necessary due to bug
@ -1828,42 +1828,6 @@ function removeFileExtension(filename) {
return filename _parts . join ( '.' ) ;
}
async function getTwitchChatByFileID ( id , type , user _uid , uuid ) {
let file _path = null ;
if ( user _uid ) {
file _path = path . join ( 'users' , user _uid , type , id + '.twitch_chat.json' ) ;
} else {
file _path = path . join ( type , id + '.twitch_chat.json' ) ;
}
var chat _file = null ;
if ( fs . existsSync ( file _path ) ) {
chat _file = fs . readJSONSync ( file _path ) ;
}
return chat _file ;
}
async function downloadTwitchChatByVODID ( vodId , id , type , user _uid ) {
const twitch _api _key = config _api . getConfigItem ( 'ytdl_twitch_api_key' ) ;
const chat = await twitch _api . getCommentsForVOD ( twitch _api _key , vodId ) ;
// save file if needec params are included
if ( id && type ) {
let file _path = null ;
if ( user _uid ) {
file _path = path . join ( 'users' , user _uid , type , id + '.twitch_chat.json' ) ;
} else {
file _path = path . join ( type , id + '.twitch_chat.json' ) ;
}
if ( chat ) fs . writeJSONSync ( file _path , chat ) ;
}
return chat ;
}
app . use ( function ( req , res , next ) {
res . header ( "Access-Control-Allow-Headers" , "Origin, X-Requested-With, Content-Type, Accept, Authorization" ) ;
res . header ( "Access-Control-Allow-Origin" , getOrigin ( ) ) ;
@ -2088,7 +2052,7 @@ app.post('/api/getFile', optionalJwt, function (req, res) {
}
// check if chat exists for twitch videos
if ( file [ 'url' ] . includes ( 'twitch.tv' ) ) file [ 'chat_exists' ] = fs . existsSync ( file [ 'path' ] . substring ( 0 , file [ 'path' ] . length - 4 ) + '.twitch_chat.json' ) ;
if ( file && file [ 'url' ] . includes ( 'twitch.tv' ) ) file [ 'chat_exists' ] = fs . existsSync ( file [ 'path' ] . substring ( 0 , file [ 'path' ] . length - 4 ) + '.twitch_chat.json' ) ;
if ( file ) {
res . send ( {
@ -2147,11 +2111,12 @@ app.post('/api/getFullTwitchChat', optionalJwt, async (req, res) => {
var id = req . body . id ;
var type = req . body . type ;
var uuid = req . body . uuid ;
var sub = req . body . sub ;
var user _uid = null ;
if ( req . isAuthenticated ( ) ) user _uid = req . user . uid ;
const chat _file = await getTwitchChatByFileID( id , type , user _uid , uuid ) ;
const chat _file = await twitch_api . getTwitchChatByFileID( id , type , user _uid , uuid , sub ) ;
res . send ( {
chat : chat _file
@ -2163,28 +2128,19 @@ app.post('/api/downloadTwitchChatByVODID', optionalJwt, async (req, res) => {
var type = req . body . type ;
var vodId = req . body . vodId ;
var uuid = req . body . uuid ;
var sub = req . body . sub ;
var user _uid = null ;
if ( req . isAuthenticated ( ) ) user _uid = req . user . uid ;
// check if file already exists. if so, send that instead
const file _exists _check = await getTwitchChatByFileID( id , type , user _uid , uuid ) ;
const file _exists _check = await twitch_api . getTwitchChatByFileID( id , type , user _uid , uuid , sub ) ;
if ( file _exists _check ) {
res . send ( { chat : file _exists _check } ) ;
return ;
}
const full _chat = await downloadTwitchChatByVODID ( vodId ) ;
let file _path = null ;
if ( user _uid ) {
file _path = path . join ( 'users' , req . user . uid , type , id + '.twitch_chat.json' ) ;
} else {
file _path = path . join ( type , id + '.twitch_chat.json' ) ;
}
if ( full _chat ) fs . writeJSONSync ( file _path , full _chat ) ;
const full _chat = await twitch _api . downloadTwitchChatByVODID ( vodId , id , type , user _uid , sub ) ;
res . send ( {
chat : full _chat
@ -2472,9 +2428,15 @@ app.post('/api/getSubscription', optionalJwt, async (req, res) => {
var file _obj = new utils . File ( id , title , thumbnail , isaudio , duration , url , uploader , size , file , upload _date ) ;
parsed _files . push ( file _obj ) ;
}
} else {
// loop through files for extra processing
for ( let i = 0 ; i < parsed _files . length ; i ++ ) {
const file = parsed _files [ i ] ;
// check if chat exists for twitch videos
if ( file && file [ 'url' ] . includes ( 'twitch.tv' ) ) file [ 'chat_exists' ] = fs . existsSync ( file [ 'path' ] . substring ( 0 , file [ 'path' ] . length - 4 ) + '.twitch_chat.json' ) ;
}
}
res . send ( {
subscription : subscription ,
files : parsed _files