Skip to content

Commit

Permalink
yt works
Browse files Browse the repository at this point in the history
  • Loading branch information
jooapa committed Dec 4, 2023
1 parent 9e9e00e commit e0ce9bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
40 changes: 19 additions & 21 deletions src/Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,42 +24,43 @@ public static string DownloadSong(string url2) {
return songPath;
}

private static async Task DownloadYoutubeTrackAsync(string urlGetDownloadUrlAsync)
private static async Task DownloadYoutubeTrackAsync(string url)
{
string formattedUrl = FormatUrlForFilename(urlGetDownloadUrlAsync);
string formattedUrl = FormatUrlForFilename(url);

songPath = Path.Combine(
Utils.jammerPath,
Environment.GetFolderPath(Environment.SpecialFolder.UserProfile),
"jammer",
formattedUrl
);

if (File.Exists(songPath))
{
// Console.WriteLine("Youtube file already exists");
Console.WriteLine("Youtube file already exists");
return;
}
try
{
Console.WriteLine("Downloading: " + urlGetDownloadUrlAsync);
var youtube = new YoutubeClient();
var streamManifest = await youtube.Videos.Streams.GetManifestAsync(urlGetDownloadUrlAsync);
var streamInfo = streamManifest.GetAudioStreams().GetWithHighestBitrate();
if (streamInfo == null)
var streamManifest = await youtube.Videos.Streams.GetManifestAsync(url);
var streamInfo = streamManifest.GetAudioOnlyStreams().GetWithHighestBitrate();
if (streamInfo != null)
{
Console.WriteLine("No audio streams available");
return;
await youtube.Videos.Streams.DownloadAsync(streamInfo, songPath);
}
else
{
Console.WriteLine("This video has no audio streams");
}
// download song
await youtube.Videos.Streams.DownloadAsync(streamInfo, songPath);

songPath = Utils.jammerPath + formattedUrl;
// Console.WriteLine("Downloaded: " + formattedUrl + " to " + songPath);
songPath = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile) + "\\jammer\\" + formattedUrl;
Console.WriteLine("Downloaded: " + formattedUrl + " to " + songPath);
}
catch (Exception ex)
{
Console.WriteLine("Youtube Error: " + ex.Message);
Console.WriteLine("Error: " + ex.Message);
Console.ReadLine();
}
Console.ReadLine();
}

public static async Task DownloadSoundCloudTrackAsync(string url) {
Expand All @@ -74,7 +75,6 @@ public static async Task DownloadSoundCloudTrackAsync(string url) {

if (File.Exists(songPath))
{
Debug.dprint("Youtube file already exists");
return;
}
url = oldUrl;
Expand Down Expand Up @@ -128,7 +128,6 @@ public static string FormatUrlForFilename(string url)
{
// Console.WriteLine("Formatting url for filename: " + url);
if (URL.isValidSoundCloudPlaylist(url)) {
Console.WriteLine("Soundcloud playlist");
return "Soundcloud Playlist";
}
else if (URL.IsValidSoundcloudSong(url))
Expand All @@ -143,17 +142,16 @@ public static string FormatUrlForFilename(string url)
}
else if (URL.IsValidYoutubeSong(url))
{
Console.WriteLine("Youtube song");
int index = url.IndexOf("&");
if (index > 0)
{
url = url.Substring(0, index);
}
url.Replace("?", " ");
}
string formattedUrl = url.Replace("https://", "")
.Replace("/", " ")
.Replace("-", " ");
.Replace("-", " ")
.Replace("?", " ");

return formattedUrl + ".mp3";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Start.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public static void Run(string[] args)
if (Utils.songs.Length == 0) {
AnsiConsole.MarkupLine("[red]No arguments given, please enter a URL or file path[/]");
Utils.songs = new string[1];
Utils.songs[0] = AnsiConsole.Ask<string>("Enter URL or file path");
Utils.songs[0] = AnsiConsole.Ask<string>("Enter URL or file path: ");
}
// Play.InitAudio();
StartPlaying();
Expand Down

0 comments on commit e0ce9bb

Please sign in to comment.