public async Task DownloadSpecificTrackById() { Console.WriteLine("Please enter an ID"); var id = Console.ReadLine(); var searchTrack = new YoutubeTrack("", new List <string>(), 0, id); await _downloadService.DownloadMediaFromYoutubeTrackAsync(searchTrack, "Test"); }
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) as IEnumerable <YoutubeTrack>; //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."); }