Skip to content

Commit

Permalink
Remove live streams from search results.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Jul 8, 2017
1 parent 44035c3 commit 6801368
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export function getPlaylistID(url) {
}

const defaultSearchOptions = {
part: 'id',
part: 'id,snippet',
fields: `
items(id/videoId),
items(id/videoId, snippet/liveBroadcastContent),
pageInfo,
nextPageToken,
prevPageToken
Expand Down Expand Up @@ -146,12 +146,14 @@ export default function youTubeSource(uw, opts = {}) {
maxHeight: 8192
});

return result.items.map(normalizeMedia);
return result.items.map(normalizeMedia).filter(item => item.duration > 0);
}

async function get(sourceIDs) {
const ids = sourceIDs.map(id => getYouTubeID(id) || id);

const pages = await Promise.all(
chunk(sourceIDs, 50).map(getPage)
chunk(ids, 50).map(getPage)
);
return pages.reduce((result, page) => result.concat(page), []);
}
Expand All @@ -162,14 +164,17 @@ export default function youTubeSource(uw, opts = {}) {
// URLs.
const id = getYouTubeID(query, { fuzzy: false });
const result = await youTubeSearch({
...params,
...defaultSearchOptions,
...searchOptions,
...params,
q: id ? `"${id}"` : query,
pageToken: page
});

return get(result.items.map(item => item.id.videoId));
return get(
result.items
.filter(item => !item.snippet || item.snippet.liveBroadcastContent === 'none')
.map(item => item.id.videoId));
}

async function getPlaylistPage(playlistID, page = null) {
Expand Down

0 comments on commit 6801368

Please sign in to comment.