Skip to content

Commit

Permalink
feat(youtube): pull video categories list
Browse files Browse the repository at this point in the history
  • Loading branch information
austil committed Sep 7, 2018
1 parent b54ae3b commit b411647
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/pullers/youtube_pull.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ const getDefaultsPlaylists = (oauth2Client) => (new Promise((resolve, reject) =>
mine: true,
part: 'contentDetails'
};

service.channels.list(channelInfo, (err, res) => {
if (err) {
reject('The channels API returned an error: ' + err);
Expand All @@ -47,6 +46,21 @@ const getDefaultsPlaylists = (oauth2Client) => (new Promise((resolve, reject) =>
});
}));

const getCategories = (oauth2Client) => (new Promise((resolve, reject) => {
const categoriesParams = {
auth: oauth2Client,
part: 'snippet',
regionCode: 'US'
};
service.videoCategories.list(categoriesParams, (err, res) => {
if (err) {
reject('The videoCategories API returned an error: ' + err);
} else {
resolve(res.data.items);
}
});
}));

const getPlaylistItems = (params) => (new Promise((resolve, reject) => {
service.playlistItems.list(params, (err, res) => {
if (err) {
Expand Down Expand Up @@ -218,7 +232,14 @@ const parseHistory = async (lastParse) => {
oauth2Client.credentials = auth.get('youtube');
log({msg: 'Ready !'});

const playlists = await getDefaultsPlaylists(oauth2Client, service);
const playlists = await getDefaultsPlaylists(oauth2Client);

const pullCategories = async () => {
if (db.get('categories').value().length <= 0) {
const categories = await getCategories(oauth2Client);
db.set('categories', categories).write();
}
};

const pullLikes = puller({
name: 'Likes',
Expand All @@ -239,6 +260,7 @@ const parseHistory = async (lastParse) => {
const lastHistoryParse = db.get('last_parse.watch_history').value();

await Promise.all([
pullCategories(),
pullLikes(lastLike ? lastLike.id : null),
pullFavorites(lastFavorite ? lastFavorite.id : null),
]);
Expand Down
1 change: 1 addition & 0 deletions src/pullers_const.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ const YOUTUBE = {
likes: [],
history: [],
favorites: [],
categories: {},
last_pull: '',
last_parse: {
watch_history: ''
Expand Down

0 comments on commit b411647

Please sign in to comment.