DraxCodes / Youtube2Mp3

Take playlists from other sources like Spotify and feed them into Youtube to get either a playable stream or a download for each track as an MP3.
GNU General Public License v3.0
8 stars 2 forks source link

Implement downloading & Filtering #17

Closed DraxCodes closed 4 years ago

DraxCodes commented 4 years ago

Currently we have the following completed/In progress.

ℹ️ To keep it simple, for the search methods that append "lyrics" we should prob simple make that a bool on each extension method. So an example of search could be like:

public Video FilerBy(this IReadonlyList<Video> videos, string title, string author, bool appendLyrics)
{
}
svr333 commented 4 years ago

Will start working after dinner, approx. 1hour, 1hour and a half

Edit: Didn't get to it due to having too much fun in Rocket League, will start working on it tomorrow morning then :)

DraxCodes commented 4 years ago

Overall the added changes do a couple things:

⚠️ NOTE: The Console.WriteLines() will eventually be replaced with a LogEvent as per #14 This was mentioned also in the commit "Big refactor"

DraxCodes commented 4 years ago

Big new feature added: (I figured this would be the best time to add it as after this PR we really want to be building Ui's rather than working on the backend).

This code snippet outlines the new feature. It is meant as a UI side search function, it's not the prettiest but it works for now and adds something I think the UI's would 100% need.

public async Task YoutubeSearchAndDownloadTest()
{
    //User would enter a search which we use to generate a Track entity.
    Console.WriteLine("Please enter a title");
    var title = Console.ReadLine();

    //Yes Author is 100% required in this useCase, however we could make this optional if you feel it's needed.
    Console.WriteLine("Please Enter the Author");
    var author = Console.ReadLine();

    //Generate the track entity within the UI. (Set duration to 0 as we don't care about that in this useCase)
    var searchTrack = new Track(title, new[] { author }, 0);

    //Search the stream repo for the tracks assocaited with the users query (Essentially searching youtube)
    var ytTracks = await _streamRepository.SearchAsync(searchTrack);

    //Display results (At this point you have YoutubeTrack entities which have an ID associated with them)
    foreach (var track in ytTracks)
    {
        Console.WriteLine($"{track.Title} : {track.Id}");
    }

    //Here we could do a few things, in this example I am getting them to enter an ID because it's a console UI. 
    //In your UI you could have a selection box or whatever, essentially you just need to be able to get the YoutubeTrack ID based on what the user selected.
    Console.WriteLine("\nPlease enter an ID from the options above.");

    var id = Console.ReadLine();

    //Now we select the track using Linq, again ensure this is by ID as it'll be the most secure way of doing it.
    var selectedTrack = ytTracks.FirstOrDefault(t => t.Id == id);

    //Pass the selected track to the download service, specify as directory as always.
    //Save filename is the same format as with spotify except now we use Youtube title and author for obvious reasons.
    //Note that this is a new method specific to YoutubeTracks, in the future I will make this cleaner. For now I was going for readability / self documenting.
    await _downloadService.DownloadMediaFromYoutubeTrackAsync(selectedTrack, "Test");

    Console.WriteLine($"Download: {selectedTrack.Title} Completed.");
}