Skip to content

Commit

Permalink
Merge pull request #50 from gatecrasher777/fix
Browse files Browse the repository at this point in the history
Updates, Fixes, Additions
  • Loading branch information
gatecrasher777 authored Apr 14, 2023
2 parents e1c6d68 + 430e232 commit 0d20fa4
Show file tree
Hide file tree
Showing 11 changed files with 376 additions and 246 deletions.
245 changes: 141 additions & 104 deletions examples/channel_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,128 +16,165 @@ let app = {
// proxy agent string
proxy: '',
// info fields to ignore
ignore: ['cookie', 'userAgent', 'options', 'sapisid', 'status', 'reason', 'cancelled'],
ignore: ['cookie', 'userAgent', 'options', 'sapisid', 'status', 'reason', 'cancelled', 'debugOn','commentOptions','commentOrder','canEmbed','isLive'],
test_options: {
// any channel id
id: 'UCG5qGWdu8nIRZqJ_GgDwQ-w',
// videos, playlists, channels, about, search
// videos, shorts, playlists, channels, about, search
items: 'about',
// new (videos/playlists), old (videos), views (videos), updated (playlists)
order: 'new',
// number of results to fetch. You can get further videos (if available) with subsequent channel.continued() calls
quantity: 60,
quantity: 30,
// items=search only
query: '',
query: 'after:'+ new Date(ut.now()-1000*60*60*24*7).toISOString().substring(0,10),
},
};

async function runAbout(channel) {
console.log('\nFetch channel profile data (items: about)');
await channel.fetch();
console.log(`Channel status: ${channel.status} (${channel.reason})`);
console.log('Raw Channel json to ./examples/channelAbout.json');
fs.writeFileSync('./examples/channelAbout.json', ut.jsp(channel.data), 'utf8');
if (channel.status === 'OK') {
console.log(`\nChannel info for ${channel.author} to ./examples/channel_about.json`);
fs.writeFileSync('./examples/channel_about.json', ut.jsp(channel.info(app.ignore)), 'utf8');
}
}

async function runVideos(channel) {
console.log('\nFetch latest Channel videos');
await channel.fetch({ items: 'videos' });
console.log(`Channel status: ${channel.status} (${channel.reason})`);
console.log('Raw Channel json to ./examples/channelVideos.json');
fs.writeFileSync('./examples/channelVideos.json', ut.jsp(channel.data), 'utf8');
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} results for ${channel.author}`);
console.log('Want some more? Will continue...');
await channel.continued();
fs.writeFileSync('./examples/channelVideos.json', ut.jsp(channel.data), 'utf8');
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} videos for ${channel.author}`);
console.log('\nChannel info/videos to ./examples/channel_videos.json');
let output = {
channel: channel.info(app.ignore),
videos: [],
};
channel.results.forEach(video => {
output.videos.push(video.info(app.ignore));
});
fs.writeFileSync('./examples/channel_videos.json', ut.jsp(output), 'utf8');
}
}
}

async function runShorts(channel) {
console.log('\nFetch latest Channel shorts');
await channel.fetch({ items: 'shorts' });
console.log(`Channel status: ${channel.status} (${channel.reason})`);
console.log('Raw Channel json to ./examples/channelShorts.json');
fs.writeFileSync('./examples/channelShorts.json', ut.jsp(channel.data), 'utf8');
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} results for ${channel.author}`);
console.log('Want some more? Will continue...');
await channel.continued();
fs.writeFileSync('./examples/channelShorts.json', ut.jsp(channel.data), 'utf8');
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} shorts for ${channel.author}`);
console.log('\nChannel info/shorts to ./examples/channel_shorts.json');
let output = {
channel: channel.info(app.ignore),
shorts: [],
};
channel.results.forEach(video => {
output.shorts.push(video.info(app.ignore));
});
fs.writeFileSync('./examples/channel_shorts.json', ut.jsp(output), 'utf8');
}
}
}

async function runPlaylists(channel) {
console.log('\n\nFetch 30 channel playlists (most recently updated)...');
await channel.fetch({ items: 'playlists', order: 'updated', quantity: 30 });
console.log('Raw Channel json to ./examples/channelPlaylists.json');
fs.writeFileSync('./examples/channelPlaylists.json', ut.jsp(channel.data), 'utf8');
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} playlist results for ${channel.author}`);
console.log('\nChannel info/playlists to ./examples/channel_playlists.json');
let output = {
channel: channel.info(app.ignore),
playlists: [],
};
channel.results.forEach(item => {
output.playlists.push(item.info(app.ignore));
});
fs.writeFileSync('./examples/channel_playlists.json', ut.jsp(output), 'utf8');
}
}

async function runChannels(channel) {
console.log('\n\nFetch 20 related channels...');
await channel.fetch({ items: 'channels', order: 'new', quantity: 20 });
console.log('Raw Channel json to ./examples/channelChannels.json');
fs.writeFileSync('./examples/channelChannels.json', ut.jsp(channel.data), 'utf8');
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} related channels for ${channel.author}`);
console.log('\nChannel info/channels to ./examples/channel_channels.json');
let output = {
channel: channel.info(app.ignore),
channels: [],
};
channel.results.forEach(item => {
output.channels.push(item.info(app.ignore));
});
fs.writeFileSync('./examples/channel_channels.json', ut.jsp(output), 'utf8');

}
}

