Skip to content

Commit

Permalink
Implement new filename params support in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
ScrubN committed Nov 8, 2024
1 parent ad40002 commit 8cb8cbe
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 18 deletions.
16 changes: 11 additions & 5 deletions TwitchDownloaderWPF/PageChatDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public partial class PageChatDownload : Page
{
public DownloadType downloadType;
public string downloadId;
public int streamerId;
public string streamerId;
public string clipper;
public string clipperId;
public DateTime currentVideoTime;
public TimeSpan vodLength;
public int viewCount;
Expand Down Expand Up @@ -144,7 +146,9 @@ private async Task GetVideoInfo()
var videoTime = videoInfo.data.video.createdAt;
textCreatedAt.Text = Settings.Default.UTCVideoTime ? videoTime.ToString(CultureInfo.CurrentCulture) : videoTime.ToLocalTime().ToString(CultureInfo.CurrentCulture);
currentVideoTime = Settings.Default.UTCVideoTime ? videoTime : videoTime.ToLocalTime();
streamerId = int.Parse(videoInfo.data.video.owner.id);
streamerId = videoInfo.data.video.owner.id;
clipper = null;
clipperId = null;
viewCount = videoInfo.data.video.viewCount;
game = videoInfo.data.video.game?.displayName ?? Translations.Strings.UnknownGame;

Expand Down Expand Up @@ -193,7 +197,9 @@ private async Task GetVideoInfo()
textCreatedAt.Text = Settings.Default.UTCVideoTime ? clipCreatedAt.ToString(CultureInfo.CurrentCulture) : clipCreatedAt.ToLocalTime().ToString(CultureInfo.CurrentCulture);
currentVideoTime = Settings.Default.UTCVideoTime ? clipCreatedAt : clipCreatedAt.ToLocalTime();
textTitle.Text = clipInfo.data.clip.title;
streamerId = int.Parse(clipInfo.data.clip.broadcaster?.id ?? "-1");
streamerId = clipInfo.data.clip.broadcaster?.id;
clipper = clipInfo.data.clip.curator.displayName;
clipperId = clipInfo.data.clip.curator.id;
labelLength.Text = vodLength.ToString("c");
SetEnabled(true);

Expand Down Expand Up @@ -498,10 +504,10 @@ private async void SplitBtnDownload_Click(object sender, RoutedEventArgs e)

var saveFileDialog = new SaveFileDialog
{
FileName = FilenameService.GetFilename(Settings.Default.TemplateChat, textTitle.Text, downloadId, currentVideoTime, textStreamer.Text,
FileName = FilenameService.GetFilename(Settings.Default.TemplateChat, textTitle.Text, downloadId, currentVideoTime, textStreamer.Text, streamerId,
CheckTrimStart.IsChecked == true ? new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value) : TimeSpan.Zero,
CheckTrimEnd.IsChecked == true ? new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value) : vodLength,
viewCount, game)
viewCount, game, clipper, clipperId)
};

if (radioJson.IsChecked == true)
Expand Down
4 changes: 3 additions & 1 deletion TwitchDownloaderWPF/PageChatUpdate.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public partial class PageChatUpdate : Page
public string InputFile;
public ChatRoot ChatJsonInfo;
public string VideoId;
public string StreamerId;
public DateTime VideoCreatedAt;
public TimeSpan VideoLength;
public int ViewCount;
Expand Down Expand Up @@ -109,6 +110,7 @@ private async void btnBrowse_Click(object sender, RoutedEventArgs e)
: Translations.Strings.UnknownVideoLength;

VideoId = ChatJsonInfo.video.id ?? ChatJsonInfo.comments.FirstOrDefault()?.content_id ?? "-1";
StreamerId = ChatJsonInfo.streamer.id.ToString(CultureInfo.InvariantCulture);
ViewCount = ChatJsonInfo.video.viewCount;
Game = ChatJsonInfo.video.game ?? ChatJsonInfo.video.chapters.FirstOrDefault()?.gameDisplayName ?? Translations.Strings.UnknownGame;

