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

Search feature #92

Closed
angelkoh opened this issue Jul 16, 2021 · 3 comments
Closed

Search feature #92

angelkoh opened this issue Jul 16, 2021 · 3 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@angelkoh
Copy link

angelkoh commented Jul 16, 2021

Feature request: A simple search function to retrieve a list of video links/ videoIds (and maybe with their associated thumbnail/description).

@sealedtx sealedtx added enhancement New feature or request help wanted Extra attention is needed labels Jul 16, 2021
@zhangyinglong1993
Copy link

You want to be able to search for videos and music with unlimited frequency

@Grodou
Copy link
Contributor

Grodou commented May 13, 2022

I'm working on the implementation of the search feature.
@sealedtx I'd like your opinion on the design, especially on the naming,
so here is the README part.

RequestSearchResult request = new RequestSearchResult("search query")
    .type(TypeField.VIDEO)                 // Videos only
    .match(FeatureField._3D,
        FeatureField.HD,
        FeatureField.SUBTITLES)            // 3D HD videos with subtitles
    .during(DurationField.OVER_20_MINUTES) // more than 20 minutes videos
    .uploadedThis(UploadDateField.MONTH)   // uploaded this month
    .sortBy(SortField.VIEW_COUNT);         // results sorted by view count
// or
RequestSearchResult request = new RequestSearchResult("search query")
    .select(
        TypeField.VIDEO,
        FeatureField.HD,
        (...)
        UploadDateField.MONTH)
    .sortBy(SortField.VIEW_COUNT);
	
SearchResult result = downloader.search(request).data();

// Retrieve next page (about 20 items per page)
if (result.hasNext()) {
    RequestSearchContinuation nextRequest = new RequestSearchContinuation(result);
    SearchResult nextResult = downloader.getNextPage(nextRequest).data();
}

// result details
System.out.println(result.estimatedResults());

// result items
List<SearchResultItem> items = result.items();
List<SearchResultVideoDetails> videos = result.videos();
List<SearchResultChannelDetails> channels = result.channels();
List<SearchResultPlaylistDetails> playlists = result.playlists();
List<SearchResultShelfDetails> shelves = result.shelves();

// item cast
SearchResultItem item = result.items().get(0);
if (item.isChannel()) {
    System.out.println(item.asChannel().author());
} else if (item.isShelf()) {
    for(SearchResultVideoDetails video : item.asShelf().videos()) {
        System.out.println(video.videoId());
    }
}

// Base 64 (use another base 64 encoder for search parameters)

// Classic JDK and Android API >= 26
Base64Encoder.Default.set(bytes -> Base64.getUrlEncoder().encodeToString(bytes));
// or
JdkBase64Encoder.setAsDefault();

// Android API < 26
Base64Encoder.Default.set(bytes -> Base64.encodeToString(bytes, Base64.URL_SAFE));

@sealedtx
Copy link
Owner

@Grodou wow, thank a lot for contribution!

  • The first type of request building looks more clear in my opinion, but some of method namings could be better
  • I prefer to keep supporting old android API when possible

Can you submit Pull request so it would be easier to review your code?

Grodou added a commit to Grodou/java-youtube-downloader that referenced this issue May 15, 2022
@Grodou Grodou mentioned this issue May 15, 2022
sealedtx pushed a commit that referenced this issue May 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants