private async Task <SongInfo> ResolveWithYtDl(string query) { string[] data; try { bool tryForBestAudio = true; var ytdl = new YtdlOperation(); data = (await ytdl.GetDataAsync(query, tryForBestAudio).ConfigureAwait(false)).Split('\n'); if (data.Length < 6) { // try without best audio flag as it might be youtube stream // which does not have bestaudio stream _log.Info("Trying to request stream without bestaudio flag."); tryForBestAudio = false; data = (await ytdl.GetDataAsync(query, tryForBestAudio).ConfigureAwait(false)).Split('\n'); } if (data.Length < 6) { _log.Info("No song found. Data less than 6"); return(null); } if (!TimeSpan.TryParseExact(data[4], new[] { "ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss" }, CultureInfo.InvariantCulture, out var time)) { time = TimeSpan.MaxValue; } return(new SongInfo() { Title = data[0], VideoId = data[1], Uri = async() => { var ytdlo = new YtdlOperation(); data = (await ytdlo.GetDataAsync(query, tryForBestAudio).ConfigureAwait(false)).Split('\n'); if (data.Length < 6) { _log.Info("No song found. Data less than 6"); return null; } return data[2]; }, Thumbnail = data[3], TotalTime = time, Provider = "YouTube", ProviderType = MusicType.YouTube, Query = "https://youtube.com/watch?v=" + data[1], }); } catch (Exception ex) { _log.Warn(ex); return(null); } }
public async Task <SongInfo> ResolveSong(string query) { _log.Info("Getting link"); string[] data; try { using (var ytdl = new YtdlOperation()) { data = (await ytdl.GetDataAsync(query)).Split('\n'); } if (data.Length < 6) { _log.Info("No song found. Data less than 6"); return(null); } if (!TimeSpan.TryParseExact(data[4], new[] { "ss", "m\\:ss", "mm\\:ss", "h\\:mm\\:ss", "hh\\:mm\\:ss", "hhh\\:mm\\:ss" }, CultureInfo.InvariantCulture, out var time)) { time = TimeSpan.FromHours(24); } return(new SongInfo() { Title = data[0], VideoId = data[1], Uri = async() => { using (var ytdl = new YtdlOperation()) { data = (await ytdl.GetDataAsync(query)).Split('\n'); } if (data.Length < 6) { _log.Info("No song found. Data less than 6"); return null; } return data[2]; }, Thumbnail = data[3], TotalTime = time, Provider = "YouTube", ProviderType = MusicType.YouTube, Query = "https://youtube.com/watch?v=" + data[1], }); } catch (Exception ex) { _log.Warn(ex); return(null); } }
public YtdlYoutubeResolver(ITrackCacher trackCacher, IGoogleApiService google) { _trackCacher = trackCacher; _google = google; _ytdlPlaylistOperation = new YtdlOperation("-4 " + "--geo-bypass " + "--encoding UTF8 " + "-f bestaudio " + "-e " + "--get-url " + "--get-id " + "--get-thumbnail " + "--get-duration " + "--no-check-certificate " + "-i " + "--yes-playlist " + "-- \"{0}\""); _ytdlIdOperation = new YtdlOperation("-4 " + "--geo-bypass " + "--encoding UTF8 " + "-f bestaudio " + "-e " + "--get-url " + "--get-id " + "--get-thumbnail " + "--get-duration " + "--no-check-certificate " + "-- \"{0}\""); _ytdlSearchOperation = new YtdlOperation("-4 " + "--geo-bypass " + "--encoding UTF8 " + "-f bestaudio " + "-e " + "--get-url " + "--get-id " + "--get-thumbnail " + "--get-duration " + "--no-check-certificate " + "--default-search " + "\"ytsearch:\" -- \"{0}\""); }