コード例 #1
0
        private R <PlayResource> YoutubeDlWrapped(AudioResource resource)
        {
            string title = null;
            string url   = null;

            Log.Write(Log.Level.Debug, "YT Ruined!");

            var result = YoutubeDlHelper.FindAndRunYoutubeDl(resource.ResourceId);

            if (!result.Ok)
            {
                return(result.Message);
            }

            var response = result.Value;

            title = response.Item1;
            var urlOptions = response.Item2;

            if (urlOptions.Count == 1)
            {
                url = urlOptions[0];
            }
            else if (urlOptions.Count >= 1)
            {
                Uri[] uriList   = urlOptions.Select(s => new Uri(s)).ToArray();
                Uri   bestMatch = uriList
                                  .FirstOrDefault(u => HttpUtility.ParseQueryString(u.Query)
                                                  .GetValues("mime")
                                                  .Any(x => x.StartsWith("audio", StringComparison.OrdinalIgnoreCase)));
                url = (bestMatch ?? uriList[0]).OriginalString;
            }

            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(url))
            {
                return("No youtube-dl response");
            }

            Log.Write(Log.Level.Debug, "YT Saved!");
            return(new PlayResource(url, resource.WithName(title)));
        }
コード例 #2
0
        private R <PlayResource, LocalStr> YoutubeDlWrapped(string link)
        {
            Log.Debug("Falling back to youtube-dl!");

            var result = YoutubeDlHelper.FindAndRunYoutubeDl(link);

            if (!result.Ok)
            {
                return(result.Error);
            }

            var(title, urls) = result.Value;
            if (urls.Count == 0 || string.IsNullOrEmpty(title) || string.IsNullOrEmpty(urls[0]))
            {
                return(new LocalStr(strings.error_ytdl_empty_response));
            }

            Log.Debug("youtube-dl succeeded!");

            return(new PlayResource(urls[0], new AudioResource(link, title, FactoryFor)));
        }
コード例 #3
0
        private static R <PlayResource, LocalStr> YoutubeDlWrapped(AudioResource resource)
        {
            Log.Debug("Falling back to youtube-dl!");

            var result = YoutubeDlHelper.FindAndRunYoutubeDl(resource.ResourceId);

            if (!result.Ok)
            {
                return(result.Error);
            }

            var response   = result.Value;
            var title      = response.title;
            var urlOptions = response.links;

            string url = null;

            if (urlOptions.Count == 1)
            {
                url = urlOptions[0];
            }
            else if (urlOptions.Count >= 1)
            {
                Uri[] uriList   = urlOptions.Select(s => new Uri(s)).ToArray();
                Uri   bestMatch = uriList
                                  .FirstOrDefault(u => ParseQueryString(u.Query).TryGetValue("mime", out var mimes) &&
                                                  mimes.Any(x => x.StartsWith("audio", StringComparison.OrdinalIgnoreCase)));
                url = (bestMatch ?? uriList[0]).OriginalString;
            }

            if (string.IsNullOrEmpty(title) || string.IsNullOrEmpty(url))
            {
                return(new LocalStr(strings.error_ytdl_empty_response));
            }

            resource.ResourceTitle = title;

            Log.Debug("youtube-dl succeeded!");
            return(new PlayResource(url, resource));
        }
コード例 #4
0
        private R <PlayResource> YoutubeDlWrapped(string link)
        {
            Log.Write(Log.Level.Debug, "SC Ruined!");

            var result = YoutubeDlHelper.FindAndRunYoutubeDl(link);

            if (!result.Ok)
            {
                return(result.Message);
            }

            var    response = result.Value;
            string title    = response.Item1;
            string url      = response.Item2.FirstOrDefault();

            if (response.Item2.Count == 0 || string.IsNullOrEmpty(title) || string.IsNullOrEmpty(url))
            {
                return("No youtube-dl response");
            }

            Log.Write(Log.Level.Debug, "SC Saved!");

            return(new PlayResource(url, new AudioResource(link, title, FactoryFor)));
        }