Skip to content

Commit

Permalink
refactor: Edited for CodeFactor suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: 陳鈞 <jim60105@gmail.com>
  • Loading branch information
jim60105 committed Dec 24, 2023
1 parent 9a214ad commit c016041
Show file tree
Hide file tree
Showing 6 changed files with 311 additions and 320 deletions.
31 changes: 8 additions & 23 deletions Download.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,28 @@
using YoutubeDLSharp;
using YoutubeDLSharp.Options;
using YoutubeSegmentDownloader.Extension;
using YoutubeSegmentDownloader.Models;
using YtdlpVideoData = YoutubeSegmentDownloader.Models.YtdlpVideoData.ytdlpVideoData;

namespace YoutubeSegmentDownloader;

internal class Download
internal class Download(string id,
float start,
float end,
DirectoryInfo outputDirectory,
string format,
string browser)
{
private readonly string id;
private string link
{
get => id.Contains('/')
? id
: @$"https://youtu.be/{id}";
}
private readonly float start;
private readonly float end;
private readonly DirectoryInfo outputDirectory;
private readonly string format;
private readonly string browser;

public bool finished = false;
public bool successed = false;
public string? outputFilePath = null;

public Download(string id,
float start,
float end,
DirectoryInfo outputDirectory,
string format,
string browser)
{
this.id = id;
this.start = start;
this.end = end;
this.outputDirectory = outputDirectory;
this.format = format;
this.browser = browser;
}

public async Task Start()
{
Log.Information("Start the download process...");
Expand Down
17 changes: 7 additions & 10 deletions Extension/YoutubeDLHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using YoutubeDLSharp;
using YoutubeDLSharp.Helpers;
using YoutubeDLSharp.Options;
using YoutubeSegmentDownloader.Models;
using YtdlpVideoData = YoutubeSegmentDownloader.Models.YtdlpVideoData.ytdlpVideoData;

namespace YoutubeSegmentDownloader.Extension;

Expand All @@ -28,7 +28,6 @@ public static async Task<RunResult<YtdlpVideoData>> RunVideoDataFetch_Alt(this Y
OptionSet overrideOptions = null)
#pragma warning restore CA1068 // CancellationToken 參數必須位於最後
{
#pragma warning disable IDE0017 // 簡化物件初始化
OptionSet opts = new()
{
IgnoreErrors = ytdl.IgnoreDownloadErrors,
Expand All @@ -42,13 +41,11 @@ public static async Task<RunResult<YtdlpVideoData>> RunVideoDataFetch_Alt(this Y
NoOverwrites = !ytdl.OverwriteFiles,
NoPart = true,
FfmpegLocation = Utils.GetFullPath(ytdl.FFmpegPath),
Exec = "echo outfile: {}"
Exec = "echo outfile: {}",
DumpSingleJson = true,
FlatPlaylist = flat,
WriteComments = fetchComments
};

opts.DumpSingleJson = true;
opts.FlatPlaylist = flat;
opts.WriteComments = fetchComments;
#pragma warning restore IDE0017 // 簡化物件初始化
if (overrideOptions != null)
{
opts = opts.OverrideOptions(overrideOptions);
Expand All @@ -66,8 +63,8 @@ public static async Task<RunResult<YtdlpVideoData>> RunVideoDataFetch_Alt(this Y
data = ChangeJsonStringSingleQuotesToDoubleQuotes().Replace(data, @"""$1""");
videoData = Newtonsoft.Json.JsonConvert.DeserializeObject<YtdlpVideoData>(data);
};
FieldInfo fieldInfo = typeof(YoutubeDLSharp.YoutubeDL).GetField("runner", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField);
(int code, string[] errors) = await (fieldInfo.GetValue(ytdl) as ProcessRunner).RunThrottled(youtubeDLProcess, new[] { url }, opts, ct);
FieldInfo fieldInfo = typeof(YoutubeDL).GetField("runner", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.SetField);
(int code, string[] errors) = await (fieldInfo.GetValue(ytdl) as ProcessRunner).RunThrottled(youtubeDLProcess, [url], opts, ct);
return new RunResult<YtdlpVideoData>(code == 0, errors, videoData);
}
#nullable enable
Expand Down
8 changes: 8 additions & 0 deletions GlobalSuppressions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.

using System.Diagnostics.CodeAnalysis;

[assembly: SuppressMessage("Maintainability", "CA1507:使用 nameof 表示符號名稱", Justification = "<暫止>", Scope = "member", Target = "~P:YoutubeSegmentDownloader.Models.YtdlpVideoData.HttpHeaders.Accept")]
Loading

0 comments on commit c016041

Please sign in to comment.