Expand Down Expand Up @@ -497,7 +499,7 @@ private async void SplitBtnUpdate_Click(object sender, RoutedEventArgs e)
var saveFileDialog = new SaveFileDialog
{
FileName = FilenameService.GetFilename(Settings.Default.TemplateChat, textTitle.Text,
ChatJsonInfo.video.id ?? ChatJsonInfo.comments.FirstOrDefault()?.content_id ?? "-1", VideoCreatedAt, textStreamer.Text,
ChatJsonInfo.video.id ?? ChatJsonInfo.comments.FirstOrDefault()?.content_id ?? "-1", VideoCreatedAt, textStreamer.Text, StreamerId,
checkStart.IsChecked == true ? new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value) : TimeSpan.FromSeconds(double.IsNegative(ChatJsonInfo.video.start) ? 0.0 : ChatJsonInfo.video.start),
checkEnd.IsChecked == true ? new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value) : VideoLength,
ViewCount, Game)
Expand Down
9 changes: 8 additions & 1 deletion TwitchDownloaderWPF/PageClipDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace TwitchDownloaderWPF
public partial class PageClipDownload : Page
{
public string clipId = "";
public string streamerId;
public string clipper;
public string clipperId;
public DateTime currentVideoTime;
public TimeSpan clipLength;
public int viewCount;
Expand Down Expand Up @@ -71,6 +74,9 @@ private async Task GetClipInfo()

clipLength = TimeSpan.FromSeconds(taskClipInfo.Result.data.clip.durationSeconds);
textStreamer.Text = clipData.data.clip.broadcaster?.displayName ?? Translations.Strings.UnknownUser;
streamerId = clipData.data.clip.broadcaster?.id;
clipper = clipData.data.clip.curator.displayName;
clipperId = clipData.data.clip.curator.id;
var clipCreatedAt = clipData.data.clip.createdAt;
textCreatedAt.Text = Settings.Default.UTCVideoTime ? clipCreatedAt.ToString(CultureInfo.CurrentCulture) : clipCreatedAt.ToLocalTime().ToString(CultureInfo.CurrentCulture);
currentVideoTime = Settings.Default.UTCVideoTime ? clipCreatedAt : clipCreatedAt.ToLocalTime();
Expand Down Expand Up @@ -201,7 +207,8 @@ private async void SplitBtnDownload_Click(object sender, RoutedEventArgs e)
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = "MP4 Files | *.mp4",
FileName = FilenameService.GetFilename(Settings.Default.TemplateClip, textTitle.Text, clipId, currentVideoTime, textStreamer.Text, TimeSpan.Zero, clipLength, viewCount, game) + ".mp4"
FileName = FilenameService.GetFilename(Settings.Default.TemplateClip, textTitle.Text, clipId, currentVideoTime, textStreamer.Text, streamerId, TimeSpan.Zero, clipLength, viewCount, game, clipper,
clipperId) + ".mp4"
};
if (saveFileDialog.ShowDialog() != true)
{
Expand Down
6 changes: 4 additions & 2 deletions TwitchDownloaderWPF/PageVodDownload.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public partial class PageVodDownload : Page
public TimeSpan vodLength;
public int viewCount;
public string game;
public string streamerId;
private CancellationTokenSource _cancellationTokenSource;

public PageVodDownload()
Expand Down Expand Up @@ -138,6 +139,7 @@ private async Task GetVideoInfo()

vodLength = TimeSpan.FromSeconds(taskVideoInfo.Result.data.video.lengthSeconds);
textStreamer.Text = taskVideoInfo.Result.data.video.owner.displayName;
streamerId = taskVideoInfo.Result.data.video.owner.id;
textTitle.Text = taskVideoInfo.Result.data.video.title;
var videoCreatedAt = taskVideoInfo.Result.data.video.createdAt;
textCreatedAt.Text = Settings.Default.UTCVideoTime ? videoCreatedAt.ToString(CultureInfo.CurrentCulture) : videoCreatedAt.ToLocalTime().ToString(CultureInfo.CurrentCulture);
Expand Down Expand Up @@ -203,7 +205,7 @@ public VideoDownloadOptions GetOptions(string filename, string folder)
ThrottleKib = Settings.Default.DownloadThrottleEnabled
? Settings.Default.MaximumBandwidthKib
: -1,
Filename = filename ?? Path.Combine(folder, FilenameService.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text,
Filename = filename ?? Path.Combine(folder, FilenameService.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text, streamerId,
checkStart.IsChecked == true ? new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value) : TimeSpan.Zero,
checkEnd.IsChecked == true ? new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value) : vodLength,
viewCount, game) + FilenameService.GuessVodFileExtension(comboQuality.Text)),
Expand Down Expand Up @@ -422,7 +424,7 @@ private async void SplitBtnDownloader_Click(object sender, RoutedEventArgs e)
SaveFileDialog saveFileDialog = new SaveFileDialog
{
Filter = comboQuality.Text.Contains("Audio", StringComparison.OrdinalIgnoreCase) ? "M4A Files | *.m4a" : "MP4 Files | *.mp4",
FileName = FilenameService.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text,
FileName = FilenameService.GetFilename(Settings.Default.TemplateVod, textTitle.Text, currentVideoId.ToString(), currentVideoTime, textStreamer.Text, streamerId,
checkStart.IsChecked == true ? new TimeSpan((int)numStartHour.Value, (int)numStartMinute.Value, (int)numStartSecond.Value) : TimeSpan.Zero,
checkEnd.IsChecked == true ? new TimeSpan((int)numEndHour.Value, (int)numEndMinute.Value, (int)numEndSecond.Value) : vodLength,
viewCount, game) + FilenameService.GuessVodFileExtension(comboQuality.Text)
Expand Down
3 changes: 3 additions & 0 deletions TwitchDownloaderWPF/TwitchTasks/TaskData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ public class TaskData
{
public string Id { get; set; }
public string Streamer { get; set; }
public string StreamerId { get; set; }
public string Clipper { get; set; }
public string ClipperId { get; set; }
public string Title { get; set; }
public ImageSource Thumbnail { get; set; }
public DateTime Time { get; set; }
Expand Down
20 changes: 11 additions & 9 deletions TwitchDownloaderWPF/WindowQueueOptions.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
ClipDownloadOptions downloadOptions = new ClipDownloadOptions
{
Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateClip, clipDownloadPage.textTitle.Text, clipDownloadPage.clipId,
clipDownloadPage.currentVideoTime, clipDownloadPage.textStreamer.Text, TimeSpan.Zero, clipDownloadPage.clipLength,
clipDownloadPage.viewCount, clipDownloadPage.game) + ".mp4"),
clipDownloadPage.currentVideoTime, clipDownloadPage.textStreamer.Text, clipDownloadPage.streamerId, TimeSpan.Zero, clipDownloadPage.clipLength,
clipDownloadPage.viewCount, clipDownloadPage.game, clipDownloadPage.clipper, clipDownloadPage.clipId) + ".mp4"),
Id = clipDownloadPage.clipId,
Quality = clipDownloadPage.comboQuality.Text,
ThrottleKib = Settings.Default.DownloadThrottleEnabled
Expand Down Expand Up @@ -301,8 +301,8 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
chatOptions.TimeFormat = TimestampFormat.Relative;
chatOptions.EmbedData = checkEmbed.IsChecked.GetValueOrDefault();
chatOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateChat, downloadTask.Info.Title, chatOptions.Id,
clipDownloadPage.currentVideoTime, clipDownloadPage.textStreamer.Text, TimeSpan.Zero, clipDownloadPage.clipLength,
clipDownloadPage.viewCount, clipDownloadPage.game) + "." + chatOptions.FileExtension);
clipDownloadPage.currentVideoTime, clipDownloadPage.textStreamer.Text, clipDownloadPage.streamerId, TimeSpan.Zero, clipDownloadPage.clipLength,
clipDownloadPage.viewCount, clipDownloadPage.game, clipDownloadPage.clipper, clipDownloadPage.clipId) + "." + chatOptions.FileExtension);
chatOptions.FileCollisionCallback = HandleFileCollisionCallback;

