Skip to content

Commit

Permalink
Fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
sorashi committed Nov 26, 2017
1 parent 5360680 commit cebaff5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
17 changes: 15 additions & 2 deletions youtube-play/LinkResolver.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using System;
using Newtonsoft.Json.Linq;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
Expand Down Expand Up @@ -55,6 +56,7 @@ public Video(string id, string title = null) {
public async Task<VideoFormat> GetBestStreamableAudioFormat() {
if (bestStreamableAudioFormat != null) return bestStreamableAudioFormat;
var videoFormats = await GetFormats();
if (videoFormats == null) return null;
// at first try to find audio only
var audioOnly = videoFormats.Where(x => x.Note == "DASH audio" &&
(x.Extension == "webm" || x.Extension == "m4a"));
Expand Down Expand Up @@ -103,11 +105,22 @@ public Task<IEnumerable<VideoFormat>> GetFormats() {
Arguments = "-j " + Id,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
}
};
iteratorProcess.Start();
var jo = JObject.Parse(iteratorProcess.StandardOutput.ReadToEnd());
var stdout = iteratorProcess.StandardOutput.ReadToEnd();
var stderr = iteratorProcess.StandardError.ReadToEnd();
iteratorProcess.WaitForExit();
var code = iteratorProcess.ExitCode;
if (code != 0) {
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("An error occured while resolving the video link:\n" + stderr);
Console.ResetColor();
return null;
}
var jo = JObject.Parse(stdout);
return ResolveFormats(jo["formats"].ToString());
});
Formats = t;
Expand Down
5 changes: 4 additions & 1 deletion youtube-play/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ public Task StartPlaying(int volume = 20) {
}

public async Task<int> AddToQueue(LinkResolver.Video video) {
await video.GetBestStreamableAudioFormat();
if (await video.GetBestStreamableAudioFormat() == null) {
Console.WriteLine("Skipped " + video.Title);
return playQueue.Count;
}
Console.WriteLine("Link resolved: " + video.Title);
playQueue.Enqueue(video);
return playQueue.Count;
Expand Down
8 changes: 5 additions & 3 deletions youtube-play/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ private static async Task MainAsync() {
if (!args.Any()) {
Console.WriteLine("\nUsage:");
Console.WriteLine("youtube-play <video/playlist/channel link> (one or more in a row)");
Console.WriteLine("Instead of a link, you can also pass at any time a '-f <filename>' option with a link on each line of the file");
Console.WriteLine(
"Instead of a link, you can also pass at any time a '-f <filename>' option with a link on each line of the file");
return;
}
var arguments = ArgumentEnumerator(args);
Expand All @@ -62,9 +63,10 @@ private static async Task MainAsync() {
Console.WriteLine("Entering loop");
while (links.MoveNext()) {
#if DEBUG
Console.WriteLine("[Debug] Current link: " + links.Current);
Console.WriteLine("[Debug] Current link: " + links.Current.Id);
#endif
await player.AddToQueue(links.Current);
var count = await player.AddToQueue(links.Current);
if (count <= 0) continue;
if (first) {
first = false;
Console.WriteLine("Starting to play");
Expand Down
4 changes: 2 additions & 2 deletions youtube-play/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.11.0")]
[assembly: AssemblyFileVersion("0.1.11.0")]
[assembly: AssemblyVersion("0.1.21.1")]
[assembly: AssemblyFileVersion("0.1.21.1")]

0 comments on commit cebaff5

Please sign in to comment.