Skip to content

Commit

Permalink
Fix clips and ffmpeg path
Browse files Browse the repository at this point in the history
  • Loading branch information
lay295 committed Nov 20, 2020
1 parent ca18152 commit f399a14
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 13 deletions.
4 changes: 2 additions & 2 deletions TwitchDownloaderCLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ private static void DownloadVideo(Options inputOptions)
downloadOptions.CropBeginningTime = inputOptions.CropBeginningTime;
downloadOptions.CropEnding = inputOptions.CropEndingTime == 0.0 ? false : true;
downloadOptions.CropEndingTime = inputOptions.CropEndingTime;
downloadOptions.FfmpegPath = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : inputOptions.FfmpegPath;
downloadOptions.FfmpegPath = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : Path.GetFullPath(inputOptions.FfmpegPath);

VideoDownloader videoDownloader = new VideoDownloader(downloadOptions);
Progress<ProgressReport> progress = new Progress<ProgressReport>();
Expand Down Expand Up @@ -221,7 +221,7 @@ private static void RenderChat(Options inputOptions)
renderOptions.GenerateMask = inputOptions.GenerateMask;
renderOptions.InputArgs = inputOptions.InputArgs;
renderOptions.OutputArgs = inputOptions.OutputArgs;
renderOptions.FfmpegPath = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : inputOptions.FfmpegPath;
renderOptions.FfmpegPath = inputOptions.FfmpegPath == null || inputOptions.FfmpegPath == "" ? ffmpegPath : Path.GetFullPath(inputOptions.FfmpegPath);

ChatRenderer chatDownloader = new ChatRenderer(renderOptions);
Progress<ProgressReport> progress = new Progress<ProgressReport>();
Expand Down
15 changes: 9 additions & 6 deletions TwitchDownloaderCore/ChatRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,11 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
.Replace("{height}", renderOptions.ChatHeight.ToString()).Replace("{width}", renderOptions.ChatWidth.ToString())
.Replace("{save_path}", renderOptions.OutputFile).Replace("{max_int}", int.MaxValue.ToString());

string ffmpegFile = "";
if (renderOptions.FfmpegPath != "")
ffmpegFile = "ffmpeg";

var process = new Process
{
StartInfo =
{
FileName = ffmpegFile,
FileName = renderOptions.FfmpegPath,
Arguments = $"{inputArgs} {outputArgs}",
UseShellExecute = false,
CreateNoWindow = true,
Expand All @@ -214,6 +210,7 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
RedirectStandardError = true
}
};

//process.ErrorDataReceived += ErrorDataHandler;

process.Start();
Expand All @@ -234,7 +231,7 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
{
StartInfo =
{
FileName = ffmpegFile,
FileName = renderOptions.FfmpegPath,
Arguments = $"{inputArgs} {outputArgsMask}",
UseShellExecute = false,
CreateNoWindow = true,
Expand Down Expand Up @@ -427,6 +424,12 @@ private void RenderVideo(ChatRenderOptions renderOptions, Queue<TwitchComment> f
progress.Report(new ProgressReport() { reportType = ReportType.Log, data = $"FINISHED. RENDER TIME: {(int)stopwatch.Elapsed.TotalSeconds}s SPEED: {(duration / stopwatch.Elapsed.TotalSeconds).ToString("0.##")}x" });
process.WaitForExit();
}

private void ErrorDataHandler(object sender, DataReceivedEventArgs e)
{
Console.WriteLine(e.Data);
}

[MethodImpl(MethodImplOptions.NoOptimization | MethodImplOptions.NoInlining)]
private byte[] GetMaskBytes(SKBitmap bufferBitmap, ChatRenderOptions renderOptions)
{
Expand Down
1 change: 1 addition & 0 deletions TwitchDownloaderCore/TwitchDownloaderCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Jellyfin.SkiaSharp.NativeAssets.LinuxArm" Version="1.68.1" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.2" />
<PackageReference Include="SkiaSharp" Version="1.68.3" />
<PackageReference Include="SkiaSharp.NativeAssets.Linux" Version="1.68.3" />
Expand Down
6 changes: 3 additions & 3 deletions TwitchDownloaderCore/TwitchHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static async Task<JObject> GetVideoInfo(int videoId)
{
client.Encoding = Encoding.UTF8;
client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json");
client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko");
client.Headers.Add("Client-ID", "v8kfhyc2980it9e7t5hhc7baukzuj2");
string response = await client.DownloadStringTaskAsync("https://api.twitch.tv/kraken/videos/" + videoId);
JObject result = JObject.Parse(response);
return result;
Expand Down Expand Up @@ -55,7 +55,7 @@ public static async Task<JObject> GetClipInfo(object clipId)
using (WebClient client = new WebClient())
{
client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json");
client.Headers.Add("Client-ID", "kimne78kx3ncx6brgo4mv6wki5h1ko");
client.Headers.Add("Client-ID", "v8kfhyc2980it9e7t5hhc7baukzuj2");
string response = await client.DownloadStringTaskAsync(String.Format("https://api.twitch.tv/kraken/clips/{0}", clipId));
JObject result = JObject.Parse(response);
return result;
Expand Down Expand Up @@ -556,7 +556,7 @@ public static string GetStreamerName(int id)
using (WebClient client = new WebClient())
{
client.Headers.Add("Accept", "application/vnd.twitchtv.v5+json; charset=UTF-8");
client.Headers.Add("Client-Id", "kimne78kx3ncx6brgo4mv6wki5h1ko");
client.Headers.Add("Client-Id", "v8kfhyc2980it9e7t5hhc7baukzuj2");

JObject response = JObject.Parse(client.DownloadString("https://api.twitch.tv/kraken/users/" + id));
return response["name"].ToString();
Expand Down
6 changes: 6 additions & 0 deletions TwitchDownloaderCore/TwitchObjects/ChatRoot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,12 @@ public class Emotes
public List<FirstPartyEmoteData> firstParty { get; set; }
}

public class CommentResponse
{
public List<Comment> comments { get; set; }
public string _next { get; set; }
}

public class ChatRoot
{
public Streamer streamer { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions TwitchDownloaderCore/VideoDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,8 @@ await Task.Run(() =>
{
StartInfo =
{
FileName = Path.GetFullPath(downloadOptions.FfmpegPath),
Arguments = String.Format("-y -avoid_negative_ts make_zero -i \"{0}\" -analyzeduration {2} -probesize {2} -c:v copy \"{4}\"", Path.Combine(downloadFolder, "output.ts"), (seekTime - startOffset).ToString(), Int32.MaxValue, seekDuration.ToString(), Path.GetFullPath(downloadOptions.Filename)),
FileName = downloadOptions.FfmpegPath,
Arguments = String.Format("-y -avoid_negative_ts make_zero " + (downloadOptions.CropBeginning ? "-ss {1} " : "") + "-i \"{0}\" -analyzeduration {2} -probesize {2} " + (downloadOptions.CropEnding ? "-t {3} " : "") + "-c:v copy \"{4}\"", Path.Combine(downloadFolder, "output.ts"), (seekTime - startOffset).ToString(), Int32.MaxValue, seekDuration.ToString(), Path.GetFullPath(downloadOptions.Filename)),
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardInput = false,
Expand Down

0 comments on commit f399a14

Please sign in to comment.