ChatDownloadTask chatTask = new ChatDownloadTask
Expand Down Expand Up @@ -377,6 +377,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)

ChatDownloadOptions chatOptions = MainWindow.pageChatDownload.GetOptions(null);
chatOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateChat, chatDownloadPage.textTitle.Text, chatOptions.Id,chatDownloadPage.currentVideoTime, chatDownloadPage.textStreamer.Text,
chatDownloadPage.streamerId,
chatOptions.TrimBeginning ? TimeSpan.FromSeconds(chatOptions.TrimBeginningTime) : TimeSpan.Zero,
chatOptions.TrimEnding ? TimeSpan.FromSeconds(chatOptions.TrimEndingTime) : chatDownloadPage.vodLength,
chatDownloadPage.viewCount, chatDownloadPage.game) + "." + chatOptions.FileExtension);
Expand Down Expand Up @@ -449,6 +450,7 @@ private void btnQueue_Click(object sender, RoutedEventArgs e)
ChatUpdateOptions chatOptions = MainWindow.pageChatUpdate.GetOptions(null);
chatOptions.InputFile = chatUpdatePage.InputFile;
chatOptions.OutputFile = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateChat, chatUpdatePage.textTitle.Text, chatUpdatePage.VideoId, chatUpdatePage.VideoCreatedAt, chatUpdatePage.textStreamer.Text,
chatUpdatePage.StreamerId,
chatOptions.TrimBeginning ? TimeSpan.FromSeconds(chatOptions.TrimBeginningTime) : TimeSpan.Zero,
chatOptions.TrimEnding ? TimeSpan.FromSeconds(chatOptions.TrimEndingTime) : chatUpdatePage.VideoLength,
chatUpdatePage.ViewCount, chatUpdatePage.Game) + "." + chatOptions.FileExtension);
Expand Down Expand Up @@ -574,7 +576,7 @@ private void EnqueueDataList()
: -1,
FileCollisionCallback = HandleFileCollisionCallback,
};
downloadOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateVod, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer,
downloadOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateVod, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer, taskData.StreamerId,
downloadOptions.TrimBeginning ? downloadOptions.TrimBeginningTime : TimeSpan.Zero,
downloadOptions.TrimEnding ? downloadOptions.TrimEndingTime : TimeSpan.FromSeconds(taskData.Length),
taskData.Views, taskData.Game) + FilenameService.GuessVodFileExtension(downloadOptions.Quality));
Expand All @@ -600,8 +602,8 @@ private void EnqueueDataList()
{
Id = taskData.Id,
Quality = (ComboPreferredQuality.SelectedItem as ComboBoxItem)?.Content as string,
Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateClip, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer,
TimeSpan.Zero, TimeSpan.FromSeconds(taskData.Length), taskData.Views, taskData.Game) + ".mp4"),
Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateClip, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer, taskData.StreamerId,
TimeSpan.Zero, TimeSpan.FromSeconds(taskData.Length), taskData.Views, taskData.Game, taskData.Clipper, taskData.ClipperId) + ".mp4"),
ThrottleKib = Settings.Default.DownloadThrottleEnabled
? Settings.Default.MaximumBandwidthKib
: -1,
Expand Down Expand Up @@ -646,10 +648,10 @@ private void EnqueueDataList()
downloadOptions.DownloadFormat = ChatFormat.Html;
else
downloadOptions.DownloadFormat = ChatFormat.Text;
downloadOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateChat, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer,
downloadOptions.Filename = Path.Combine(folderPath, FilenameService.GetFilename(Settings.Default.TemplateChat, taskData.Title, taskData.Id, taskData.Time, taskData.Streamer, taskData.StreamerId,
downloadOptions.TrimBeginning ? TimeSpan.FromSeconds(downloadOptions.TrimBeginningTime) : TimeSpan.Zero,
downloadOptions.TrimEnding ? TimeSpan.FromSeconds(downloadOptions.TrimEndingTime) : TimeSpan.FromSeconds(taskData.Length),
taskData.Views, taskData.Game) + "." + downloadOptions.FileExtension);
taskData.Views, taskData.Game, taskData.Clipper, taskData.ClipperId) + "." + downloadOptions.FileExtension);

