Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non playable items in playlists. #7578

Merged
merged 3 commits into from
May 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions ui/component/viewers/videoViewer/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { connect } from 'react-redux';
import { makeSelectClaimForUri, selectThumbnailForUri } from 'redux/selectors/claims';
import {
makeSelectNextUrlForCollectionAndUrl,
makeSelectPreviousUrlForCollectionAndUrl,
makeSelectPrevPlayableUrlFromCollectionAndUrl,
makeSelectNextPlayableUrlFromCollectionAndUrl,
} from 'redux/selectors/collections';
import * as SETTINGS from 'constants/settings';
import * as COLLECTIONS_CONSTS from 'constants/collections';
Expand Down Expand Up @@ -38,8 +38,8 @@ const select = (state, props) => {
let nextRecommendedUri;
let previousListUri;
if (collectionId) {
nextRecommendedUri = makeSelectNextUrlForCollectionAndUrl(collectionId, uri)(state);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should do a makeSelectNextPlayableUrl.. etc. Keep the logic in the same place. What do you think?

previousListUri = makeSelectPreviousUrlForCollectionAndUrl(collectionId, uri)(state);
nextRecommendedUri = makeSelectNextPlayableUrlFromCollectionAndUrl(collectionId, uri)(state);
previousListUri = makeSelectPrevPlayableUrlFromCollectionAndUrl(collectionId, uri)(state);
} else {
const recommendedContent = selectRecommendedContentForUri(state, uri);
nextRecommendedUri = recommendedContent && recommendedContent[0];
Expand Down
31 changes: 30 additions & 1 deletion ui/redux/selectors/collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import fromEntries from '@ungap/from-entries';
import { createSelector } from 'reselect';
import { selectMyCollectionIds, makeSelectClaimForUri } from 'redux/selectors/claims';
import { parseURI } from 'util/lbryURI';
import { isClaimPlayable } from 'util/claim';

const selectState = (state: { collections: CollectionState }) => state.collections;

Expand Down Expand Up @@ -216,7 +217,7 @@ export const makeSelectNextUrlForCollectionAndUrl = (id: string, url: string) =>

if (index > -1) {
const listUrls = shuffleUrls || urls;
// We'll get the next playble url
// We'll get the next playable url
let remainingUrls = listUrls.slice(index + 1);
if (!remainingUrls.length && loopList) {
remainingUrls = listUrls.slice(0);
Expand All @@ -229,6 +230,34 @@ export const makeSelectNextUrlForCollectionAndUrl = (id: string, url: string) =>
}
);

export const makeSelectPrevPlayableUrlFromCollectionAndUrl = (collectionId: string, url: string) =>
createSelector(
(state) => state,
(state) => {
let prevUrl = url;
let prevPlayableClaim;
do {
prevUrl = makeSelectPreviousUrlForCollectionAndUrl(collectionId, prevUrl)(state);
prevPlayableClaim = makeSelectClaimForUri(prevUrl)(state);
} while (prevUrl && !isClaimPlayable(prevPlayableClaim));
return prevUrl;
}
);

export const makeSelectNextPlayableUrlFromCollectionAndUrl = (collectionId: string, url: string) =>
createSelector(
(state) => state,
(state) => {
let nextUrl = url;
let nextPlayableClaim;
do {
nextUrl = makeSelectNextUrlForCollectionAndUrl(collectionId, nextUrl)(state);
nextPlayableClaim = makeSelectClaimForUri(nextUrl)(state);
} while (nextUrl && !isClaimPlayable(nextPlayableClaim));
return nextUrl;
}
);

export const makeSelectNameForCollectionId = (id: string) =>
createSelector(makeSelectCollectionForId(id), (collection) => {
return (collection && collection.name) || '';
Expand Down
9 changes: 9 additions & 0 deletions ui/util/claim.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,12 @@ export function getChannelFromClaim(claim: ?Claim) {
? claim.signing_channel
: null;
}

export function isClaimPlayable(claim: ?Claim) {
// $FlowFixMe
if (!claim || !claim.value || !claim.value.stream_type) {
return false;
}
// $FlowFixMe
return ['audio', 'video'].includes(claim.value.stream_type);
}