Compare commits
No commits in common. "c5fc9ac223337bdde8cb4553a38a9b09d74cba5c" and "5ffdccdfefd1096aa71345cbffec471f858ee2c3" have entirely different histories.
c5fc9ac223
...
5ffdccdfef
@ -103,7 +103,6 @@ public partial class MainTreePanel : Tree
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void OnMultiSelected(TreeItem item, long column, bool selected)
|
||||
@ -190,7 +189,6 @@ public partial class MainTreePanel : Tree
|
||||
_selectingNodes.Clear();
|
||||
|
||||
TreeItem root = CreateItem();
|
||||
_mapper[root] = new TreeNode(null);
|
||||
BuildTree(root, path);
|
||||
}
|
||||
|
||||
@ -199,39 +197,35 @@ public partial class MainTreePanel : Tree
|
||||
return _mapper.TryGetValue(item, out node);
|
||||
}
|
||||
|
||||
private bool BuildTree(TreeItem current, string path)
|
||||
private void BuildTree(TreeItem root, string path)
|
||||
{
|
||||
var isEmpty = true;
|
||||
var node = _mapper[current];
|
||||
|
||||
foreach (var filePath in Directory.GetFiles(path))
|
||||
var nodes = new Stack<(TreeItem node, string path)>();
|
||||
_mapper[root] = new TreeNode(null);
|
||||
nodes.Push((root, path));
|
||||
while (nodes.Count > 0)
|
||||
{
|
||||
isEmpty = false;
|
||||
var item = InitItem(filePath, false);
|
||||
var childNode = new TreeNode(item);
|
||||
node.AddNode(childNode);
|
||||
var child = CreateNode(current, item);
|
||||
_mapper[child] = childNode;
|
||||
}
|
||||
var node = nodes.Pop();
|
||||
var father = node.node;
|
||||
var fatherNode = _mapper[father];
|
||||
|
||||
foreach (var subDirPath in Directory.GetDirectories(path))
|
||||
{
|
||||
var item = InitItem(subDirPath, true);
|
||||
var childNode = new TreeNode(item);
|
||||
node.AddNode(childNode);
|
||||
var child = CreateNode(current, item);
|
||||
_mapper[child] = childNode;
|
||||
if (BuildTree(child, subDirPath))
|
||||
foreach (var filePath in Directory.GetFiles(node.path))
|
||||
{
|
||||
_mapper.Remove(child);
|
||||
child.Free();
|
||||
var item = InitItem(filePath, false);
|
||||
var childNode = new TreeNode(item);
|
||||
fatherNode.AddNode(childNode);
|
||||
var child = CreateNode(father, item);
|
||||
_mapper[child] = childNode;
|
||||
}
|
||||
else
|
||||
|
||||
foreach (var subDirPath in Directory.GetDirectories(node.path))
|
||||
{
|
||||
isEmpty = false;
|
||||
var item = InitItem(subDirPath, true);
|
||||
var childNode = new TreeNode(item);
|
||||
fatherNode.AddNode(childNode);
|
||||
var child = CreateNode(father, item);
|
||||
_mapper[child] = childNode;
|
||||
nodes.Push((child, subDirPath));
|
||||
}
|
||||
}
|
||||
|
||||
return isEmpty;
|
||||
}
|
||||
}
|
||||
|
||||
125
FileMover.cs
125
FileMover.cs
@ -1,125 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using Learn.Models;
|
||||
using Learn.Parsers;
|
||||
|
||||
namespace Learn;
|
||||
|
||||
public class FileMover(string targetPath)
|
||||
{
|
||||
private readonly HashSet<TreeNode> _visited = new ();
|
||||
|
||||
private string NumToString(int n)
|
||||
{
|
||||
if (n < 10) return "0" + n;
|
||||
return n.ToString();
|
||||
}
|
||||
|
||||
private bool TryGetPath(TreeNode node, out string path)
|
||||
{
|
||||
path = null;
|
||||
if (!node.TryGetValue(ItemFields.Key_Title, out var title, out _)) return false;
|
||||
if (!node.TryGetValue(ItemFields.Key_Season, out var season, out _)) return false;
|
||||
if (!node.TryGetValue(ItemFields.Key_Year, out var year, out _)) return false;
|
||||
|
||||
path = $"{title} ({year})/";
|
||||
|
||||
if (int.TryParse(season, out var seasonNum))
|
||||
{
|
||||
path += $"Season {seasonNum}";
|
||||
}
|
||||
else
|
||||
{
|
||||
path += season;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void MoveFile(TreeNode node)
|
||||
{
|
||||
var path = node.Info.MainInfo[ItemFields.MainKey_Path];
|
||||
|
||||
if (!node.TryGetValue(ItemFields.Key_Type, out var type, out _)) return;
|
||||
if (!node.TryGetValue(ItemFields.Key_Title, out var title, out _)) return;
|
||||
if (!node.TryGetValue(ItemFields.Key_Episode, out var episode, out _)) return;
|
||||
if (!node.TryGetValue(ItemFields.Key_Season, out var season, out _)) return;
|
||||
if (!node.TryGetValue(ItemFields.Key_Year, out var year, out _)) return;
|
||||
if (!TryGetPath(node, out var relativePath)) return;
|
||||
|
||||
var filenameParts = new List<string>();
|
||||
var metaParts = new List<string>();
|
||||
filenameParts.Add(title);
|
||||
filenameParts.Add($"({year})");
|
||||
|
||||
var seasonAndEpisodePart = "";
|
||||
if (int.TryParse(season, out var seasonNum))
|
||||
{
|
||||
seasonAndEpisodePart += $"S{NumToString(seasonNum)}";
|
||||
}
|
||||
var episodeNum = int.Parse(episode);
|
||||
seasonAndEpisodePart += $"E{NumToString(episodeNum)}";
|
||||
filenameParts.Add(seasonAndEpisodePart);
|
||||
|
||||
if (node.TryGetValue(ItemFields.Key_Group, out var group, out _))
|
||||
{
|
||||
metaParts.Add(group);
|
||||
}
|
||||
|
||||
if (type == ItemFields.ItemType.Subtitle.ToString())
|
||||
{
|
||||
if (node.TryGetValue(ItemFields.Key_SubtitleLanguage, out var subLang, out _))
|
||||
{
|
||||
metaParts.Add(subLang);
|
||||
}
|
||||
}
|
||||
|
||||
var filename = string.Join(" ", string.Join(" ", filenameParts), string.Join("", metaParts.Select(part => $"[{part}]")));
|
||||
filename += Path.GetExtension(path);
|
||||
var filePath = string.Join("/", targetPath, relativePath, filename);
|
||||
node.Info.Info["TargetPath"] = filePath;
|
||||
}
|
||||
|
||||
private void MoveExtra(TreeNode node)
|
||||
{
|
||||
if (!TryGetPath(node, out var relativePath)) return;
|
||||
|
||||
var path = node.Info.MainInfo[ItemFields.MainKey_Path];
|
||||
var name = Path.GetFileName(path);
|
||||
var target = string.Join("/", targetPath, relativePath, name);
|
||||
node.Info.Info["TargetPath"] = target;
|
||||
}
|
||||
|
||||
public void DoMove(TreeNode node)
|
||||
{
|
||||
if (_visited.Contains(node)) return;
|
||||
|
||||
string type;
|
||||
if (!node.TryGetValue(ItemFields.Key_Type, out type, out _))
|
||||
{
|
||||
type = ItemFields.ItemType.Unknown.ToString();
|
||||
}
|
||||
|
||||
if (type == ItemFields.ItemType.Extra.ToString())
|
||||
{
|
||||
MoveExtra(node);
|
||||
_visited.Add(node);
|
||||
return;
|
||||
}
|
||||
|
||||
if (node.Info.IsFolder())
|
||||
{
|
||||
foreach (var child in node.Children)
|
||||
{
|
||||
DoMove(child);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveFile(node);
|
||||
}
|
||||
|
||||
_visited.Add(node);
|
||||
}
|
||||
}
|
||||
@ -1 +0,0 @@
|
||||
uid://cbo6d0l8ax518
|
||||
47
Main.cs
47
Main.cs
@ -5,10 +5,8 @@ using System.IO;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Learn;
|
||||
using Learn.Component;
|
||||
using Learn.Config;
|
||||
using Learn.Models;
|
||||
using Learn.Parsers;
|
||||
using Learn.Utils;
|
||||
|
||||
@ -21,7 +19,6 @@ public partial class Main : Node
|
||||
[Export] private Button _openDirButton;
|
||||
[Export] private Button _doParseButton;
|
||||
[Export] private Button _doTMDBParseButton;
|
||||
[Export] private Button _doMoveButton;
|
||||
[Export] private Button _saveButton;
|
||||
[Export] private Button _resetButton;
|
||||
[Export] private Button _loadButton;
|
||||
@ -62,18 +59,9 @@ public partial class Main : Node
|
||||
_mainTreePanel.AddColumn(_columnText.Text,
|
||||
int.TryParse(_columnIndexText.Text, out var index) ? index : -1,
|
||||
int.TryParse(_columnWidthText.Text, out var width) ? width : -1);
|
||||
DoSave();
|
||||
};
|
||||
_removeColumnButton.Pressed += () =>
|
||||
{
|
||||
_mainTreePanel.RemoveColumn(_columnText.Text);
|
||||
DoSave();
|
||||
};
|
||||
_clearColumnButton.Pressed += () =>
|
||||
{
|
||||
_mainTreePanel.ClearColumns();
|
||||
DoSave();
|
||||
};
|
||||
_removeColumnButton.Pressed += () => _mainTreePanel.RemoveColumn(_columnText.Text);
|
||||
_clearColumnButton.Pressed += () => _mainTreePanel.ClearColumns();
|
||||
|
||||
_expandAllButton.Pressed += ExpandAll;
|
||||
_foldAllButton.Pressed += FoldAll;
|
||||
@ -83,7 +71,6 @@ public partial class Main : Node
|
||||
_doParseButton.Pressed += DoParse;
|
||||
_doTMDBParseButton.Pressed += DoTMDBParse;
|
||||
_saveButton.Pressed += DoSave;
|
||||
_doMoveButton.Pressed += DoMove;
|
||||
_resetButton.Pressed += DoReset;
|
||||
_loadButton.Pressed += LoadData;
|
||||
_reloadConfigButton.Pressed += ReloadConfig;
|
||||
@ -172,14 +159,7 @@ public partial class Main : Node
|
||||
|
||||
foreach (var node in _mainTreePanel.SelectingNodes)
|
||||
{
|
||||
try
|
||||
{
|
||||
await parser.Parse(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GD.Print(ex);
|
||||
}
|
||||
await parser.Parse(node);
|
||||
}
|
||||
|
||||
_doTMDBParseButton.Disabled = false;
|
||||
@ -198,14 +178,7 @@ public partial class Main : Node
|
||||
|
||||
if (_mainTreePanel.Query(root, out var node))
|
||||
{
|
||||
try
|
||||
{
|
||||
await parser.Parse(node);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
GD.Print(ex);
|
||||
}
|
||||
await parser.Parse(node);
|
||||
}
|
||||
|
||||
_doParseButton.Disabled = false;
|
||||
@ -216,18 +189,6 @@ public partial class Main : Node
|
||||
|
||||
private const string DataPath = "data.json";
|
||||
|
||||
private void DoMove()
|
||||
{
|
||||
var mover = new FileMover("");
|
||||
|
||||
foreach (var node in _mainTreePanel.SelectingNodes)
|
||||
{
|
||||
mover.DoMove(node);
|
||||
}
|
||||
|
||||
_mainTreePanel.UpdateColumns();
|
||||
}
|
||||
|
||||
private void DoSave()
|
||||
{
|
||||
_mainTreePanel.SaveData(DataPath);
|
||||
|
||||
@ -17,13 +17,12 @@ grow_vertical = 2
|
||||
[node name="FileDirDialog" type="FileDialog" parent="."]
|
||||
script = ExtResource("1_d2g23")
|
||||
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_doMoveButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
[node name="Main" type="Node" parent="." node_paths=PackedStringArray("_dirSelector", "_openDirButton", "_doParseButton", "_doTMDBParseButton", "_saveButton", "_resetButton", "_loadButton", "_reloadConfigButton", "_nodeInfoEditPanel", "_addKeyButton", "_removeKeyButton", "_inspectorPanel", "_mainTreePanel", "_columnIndexText", "_columnWidthText", "_columnText", "_addColumnButton", "_removeColumnButton", "_clearColumnButton", "_expandAllButton", "_foldAllButton")]
|
||||
script = ExtResource("2_0727o")
|
||||
_dirSelector = NodePath("../FileDirDialog")
|
||||
_openDirButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/ScanDir")
|
||||
_doParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoParse")
|
||||
_doTMDBParseButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoTMDBParse")
|
||||
_doMoveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作/DoMove")
|
||||
_saveButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Save")
|
||||
_resetButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Reset")
|
||||
_loadButton = NodePath("../MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/保存操作/Load")
|
||||
@ -109,11 +108,6 @@ layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
text = "搜刮选中部分"
|
||||
|
||||
[node name="DoMove" type="Button" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer/文件夹操作"]
|
||||
layout_mode = 2
|
||||
text = "整理选中部分
|
||||
"
|
||||
|
||||
[node name="保存操作" type="VBoxContainer" parent="MarginContainer/HSplitContainer/ScrollContainer/VBoxContainer2/FoldableContainer4/VBoxContainer2/TabContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
||||
@ -47,9 +47,6 @@ public static class ItemFields
|
||||
|
||||
public static string Key_TMDBID => "TMDBID";
|
||||
|
||||
public static string Key_Offset => "EpisodeOffset";
|
||||
|
||||
|
||||
public static ItemType Type(this Item item)
|
||||
{
|
||||
if (item.Info.TryGetValue(Key_Type, out var typeName))
|
||||
|
||||
@ -86,20 +86,12 @@ public class TMDBParser(Configs configs) : ItemParser
|
||||
return;
|
||||
}
|
||||
|
||||
var showInfo = await _client.GetTvShowAsync(result.Id, language: "zh-CN");
|
||||
|
||||
if (result.FirstAirDate != null)
|
||||
{
|
||||
node.Info.Info[ItemFields.Key_Year] = showInfo.FirstAirDate.Value.Year.ToString();
|
||||
node.Info.Info[ItemFields.Key_Year] = result.FirstAirDate.Value.Year.ToString();
|
||||
}
|
||||
|
||||
node.Info.Info[ItemFields.Key_Title] = showInfo.Name;
|
||||
node.Info.Info[ItemFields.Key_TMDBID] = showInfo.Id.ToString();
|
||||
node.Info.Info["SeasonInfo"] = string.Join(", ", showInfo.Seasons.Select(season => season.Name));
|
||||
|
||||
if (showInfo.Seasons.Count == 1)
|
||||
{
|
||||
node.Info.Info.TryAdd(ItemFields.Key_Season, "1");
|
||||
}
|
||||
node.Info.Info[ItemFields.Key_Title] = result.Name;
|
||||
node.Info.Info[ItemFields.Key_TMDBID] = result.Id.ToString();
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,10 @@
|
||||
## TODO
|
||||
|
||||
- [x] 添加匹配Season功能
|
||||
- [x] 添加剧集偏移功能
|
||||
- [x] 解析操作添加异常保护
|
||||
- [ ] 添加匹配Season功能
|
||||
- [ ] 添加剧集偏移功能
|
||||
- [ ] 解析操作添加异常保护
|
||||
- [ ] 实现Popout提示功能
|
||||
- [ ] 添加检查是否完全解析完成
|
||||
- 添加一个字段,如果是文件夹,就是文件夹下剩余未完全解析的数量;如果是文件,就是文件是否已经完全解析
|
||||
- 完全解析是指已经包含:Title、Episode、Season、TMDBID的剧集
|
||||
- [ ] 添加转移选中的项目,转移完成添加一个标记。有这个标记的被隐藏起来
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user