bluegrams / youtubedlsharp Goto Github PK
View Code? Open in Web Editor NEWA simple .NET wrapper library for youtube-dl and yt-dlp
License: BSD 3-Clause "New" or "Revised" License
A simple .NET wrapper library for youtube-dl and yt-dlp
License: BSD 3-Clause "New" or "Revised" License
This is really a problem in yt-dlp, but I was curious if we might be able to add support for either restricting the file-type of the thumbnail used when using --embed-thumbnail, or converting an available thumbnail to a specific file-type before it is embedded?
The problem is that when you download OPUS audio from a YT url the thumbnails are in webp format which cannot be embedded. I do not know if the ThumbnailData contains multiple file-types we can choose from or not. If it doesnt, the next thing I can think of is to convert the existing Thumbnail to JPG.
I don't want bestvideo and audio. I want to download a video by its format id, whereby using commandline would be -f 22 (720p)
I can't figure it out.
EDIT:
I've found that passing "mp4" as format argument gets me the best quality .mp4 file, (720p in the cases I've tested on). But what if I want 480p, or 360p? I still haven't figured that out.
EDIT: I think I have it.
await ytdl.RunVideoDownload(textBoxUrl.Text, format: "22", progress: progress, ct: cts.Token, mergeFormat: DownloadMergeFormat.Mp4);
I noticed that sometimes the file name is not generated correctly. In this case I get file names that look like the following example "index-v1-a1 [index-v1-a1].mp4". The title is actually determined correctly in the fetch result, only when creating the filename there sometimes seems to be problems. Is there a way to configure a custom title for the filename? Actually I would like to have a filename like in this example.
string videoTitle = "This is a video title without special characters";
string videoQuality = "720p";
string myFileName = $"{videoTitle} [{videoQuality}].%(ext)s"
Hi
Is YoutubeDLSharp suppose to work on Linux?, it works fine on windows but fails on Linux I have this error
An error occurred trying to start process 'yt-dlp.exe' with working directory '/home/...'. No such file or directory
I'm using
And
await YoutubeDL.DownloadYtDlpBinary(); await YoutubeDL.DownloadFFmpegBinary();
Thank you
YoutubeDLSharp/YoutubeDLSharp/YoutubeDL.cs
Line 119 in 74b79e2
I am using your library in a WinForms app. Although I am calling await ytdl.RunVideoDataFetch(url)
the UI thread is temporarily blocked and the program freezes for a couple seconds.
It seems like one or more lines between line 122 and 131 are taking longer than expected and blocking the UI. I did not dig into it much, but this was the only thing I noticed at a glance that could possibly be blocking the thread.
var opts = GetDownloadOptions();
Moving GetDownloadOptions
to an async Task and awaiting that task for the options may fix the issue.
So I have the following code:
var ytdl = new YoutubeDL();
ytdl.FFmpegPath = @"..\ffmpeg.exe";
ytdl.YoutubeDLPath = @"..\youtube-dl.exe";
ytdl.OutputFolder = @"..\Downloads\";
Progress<DownloadProgress> dlprogress = new(p => Console.WriteLine(p.Progress * 100));
var dledpath = await ytdl.RunAudioDownload("https://www.youtube.com/watch?v=a4YwJCZRh5M", AudioConversionFormat.Mp3, progress: dlprogress);
var awaitdata = await ytdl.RunVideoDataFetch("https://www.youtube.com/watch?v=a4YwJCZRh5M");
VideoData Data = awaitdata.Data;
Console.WriteLine(Data.Title);
Console.ReadLine();
This code works fine and with no errors, however if I change the
ytdl.YoutubeDLPath = @"..\youtube-dl.exe";
to
ytdl.YoutubeDLPath = @"..\yt-dlp.exe";
I'll get this error
Newtonsoft.Json.JsonReaderException: 'Input string '1.0' is not a valid integer. Path 'formats[3].quality', line 1, position 4175.'
Am I doing something wrong? how should I go about this?
using version 1.0.0-beta2 didn't fix the problem
In my Xamarin forms app, I realized that cancellation of the CancellationTokenSource does not stop the download. Only no more progress updates are passed to the application, but in task manager you see the download-process is still running. Also for 30 seconds you see the taskkill.exe process, but then it times out. Any ideas to fix this? Canceling downloads is essential to youtube dl apps.
I might not be using the library the correct way, so I admit this might not be a problem, but what I want to do is essentially list all the videos/audio in a playlist and just return the urls. The reason for this is because several of the watchlists I want to download have overlapping videos and it seems to be redundant. When I try the code below with the FlatPlaylist option all that happens is an empty[]. Maybe I'm not using the library correctly?
// See https://aka.ms/new-console-template for more information
using YoutubeDLSharp;
using YoutubeDLSharp.Metadata;
using YoutubeDLSharp.Options;
string basePath = System.AppDomain.CurrentDomain.BaseDirectory;
var ytdl = new YoutubeDL();
ytdl.YoutubeDLPath = Path.Combine($"{basePath}yt-dlp.exe");
ytdl.FFmpegPath = Path.Combine($"{basePath}ffmpeg.exe");
ytdl.OutputFolder = @"H:\Youtube\Test";
var optionsSet = new OptionSet()
{
FlatPlaylist = true
};
string vid_target = "mywatchlist";
string[] vid_targets = new string[] { vid_target };
var ytdlProc = new YoutubeDLProcess();
var proc = await ytdlProc.RunAsync(vid_targets, optionsSet);
var res = await ytdl.RunAudioPlaylistDownload(vid_target, 1, 100, null, AudioConversionFormat.Mp3, default, null, null, optionsSet);
Console.ReadLine();
The options "DownloadSections"
and "ForceKeyframesAtCuts"
don't work when using "RunVideoDownload"
BUT DO WORK with "RunWithOptions"
Code Example:
using YoutubeDLSharp;
using YoutubeDLSharp.Options;
const string url = "https://youtu.be/4Ot0T4iCXfM";
var youtubeDl = new YoutubeDL
{
YoutubeDLPath = "yt-dlp",
FFmpegPath = "ffmpeg",
OutputFileTemplate = "%(id)s.%(ext)s",
OutputFolder = Directory.GetCurrentDirectory()
};
var options = new OptionSet
{
DownloadSections = "*15-30",
ForceKeyframesAtCuts = true
};
Console.WriteLine($"Options: {options}");
await youtubeDl.RunVideoDownload(url,
mergeFormat: DownloadMergeFormat.Mp4,
overrideOptions: options,
ct: CancellationToken.None);
// await youtubeDl.RunWithOptions(new[] { url }, options, CancellationToken.None);
So, on my fork ytdlp/master, I have basically implemented all of the updated features of yt-dlp.
However, as I did this, there were Options
that got removed because they were no longer applicable, as well as some methods that got rearranged/moved around. This fork also uses .net 6, and removes Newtonsoft.Json in favor of the built in (.net 6) System.Text.Json
.
Would you like to proceed with using the new YtDlpSharpLib
? Or would you rather have me work on maintaining it as a seperate project/nuget package?
When I download long audio files that don't output directly to MP3 and need to be converted, it takes a while and I don't see the progress. As far as I know, ffmpeg converts the audio. Can I get the conversion progress or the FFmpeg output?
Is there a way to tell RunAudioDownload/RunVideoDownload to select a custom Language, if the are multiple Audio Languages? Or maybe, you can set the required Audio Language in RunVideoDataFetch somehow?
Edit: It seems, that you can do such things in Format description, but I have no idea, how to extend my format string to get an englisch, german or default language, if no audio language can be found.
overrideOptions: new OptionSet {
Format = $"bv*[height<={progressInfo.VidoFormat.Height}]+ba/b[height<={progressInfo.VidoFormat.Height}] / wv*+ba/w"
}
I want to play a video while it's still downloading.
I've tried it using the YoutubeDLProcess (params: NoPart) and the OutputReceivedEvent. This just gives me the current state of the downloader.
In my case I want to use just the audiotrack. Conviniently I would like to use _youtubeDL.RunAudioDownload(url, YoutubeDLSharp.Options.AudioConversionFormat.Mp3)
and start it once its progress is above like 3% using CSCore
I am currently using version 1.0.0.beta3 with yt-dlp and have encountered an error that had baffled me for a good while. When creating a new youtubedl object, my path had a space in it (C:\Project Repo\Project\asdf\yt-dlp.exe), causing an error. Hope this can get fixed soon, thanks ;)
I'm currently using this in a project of mine, we ran into the bug fixed by e16e2ce. We've worked around it by using git submodules, but would greatly appreciate a NuGet package update whenever you're free as it'd be preferred.
Thanks a ton for this project otherwise, it's been super helpful!
Sorry for the question but im not sure if i can use it in a MAUI project
A .NET Crash occurs when attempting to fetch a list of formats for Youtube videos because they have started returning the Format.Quality property as a decimal value which cannot be parsed to an Int by Newtonsoft.
Changing the FormatData.Quality property to a double appears to fix the issue, but I have not tested with other hosts.
It seems like the new yt-dlp version broke the jsonreader
I'm using version 1.0.0-beta2
Unhandled exception. Newtonsoft.Json.JsonReaderException: Input string '1.0' is not a valid integer. Path 'formats[3].quality', line 1, position 9500.
...
Sample Code:
using YoutubeDLSharp;
using YoutubeDLSharp.Options;
YoutubeDL youtubeDl = new()
{
YoutubeDLPath = "yt-dlp",
FFmpegPath = "ffmpeg",
OutputFolder = Path.GetTempPath(),
OutputFileTemplate = "%(id)s.%(ext)s",
};
const string url = "https://youtu.be/sca4VG9b0NY";
var videoDataFetch = await youtubeDl.RunVideoDataFetch(url, flat: true);
var duration = videoDataFetch.Data.Duration;
var tags = videoDataFetch.Data.Tags;
Console.WriteLine($"Duration: {duration}");
Console.WriteLine($"Tags: {string.Join(", ", tags)}");
await youtubeDl.RunAudioDownload(url, AudioConversionFormat.Opus);
Hi, is it possible to improve the fetch speed for video information in the following call somehow?
var res = await ytdl.RunVideoDataFetch("https://www.youtube.com/watch?v=_QdPW8JrYzQ");
I was wondering if you could limit the information you want to get.
For example, you wand just search for the title, thumbnail and the format list of a single video.
I am using .NetCore 6.0. When I try to run any operation wether that be RunVideoFetch or RunVideoDownload etc, nothing ever happens. If I pass in a function for the progress callback, I always remain at 0%. What I find more odd about this is the WPF demo does work and I have tried replicating that too but no luck.
YoutubeDL ytdl = new YoutubeDL();
ytdl.YoutubeDLPath = ytdlPath; //Both paths are valid, no error.
ytdl.FFmpegPath = ffmpegPath;
await ytdl.RunVideoDownload(
$"https://www.youtube.com/watch?v={videoID}",
progress: new Progress<DownloadProgress>(downloadProgress => Console.Write($"\r{downloadProgress.Progress * 100}%"))
);
//Never completes, no errors.
I am truly confused here as to why this isn't working.
I wanna know if it's possible to set the download name of the file to be download using RunVideoDownload() or RunAudioDownload()
Hi i am using the library and working locally, but not working when i publish to azure app service.
Asp Version
Asp core mvc 2.2
Azure app service
Error:
[youtube-dl ERROR] PermissionError: [WinError 5] Access is denied
I think this doesn't work for non-ASCII characters. Take racing into the night (夜に駆ける), for example. While it does save the file name correctly, taking RunResult.Data returns a file path of C:\...\bin\Debug\net6.0-windows\output\.mp3
. As you can see, I can no longer get the file path of the audio file.
I'm trying to figure out how to use Paths. From an example I saw for the CLI you can do -P "home:final/path" -P "temp:ssd/path" -o "file-name.%(ext)s"
. When I try this with the Paths property, I can only set it once not multiple times which is leading to my confusion on how to use it, or if it was forgotten to include multiple values?
The following exception will be thrown if you attempt to get the VideoData of a finished Premier and/or finished Live stream.
Faulty Package Version: 1.0.0-beta5
Thrown Exception:
Unhandled exception. System.InvalidCastException: Unable to cast object of type 'System.Int64' to type 'System.Double'.
at YoutubeDLSharp.Converters.UnixTimestampConverter.ReadJson(JsonReader reader, Type objectType, Nullable`1 existingValue, Boolean hasExistingValue, JsonSerializer serializer)
at Newtonsoft.Json.JsonConverter`1.ReadJson(JsonReader reader, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConvertable(JsonConverter converter, JsonReader reader, Type objectType, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.SetPropertyValue(JsonProperty property, JsonConverter propertyConverter, JsonContainerContract containerContract, JsonProperty containerProperty, JsonReader reader, Object target)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.PopulateObject(Object newObject, JsonReader reader, JsonObjectContract contract, JsonProperty member, String id)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateObject(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.CreateValueInternal(JsonReader reader, Type objectType, JsonContract contract, JsonProperty member, JsonContainerContract containerContract, JsonProperty containerMember, Object existingValue)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.Deserialize(JsonReader reader, Type objectType, Boolean checkAdditionalContent)
at Newtonsoft.Json.JsonSerializer.DeserializeInternal(JsonReader reader, Type objectType)
at Newtonsoft.Json.JsonConvert.DeserializeObject(String value, Type type, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value, JsonSerializerSettings settings)
at Newtonsoft.Json.JsonConvert.DeserializeObject[T](String value)
at YoutubeDLSharp.YoutubeDL.<>c__DisplayClass38_0.<RunVideoDataFetch>b__0(Object o, DataReceivedEventArgs e)
at YoutubeDLSharp.YoutubeDLProcess.<>c__DisplayClass24_0.<RunAsync>b__0(Object o, DataReceivedEventArgs e)
at System.Diagnostics.AsyncStreamReader.FlushMessageQueue(Boolean rethrowInNewThread)
--- End of stack trace from previous location ---
at System.Threading.ThreadPoolWorkQueue.Dispatch()
at System.Threading.PortableThreadPool.WorkerThread.WorkerThreadStart()
If you use a timelink, YoutubeDLSharp crashes with a JsonReaderException.
I work around this problem with this code:
if (videolink.Contains("t=") && videolink.ToLower().Contains("youtu")) { for (int i = 0; i < videolink.Length - 1; i++) { if (videolink[i] == 't' && videolink[i + 1] == '=') { videolink = videolink.Remove(i); } } }
It would be nice if you fix the problem :)
Hi,
I have an app that may run on windows, Android and IOS,
how to use YoutubeDLSharp cross-platform?
And if I only need links of videos, may I omit path or download of FFmpeg?
I noticed when looking at the VideoData
for a deserialised playlist, the availability of each entry was listed as Private
. I knew they were public videos and I checked the raw output from yt-dlp and it was returning null
. It seems even though Availability
is specified as nullable in VideoData
, the StringToEnumConverter
that deserializes it returns default(T)
when the value is null
. I would think if the enum is nullable, null should be returned instead.
Hello:
I found one web site, which I can see live sports video, and using the tool yt-dlp, I can download the underlying m3u8 link.
One example is something like:
yt-dlp https://m3u8.1proxy.xyz/media/g_18/playlist.m3u8 --downloader ffmpeg --referer "https://bingsport.com/"
You can find some live streams from the following URL:
(# can be a number from 1 to 20 or 30 depend on how many live games have for today).
https://bingsport.com/1proxy.php?id=g_#
Let me know if I can do the job like yt-dlp does with this repo with some type of custom arguments? As I need API library in C# for my project.
Thanks,
Hi there! I've been using this library and I'm very pleased.
However I have recently started using yt-dlp instead of youtube-dl (by just giving this library the path to yt-dlp instead of youtube-dl binary), and given this fork has arguments not supported in youtube-dl I would love to have the option to pass custom string arguments.
Thanks!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.