async function runSearch(channel) {
console.log(`\n\nSearch for up to 100 videos/shorts in the channel with query: "${app.test_options.query}"`);
await channel.fetch({ items: 'search', quantity: 100 });
console.log('Raw Channel json to ./examples/channelSearch.json');
fs.writeFileSync('./examples/channelSearch.json', ut.jsp(channel.data), 'utf8');
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} search results in ${channel
.author} for "${channel.options.query}"`);
console.log('\nChannel search info/videos to ./examples/channel_search.json');
let output = {
channel: channel.info(app.ignore),
videos: [],
};
channel.results.forEach(item => {
output.videos.push(item.info(app.ignore));
});
fs.writeFileSync('./examples/channel_search.json', ut.jsp(output), 'utf8');
}
}

async function run() {
let session = new ytcog.Session(app.cookie, app.userAgent, app.proxy);
await session.fetch();
console.log(`Session status: ${session.status} (${session.reason})`);
if (session.status === 'OK') {
let channel = new ytcog.Channel(session, app.test_options);
channel.debugOn = true;
console.log('\nFetch channel profile data (items: about)');
await channel.fetch();
console.log('Raw Channel json to ./examples/channelA.json');
fs.writeFileSync('./examples/channelA.json', ut.jsp(channel.data), 'utf8');
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log('\nFetch latest Channel videos');
await channel.fetch({ items: 'videos' });
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} results for ${channel.author}`);
console.log('Want some more? Will continue...');
await channel.continued();
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} video results for ${channel.author}`);
console.log('\nChannel info/results to ./examples/channel_results.json');
let output1 = {
channel: channel.info(app.ignore),
results: [],
};
channel.results.forEach(video => {
output1.results.push(video.info(app.ignore));
});
fs.writeFileSync('./examples/channel_results.json', ut.jsp(output1), 'utf8');
console.log('Raw Channel json to ./examples/channel.json');
fs.writeFileSync('./examples/channel.json', ut.jsp(channel.data), 'utf8');
console.log('\n\nFetch 30 channel playlists (most recently updated)...');
await channel.fetch({ items: 'playlists', order: 'updated', quantity: 30 });
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} playlist results for ${channel.author}`);
console.log('\nChannel info/results to ./examples/channel_playlists.json');
let output2 = {
channel: channel.info(app.ignore),
results: [],
};
channel.results.forEach(item => {
output2.results.push(item.info(app.ignore));
});
fs.writeFileSync('./examples/channel_playlists.json', ut.jsp(output2), 'utf8');
console.log('Raw Channel json to ./examples/channelP.json');
fs.writeFileSync('./examples/channelP.json', ut.jsp(channel.data), 'utf8');
console.log('\n\nFetch 20 related channels...');
await channel.fetch({ items: 'channels', order: 'new', quantity: 20 });
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} channel results for ${channel.author}`);
console.log('\nChannel info/results to ./examples/channel_channels.json');
let output3 = {
channel: channel.info(app.ignore),
results: [],
};
channel.results.forEach(item => {
output3.results.push(item.info(app.ignore));
});
fs.writeFileSync('./examples/channel_channels.json', ut.jsp(output3), 'utf8');
console.log('Raw Channel json to ./examples/channelC.json');
fs.writeFileSync('./examples/channelC.json', ut.jsp(channel.data), 'utf8');
console.log('\n\nSearch for 20 videos in the channel ...');
await channel.fetch({ items: 'search', query: 'Chelsea', quantity: 20 });
console.log(`Channel status: ${channel.status} (${channel.reason})`);
if (channel.status === 'OK') {
console.log(`\nFound ${channel.results.length} search results in ${channel
.author} for ${channel.options.query}`);
console.log('\nChannel info/results to ./examples/channel_search.json');
let output4 = {
channel: channel.info(app.ignore),
results: [],
};
channel.results.forEach(item => {
output4.results.push(item.info(app.ignore));
});
fs.writeFileSync('./examples/channel_search.json', ut.jsp(output4), 'utf8');
console.log('Raw Channel json to ./examples/channelS.json');
fs.writeFileSync('./examples/channelS.json', ut.jsp(channel.data), 'utf8');
} else {
console.log('Raw Channel json to ./examples/channelS.json');
fs.writeFileSync('./examples/channelS.json', ut.jsp(channel.data), 'utf8');
}
} else {
console.log('Raw Channel json to ./examples/channelC.json');
fs.writeFileSync('./examples/channelC.json', ut.jsp(channel.data), 'utf8');
}
} else {
console.log('Raw Channel json to ./examples/channelP.json');
fs.writeFileSync('./examples/channelP.json', ut.jsp(channel.data), 'utf8');
}
} else {
console.log('Raw Channel json to ./examples/channel.json');
fs.writeFileSync('./examples/channel.json', ut.jsp(channel.data), 'utf8');
}
} else {
console.log('Raw Channel json to ./examples/channel.json');
fs.writeFileSync('./examples/channel.json', ut.jsp(channel.data), 'utf8');
}
} else {
console.log('Raw Channel json to ./examples/channelA.json');
fs.writeFileSync('./examples/channelA.json', ut.jsp(channel.data), 'utf8');
}
await runAbout(channel);
await runVideos(channel);
await runShorts(channel);
await runPlaylists(channel);
await runChannels(channel);
await runSearch(channel);
console.log('Session complete.')
} else {
console.log('Session failed.')
}
}

Expand Down
Loading

0 comments on commit 0d20fa4

Please sign in to comment.