Example #1
0
        private static R <PlayResource, LocalStr> YoutubeDlWrapped(AudioResource resource)
        {
            Log.Debug("Falling back to youtube-dl!");

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

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

            var response = result.Value;

            resource.ResourceTitle = response.track ?? response.title ?? $"Youtube-{resource.ResourceId}";
            var    format = YoutubeDlHelper.FilterBest(response.formats);
            string url    = format?.url;

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

            Log.Debug("youtube-dl succeeded!");
            return(new PlayResource(url, resource));
        }
Example #2
0
        public async Task <IList <AudioResource> > SearchYoutubeDlAsync(string keyword)
        {
            var search = await YoutubeDlHelper.GetSearchAsync(keyword);

            return(search.entries
                   .Where(entry => entry.id != null)
                   .Select(entry => new AudioResource(
                               entry.id !,
                               entry.title,
                               ResolverFor
                               )).ToArray());
        }
Example #3
0
        public R <IList <AudioResource>, LocalStr> SearchYoutubeDl(string keyword)
        {
            var result = YoutubeDlHelper.GetSearch(keyword);

            if (!result.Ok)
            {
                return(result.Error);
            }
            var search = result.Value;

            return(search.entries.Select(entry =>
                                         new AudioResource(
                                             entry.id,
                                             StringNormalize.Normalize(entry.title),
                                             ResolverFor
                                             )).ToArray());
        }
Example #4
0
        private async Task <Playlist> GetPlaylistYoutubeDl(string id, string url)
        {
            var plistData = await YoutubeDlHelper.GetPlaylistAsync(url);

            var plist = new Playlist().SetTitle(plistData.title ?? $"youtube-{id}");

            plist.AddRange(plistData.entries
                           .Where(entry => entry.id != null)
                           .Select(entry => new PlaylistItem(
                                       new AudioResource(
                                           entry.id !,
                                           entry.title,
                                           ResolverFor
                                           )
                                       )));

            return(plist);
        }
Example #5
0
        private static async Task <PlayResource> YoutubeDlWrapped(AudioResource resource)
        {
            Log.Debug("Falling back to youtube-dl!");

            var response = await YoutubeDlHelper.GetSingleVideo(resource.ResourceId);

            resource.ResourceTitle = response.AutoTitle ?? $"Youtube-{resource.ResourceId}";
            var songInfo = YoutubeDlHelper.MapToSongInfo(response);
            var format   = YoutubeDlHelper.FilterBest(response.formats);
            var url      = format?.url;

            if (string.IsNullOrEmpty(url))
            {
                throw Error.LocalStr(strings.error_ytdl_empty_response);
            }

            Log.Debug("youtube-dl succeeded!");
            return(new PlayResource(url, resource, songInfo: songInfo));
        }
Example #6
0
        private R <Playlist, LocalStr> GetPlaylistYoutubeDl(string id, Uid owner)
        {
            var result = YoutubeDlHelper.GetPlaylist(id);

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

            var plistData = result.Value;
            var plist     = new Playlist(owner);

            plist.AddRange(plistData.entries.Select(entry =>
                                                    new AudioResource(
                                                        entry.id,
                                                        StringNormalize.Normalize(entry.title),
                                                        ResolverFor
                                                        )
                                                    ));

            return(plist);
        }
Example #7
0
        private static R <PlayResource, LocalStr> YoutubeDlWrapped(AudioResource resource)
        {
            R <JsonYtdlDump, LocalStr> GetResourceInfo(string id)
            {
                var result = YoutubeDlHelper.GetSingleVideo(id);

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

                return(result.Value);
            }

            Log.Debug("Falling back to youtube-dl!");

            // Get first try information
            var resourceInfo = GetResourceInfo(resource.ResourceId);

            if (!resourceInfo.Ok)
            {
                return(resourceInfo.Error);
            }
            var response = resourceInfo.Value;

            var formats = YoutubeDlHelper.SortBest(response.formats);

            if (formats.Count == 0)
            {
                return(new LocalStr(strings.error_ytdl_empty_response));
            }
            string url = formats[0]?.url;

            Log.Trace("Found the following audio codec possibilities:");
            foreach (var f in formats)
            {
                if (f.acodec != "none")
                {
                    Log.Trace("Result: abr={0} acodec={1} vcodec={2} url={3}", f.abr, f.acodec, f.vcodec, f.url);
                }
            }
            Log.Trace("Using version with {0}kbit/s", formats[0]?.abr);

            // Resource is broken
            if (string.IsNullOrEmpty(url))
            {
                return(new LocalStr(strings.error_ytdl_empty_response));
            }

            // Check if URL actually works. If not, return an error.
            var resp = new HttpClient().GetAsync(url, HttpCompletionOption.ResponseHeadersRead).Result;

            if (!resp.IsSuccessStatusCode)
            {
                Log.Info("Download URL generated by youtube-dl responds with non-200 status code: " + resp.StatusCode);
                return(new LocalStr("Youtube-URL for song is broken."));
            }

            if (resource.ResourceTitle == null)
            {
                resource = resource.WithTitle(StringNormalize.Normalize(response.title) ?? $"Youtube-{resource.ResourceId}");
            }


            Log.Debug("youtube-dl succeeded!");
            return(new PlayResource(url, resource));
        }
Example #8
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            var downloadThread = new Thread(() => YoutubeDlHelper.Download(txtMediaLinkDownload.Text, txtSavePath.Text));

            downloadThread.Start();
        }
Example #9
0
        private void LiveFromLiveStream(string mediaLink, string resolution, int fps, string outputRtmp)
        {
            var data = YoutubeDlHelper.GetMediaLivestreamLink(mediaLink);

            FfmpegHelper.PushLivestreamFromLivestream(data, resolution, fps, outputRtmp);
        }
Example #10
0
        private async Task LiveFromMediaLink(string mediaLink, string resolution, int fps, string outputRtmp)
        {
            var data = await YoutubeDlHelper.GetMediaStreamLink(mediaLink);

            FfmpegHelper.PushLivestreamFromMediaLink(data, resolution, fps, outputRtmp);
        }