-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYoutubeExploder.cs
More file actions
63 lines (60 loc) · 1.92 KB
/
YoutubeExploder.cs
File metadata and controls
63 lines (60 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
using YoutubeExplode;
using YoutubeExplode.Videos;
using YoutubeExplode.Videos.Streams;
using System;
using System.Threading.Tasks;
using System.IO;
using System.Linq;
using Xamarin.MP4Transcoder;
namespace MauiApp1
{
internal class YoutubeExploder
{
public Action<double> progress;
public YoutubeClient youtube;
public YoutubeExploder()
{
youtube = new();
progress = ProgressMethod;
}
void ProgressMethod(double value)
{
}
public async Task<StreamManifest> GetManifestAsync(string link)
{
return await youtube.Videos.Streams.GetManifestAsync(link);
}
public async Task<Video> GetVideoInfoAsync(string link)
{
return await youtube.Videos.GetAsync(link);
}
public IStreamInfo GetAudioStream(StreamManifest streamManifest)
{
return streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate();
}
public IStreamInfo GetVideoStream(StreamManifest streamManifest, int resolution)
{
return streamManifest.GetVideoStreams()
.Where(s => s.Container == Container.Mp4)
.Where(s => s.VideoResolution.Height == resolution)
.First();
}
public async Task DownloadStreamAsync(IStreamInfo streamInfo, string path)
{
await youtube.Videos.Streams.DownloadAsync(
streamInfo,
path,
new Progress<double>(progress));
}
public async Task ConvertToMP3(string inPath, string outPath)
{
await Transcoder
.For720pFormat()
.ConvertAsync(new(inPath), new(outPath), progress);
}
public void removeVideo(string file)
{
File.Delete(file);
}
}
}