ChatDownloadTask downloadTask = new ChatDownloadTask
{
Expand Down
4 changes: 4 additions & 0 deletions TwitchDownloaderWPF/WindowUrlList.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = thumbnail,
Title = videoInfo.title,
Streamer = videoInfo.owner.displayName,
StreamerId = videoInfo.owner.id,
Time = Settings.Default.UTCVideoTime ? videoInfo.createdAt : videoInfo.createdAt.ToLocalTime(),
Views = videoInfo.viewCount,
Game = videoInfo.game?.displayName ?? Translations.Strings.UnknownGame,
Expand Down Expand Up @@ -137,6 +138,9 @@ private async void btnQueue_Click(object sender, RoutedEventArgs e)
Thumbnail = thumbnail,
Title = clipInfo.title,
Streamer = clipInfo.broadcaster?.displayName ?? Translations.Strings.UnknownUser,
StreamerId = clipInfo.broadcaster?.id,
Clipper = clipInfo.curator.displayName,
ClipperId = clipInfo.curator.id,
Time = Settings.Default.UTCVideoTime ? clipInfo.createdAt : clipInfo.createdAt.ToLocalTime(),
Views = clipInfo.viewCount,
Game = clipInfo.game?.displayName ?? Translations.Strings.UnknownGame,
Expand Down

0 comments on commit 8cb8cbe

Please sign in to comment.