├── .gitattributes ├── .gitignore ├── App.config ├── FormMain.Designer.cs ├── FormMain.cs ├── FormMain.resx ├── FormSource.Designer.cs ├── FormSource.cs ├── FormSource.resx ├── List ├── ListView.cs └── ListViewItem.cs ├── MagnetX.csproj ├── MagnetX.png ├── MagnetX.sln ├── Program.cs ├── Properties └── AssemblyInfo.cs ├── README.md ├── Searcher ├── HistorySearcher │ ├── HistoryRecorder.cs │ ├── HistorySearcher.cs │ └── Utils.cs ├── Searcher.cs └── WebSearcher │ ├── Bt177WebSearcher.cs │ ├── BtcatWebSearcher.cs │ ├── BtsoWebSearcher.cs │ ├── BturlWebSearcher.cs │ ├── CilibaWebSearcher.cs │ ├── CililianxWebSearcher.cs │ ├── CilimaoWebSearcher.cs │ ├── CnbtkittyWebSearcher.cs │ ├── SomagentWebSearcher.cs │ ├── WtsqyyWebSearcher.cs │ ├── ZhizhucWebSearcher.cs │ ├── _SimpleWebSearcher.cs │ └── _WebSearcher.cs ├── Settings.cs └── Utils.cs /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | [Xx]64/ 19 | [Xx]86/ 20 | [Bb]uild/ 21 | bld/ 22 | [Bb]in/ 23 | [Oo]bj/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | 85 | # Visual Studio profiler 86 | *.psess 87 | *.vsp 88 | *.vspx 89 | *.sap 90 | 91 | # TFS 2012 Local Workspace 92 | $tf/ 93 | 94 | # Guidance Automation Toolkit 95 | *.gpState 96 | 97 | # ReSharper is a .NET coding add-in 98 | _ReSharper*/ 99 | *.[Rr]e[Ss]harper 100 | *.DotSettings.user 101 | 102 | # JustCode is a .NET coding add-in 103 | .JustCode 104 | 105 | # TeamCity is a build add-in 106 | _TeamCity* 107 | 108 | # DotCover is a Code Coverage Tool 109 | *.dotCover 110 | 111 | # NCrunch 112 | _NCrunch_* 113 | .*crunch*.local.xml 114 | nCrunchTemp_* 115 | 116 | # MightyMoose 117 | *.mm.* 118 | AutoTest.Net/ 119 | 120 | # Web workbench (sass) 121 | .sass-cache/ 122 | 123 | # Installshield output folder 124 | [Ee]xpress/ 125 | 126 | # DocProject is a documentation generator add-in 127 | DocProject/buildhelp/ 128 | DocProject/Help/*.HxT 129 | DocProject/Help/*.HxC 130 | DocProject/Help/*.hhc 131 | DocProject/Help/*.hhk 132 | DocProject/Help/*.hhp 133 | DocProject/Help/Html2 134 | DocProject/Help/html 135 | 136 | # Click-Once directory 137 | publish/ 138 | 139 | # Publish Web Output 140 | *.[Pp]ublish.xml 141 | *.azurePubxml 142 | 143 | # TODO: Un-comment the next line if you do not want to checkin 144 | # your web deploy settings because they may include unencrypted 145 | # passwords 146 | #*.pubxml 147 | *.publishproj 148 | 149 | # NuGet Packages 150 | *.nupkg 151 | # The packages folder can be ignored because of Package Restore 152 | **/packages/* 153 | # except build/, which is used as an MSBuild target. 154 | !**/packages/build/ 155 | # Uncomment if necessary however generally it will be regenerated when needed 156 | #!**/packages/repositories.config 157 | # NuGet v3's project.json files produces more ignoreable files 158 | *.nuget.props 159 | *.nuget.targets 160 | 161 | # Microsoft Azure Build Output 162 | csx/ 163 | *.build.csdef 164 | 165 | # Microsoft Azure Emulator 166 | ecf/ 167 | rcf/ 168 | 169 | # Windows Store app package directory 170 | AppPackages/ 171 | BundleArtifacts/ 172 | 173 | # Visual Studio cache files 174 | # files ending in .cache can be ignored 175 | *.[Cc]ache 176 | # but keep track of directories ending in .cache 177 | !*.[Cc]ache/ 178 | 179 | # Others 180 | ClientBin/ 181 | [Ss]tyle[Cc]op.* 182 | ~$* 183 | *~ 184 | *.dbmdl 185 | *.dbproj.schemaview 186 | *.pfx 187 | *.publishsettings 188 | node_modules/ 189 | orleans.codegen.cs 190 | 191 | # RIA/Silverlight projects 192 | Generated_Code/ 193 | 194 | # Backup & report files from converting an old project file 195 | # to a newer Visual Studio version. Backup files are not needed, 196 | # because we have git ;-) 197 | _UpgradeReport_Files/ 198 | Backup*/ 199 | UpgradeLog*.XML 200 | UpgradeLog*.htm 201 | 202 | # SQL Server files 203 | *.mdf 204 | *.ldf 205 | 206 | # Business Intelligence projects 207 | *.rdl.data 208 | *.bim.layout 209 | *.bim_*.settings 210 | 211 | # Microsoft Fakes 212 | FakesAssemblies/ 213 | 214 | # GhostDoc plugin setting file 215 | *.GhostDoc.xml 216 | 217 | # Node.js Tools for Visual Studio 218 | .ntvs_analysis.dat 219 | 220 | # Visual Studio 6 build log 221 | *.plg 222 | 223 | # Visual Studio 6 workspace options file 224 | *.opt 225 | 226 | # Visual Studio LightSwitch build output 227 | **/*.HTMLClient/GeneratedArtifacts 228 | **/*.DesktopClient/GeneratedArtifacts 229 | **/*.DesktopClient/ModelManifest.xml 230 | **/*.Server/GeneratedArtifacts 231 | **/*.Server/ModelManifest.xml 232 | _Pvt_Extensions 233 | 234 | # LightSwitch generated files 235 | GeneratedArtifacts/ 236 | ModelManifest.xml 237 | 238 | # Paket dependency manager 239 | .paket/paket.exe 240 | 241 | # FAKE - F# Make 242 | .fake/ 243 | -------------------------------------------------------------------------------- /App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /FormMain.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MagnetX 2 | { 3 | partial class FormMain 4 | { 5 | /// 6 | /// 必需的设计器变量。 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// 清理所有正在使用的资源。 12 | /// 13 | /// 如果应释放托管资源,为 true;否则为 false。 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows 窗体设计器生成的代码 24 | 25 | /// 26 | /// 设计器支持所需的方法 - 不要修改 27 | /// 使用代码编辑器修改此方法的内容。 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.components = new System.ComponentModel.Container(); 32 | this.textBoxWord = new System.Windows.Forms.TextBox(); 33 | this.buttonSearch = new System.Windows.Forms.Button(); 34 | this.contextMenuStripResult = new System.Windows.Forms.ContextMenuStrip(this.components); 35 | this.复制ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 36 | this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); 37 | this.资源名ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 38 | this.menuStrip1 = new System.Windows.Forms.MenuStrip(); 39 | this.功能ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 40 | this.数据源ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 41 | this.githubToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 42 | this.toolStripSeparator2 = new System.Windows.Forms.ToolStripSeparator(); 43 | this.保存纪录ToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); 44 | this.listViewResults = new MagnetX.List.ListView(); 45 | this.columnHeaderName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 46 | this.columnHeaderSize = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 47 | this.columnHeaderFrom = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 48 | this.contextMenuStripResult.SuspendLayout(); 49 | this.menuStrip1.SuspendLayout(); 50 | this.SuspendLayout(); 51 | // 52 | // textBoxWord 53 | // 54 | this.textBoxWord.Location = new System.Drawing.Point(12, 28); 55 | this.textBoxWord.Name = "textBoxWord"; 56 | this.textBoxWord.Size = new System.Drawing.Size(778, 21); 57 | this.textBoxWord.TabIndex = 0; 58 | this.textBoxWord.KeyDown += new System.Windows.Forms.KeyEventHandler(this.textBoxWord_KeyDown); 59 | // 60 | // buttonSearch 61 | // 62 | this.buttonSearch.Location = new System.Drawing.Point(796, 28); 63 | this.buttonSearch.Name = "buttonSearch"; 64 | this.buttonSearch.Size = new System.Drawing.Size(79, 21); 65 | this.buttonSearch.TabIndex = 1; 66 | this.buttonSearch.Text = "搜索"; 67 | this.buttonSearch.UseVisualStyleBackColor = true; 68 | this.buttonSearch.Click += new System.EventHandler(this.buttonSearch_Click); 69 | // 70 | // contextMenuStripResult 71 | // 72 | this.contextMenuStripResult.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 73 | this.复制ToolStripMenuItem, 74 | this.toolStripSeparator1, 75 | this.资源名ToolStripMenuItem}); 76 | this.contextMenuStripResult.Name = "contextMenuStripResult"; 77 | this.contextMenuStripResult.Size = new System.Drawing.Size(125, 54); 78 | // 79 | // 复制ToolStripMenuItem 80 | // 81 | this.复制ToolStripMenuItem.Name = "复制ToolStripMenuItem"; 82 | this.复制ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); 83 | this.复制ToolStripMenuItem.Text = "复制链接"; 84 | this.复制ToolStripMenuItem.Click += new System.EventHandler(this.复制ToolStripMenuItem_Click); 85 | // 86 | // toolStripSeparator1 87 | // 88 | this.toolStripSeparator1.Name = "toolStripSeparator1"; 89 | this.toolStripSeparator1.Size = new System.Drawing.Size(121, 6); 90 | // 91 | // 资源名ToolStripMenuItem 92 | // 93 | this.资源名ToolStripMenuItem.Enabled = false; 94 | this.资源名ToolStripMenuItem.Name = "资源名ToolStripMenuItem"; 95 | this.资源名ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); 96 | this.资源名ToolStripMenuItem.Text = "资源名"; 97 | // 98 | // menuStrip1 99 | // 100 | this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { 101 | this.功能ToolStripMenuItem}); 102 | this.menuStrip1.Location = new System.Drawing.Point(0, 0); 103 | this.menuStrip1.Name = "menuStrip1"; 104 | this.menuStrip1.Size = new System.Drawing.Size(885, 25); 105 | this.menuStrip1.TabIndex = 4; 106 | this.menuStrip1.Text = "menuStrip1"; 107 | this.menuStrip1.MenuActivate += new System.EventHandler(this.menuStrip1_MenuActivate); 108 | // 109 | // 功能ToolStripMenuItem 110 | // 111 | this.功能ToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] { 112 | this.数据源ToolStripMenuItem, 113 | this.githubToolStripMenuItem, 114 | this.toolStripSeparator2, 115 | this.保存纪录ToolStripMenuItem}); 116 | this.功能ToolStripMenuItem.Name = "功能ToolStripMenuItem"; 117 | this.功能ToolStripMenuItem.Size = new System.Drawing.Size(44, 21); 118 | this.功能ToolStripMenuItem.Text = "菜单"; 119 | // 120 | // 数据源ToolStripMenuItem 121 | // 122 | this.数据源ToolStripMenuItem.Name = "数据源ToolStripMenuItem"; 123 | this.数据源ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); 124 | this.数据源ToolStripMenuItem.Text = "数据源"; 125 | this.数据源ToolStripMenuItem.Click += new System.EventHandler(this.数据源ToolStripMenuItem_Click); 126 | // 127 | // githubToolStripMenuItem 128 | // 129 | this.githubToolStripMenuItem.Name = "githubToolStripMenuItem"; 130 | this.githubToolStripMenuItem.Size = new System.Drawing.Size(124, 22); 131 | this.githubToolStripMenuItem.Text = "检查更新"; 132 | this.githubToolStripMenuItem.Click += new System.EventHandler(this.githubToolStripMenuItem_Click); 133 | // 134 | // toolStripSeparator2 135 | // 136 | this.toolStripSeparator2.Name = "toolStripSeparator2"; 137 | this.toolStripSeparator2.Size = new System.Drawing.Size(121, 6); 138 | // 139 | // 保存纪录ToolStripMenuItem 140 | // 141 | this.保存纪录ToolStripMenuItem.Checked = true; 142 | this.保存纪录ToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked; 143 | this.保存纪录ToolStripMenuItem.Name = "保存纪录ToolStripMenuItem"; 144 | this.保存纪录ToolStripMenuItem.Size = new System.Drawing.Size(124, 22); 145 | this.保存纪录ToolStripMenuItem.Text = "保存记录"; 146 | this.保存纪录ToolStripMenuItem.Click += new System.EventHandler(this.保存纪录ToolStripMenuItem_Click); 147 | // 148 | // listViewResults 149 | // 150 | this.listViewResults.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 151 | this.columnHeaderName, 152 | this.columnHeaderSize, 153 | this.columnHeaderFrom}); 154 | this.listViewResults.FullRowSelect = true; 155 | this.listViewResults.ListViewSortType = MagnetX.List.ListView.ListViewSortTypes.None; 156 | this.listViewResults.Location = new System.Drawing.Point(12, 55); 157 | this.listViewResults.Name = "listViewResults"; 158 | this.listViewResults.Size = new System.Drawing.Size(861, 401); 159 | this.listViewResults.TabIndex = 2; 160 | this.listViewResults.UseCompatibleStateImageBehavior = false; 161 | this.listViewResults.View = System.Windows.Forms.View.Details; 162 | this.listViewResults.ColumnClick += new System.Windows.Forms.ColumnClickEventHandler(this.listViewResults_ColumnClick); 163 | this.listViewResults.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.listViewResults_MouseDoubleClick); 164 | this.listViewResults.MouseDown += new System.Windows.Forms.MouseEventHandler(this.listViewResults_MouseDown); 165 | // 166 | // columnHeaderName 167 | // 168 | this.columnHeaderName.Text = "资源名"; 169 | this.columnHeaderName.Width = 652; 170 | // 171 | // columnHeaderSize 172 | // 173 | this.columnHeaderSize.Text = "大小"; 174 | this.columnHeaderSize.Width = 81; 175 | // 176 | // columnHeaderFrom 177 | // 178 | this.columnHeaderFrom.Text = "来源"; 179 | this.columnHeaderFrom.Width = 105; 180 | // 181 | // FormMain 182 | // 183 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 184 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 185 | this.ClientSize = new System.Drawing.Size(885, 468); 186 | this.Controls.Add(this.menuStrip1); 187 | this.Controls.Add(this.listViewResults); 188 | this.Controls.Add(this.buttonSearch); 189 | this.Controls.Add(this.textBoxWord); 190 | this.MainMenuStrip = this.menuStrip1; 191 | this.Name = "FormMain"; 192 | this.Text = "MagnetX(20181108)"; 193 | this.Load += new System.EventHandler(this.FormMain_Load); 194 | this.SizeChanged += new System.EventHandler(this.FormMain_SizeChanged); 195 | this.contextMenuStripResult.ResumeLayout(false); 196 | this.menuStrip1.ResumeLayout(false); 197 | this.menuStrip1.PerformLayout(); 198 | this.ResumeLayout(false); 199 | this.PerformLayout(); 200 | 201 | } 202 | 203 | #endregion 204 | 205 | private System.Windows.Forms.TextBox textBoxWord; 206 | private System.Windows.Forms.Button buttonSearch; 207 | private System.Windows.Forms.ColumnHeader columnHeaderName; 208 | private System.Windows.Forms.ColumnHeader columnHeaderSize; 209 | private System.Windows.Forms.ContextMenuStrip contextMenuStripResult; 210 | private System.Windows.Forms.ToolStripMenuItem 复制ToolStripMenuItem; 211 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; 212 | private System.Windows.Forms.ToolStripMenuItem 资源名ToolStripMenuItem; 213 | private MagnetX.List.ListView listViewResults; 214 | private System.Windows.Forms.MenuStrip menuStrip1; 215 | private System.Windows.Forms.ToolStripMenuItem 功能ToolStripMenuItem; 216 | private System.Windows.Forms.ToolStripMenuItem 数据源ToolStripMenuItem; 217 | private System.Windows.Forms.ToolStripMenuItem githubToolStripMenuItem; 218 | private System.Windows.Forms.ColumnHeader columnHeaderFrom; 219 | private System.Windows.Forms.ToolStripSeparator toolStripSeparator2; 220 | private System.Windows.Forms.ToolStripMenuItem 保存纪录ToolStripMenuItem; 221 | } 222 | } 223 | 224 | -------------------------------------------------------------------------------- /FormMain.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Diagnostics; 6 | using System.Drawing; 7 | using System.Linq; 8 | using System.Text; 9 | using System.Threading.Tasks; 10 | using System.Windows.Forms; 11 | using MagnetX.Searcher; 12 | using MagnetX.Searcher.HistorySearcher; 13 | 14 | namespace MagnetX 15 | { 16 | public partial class FormMain : Form 17 | { 18 | public FormMain() 19 | { 20 | InitializeComponent(); 21 | this.MinimumSize = new Size(300, 200); 22 | listViewResults.ListViewItemSorter = null; 23 | } 24 | 25 | private void FormMain_Load(object sender, EventArgs e) 26 | { 27 | 28 | } 29 | 30 | private void FormMain_SizeChanged(object sender, EventArgs e) 31 | { 32 | textBoxWord.Width = this.Width - 125; 33 | buttonSearch.Left = textBoxWord.Left + textBoxWord.Width + 6; 34 | listViewResults.Width = this.Width - 40; 35 | listViewResults.Height = this.Height - 106; 36 | if (columnHeaderName.Width + columnHeaderSize.Width != listViewResults.Width - 24) 37 | { 38 | this.columnHeaderName.Width = Math.Max(75, listViewResults.Width - 24 - (columnHeaderSize.Width + columnHeaderFrom.Width)); 39 | } 40 | } 41 | 42 | 43 | #region ListView 44 | 45 | private void listViewResults_MouseDown(object sender, MouseEventArgs e) 46 | { 47 | if (e.Button == MouseButtons.Right) 48 | { 49 | if (listViewResults.SelectedItems.Count != 0) 50 | { 51 | var r = (listViewResults.SelectedItems[0] as List.ListViewItem).Result; 52 | contextMenuStripResult.Items[2].Text = r.Name; 53 | toCopy = r.Magnet; 54 | contextMenuStripResult.Show(listViewResults, new Point(e.X, e.Y)); 55 | } 56 | } 57 | } 58 | 59 | private void listViewResults_MouseDoubleClick(object sender, MouseEventArgs e) 60 | { 61 | if (e.Button == MouseButtons.Left) 62 | { 63 | if (listViewResults.SelectedItems.Count != 0) 64 | { 65 | var r = (listViewResults.SelectedItems[0] as List.ListViewItem).Result; 66 | Process.Start(r.Magnet); 67 | } 68 | } 69 | } 70 | 71 | private void listViewResults_ColumnClick(object sender, ColumnClickEventArgs e) 72 | { 73 | bool sortDesc = listViewResults.ListViewSortType.HasFlag(List.ListView.ListViewSortTypes.Asc); 74 | var sortType = sortDesc ? List.ListView.ListViewSortTypes.Desc : List.ListView.ListViewSortTypes.Asc; 75 | switch (e.Column) 76 | { 77 | case 0: 78 | { 79 | sortType |= MagnetX.List.ListView.ListViewSortTypes.Name; 80 | listViewResults.ListViewSortType = sortType; 81 | } 82 | break; 83 | 84 | case 1: 85 | { 86 | sortType |= MagnetX.List.ListView.ListViewSortTypes.Size; 87 | listViewResults.ListViewSortType = sortType; 88 | } 89 | break; 90 | 91 | case 2: 92 | { 93 | sortType |= MagnetX.List.ListView.ListViewSortTypes.From; 94 | listViewResults.ListViewSortType = sortType; 95 | } 96 | break; 97 | 98 | default: 99 | { 100 | listViewResults.ListViewSortType = MagnetX.List.ListView.ListViewSortTypes.None; 101 | } 102 | break; 103 | } 104 | } 105 | 106 | private string toCopy = ""; 107 | private void 复制ToolStripMenuItem_Click(object sender, EventArgs e) 108 | { 109 | Clipboard.Clear(); 110 | Clipboard.SetText(toCopy); 111 | } 112 | #endregion 113 | 114 | #region Search 115 | private void buttonSearch_Click(object sender, EventArgs e) 116 | { 117 | Search(textBoxWord.Text); 118 | } 119 | 120 | private void textBoxWord_KeyDown(object sender, KeyEventArgs e) 121 | { 122 | if (e.KeyCode == Keys.Enter) 123 | { 124 | Search(textBoxWord.Text); 125 | } 126 | } 127 | 128 | private int searchGeneration = 0; 129 | 130 | private void Search(string word) 131 | { 132 | searchGeneration++; 133 | listViewResults.UniqueItemClear(); 134 | this.Text = "MagnetX"; 135 | if (!string.IsNullOrEmpty(word)) 136 | { 137 | foreach (var s in Utils.GetAllSearchers()) 138 | { 139 | if (Utils.GetSearcherEnabled(s)) 140 | { 141 | s.Tag = searchGeneration; 142 | s.OnResults += OnSearchResults; 143 | s.SearchAsync(word); 144 | } 145 | } 146 | } 147 | } 148 | 149 | private bool OnSearchResults(Searcher.Searcher sender, List results) 150 | { 151 | bool retval = false; 152 | if (!(sender is HistorySearcher) && Utils.RecordHistory) 153 | { 154 | Utils.HistoryRecorder.Insert(results); 155 | } 156 | 157 | this.Invoke(new MethodInvoker(() => 158 | { 159 | int gen = (int)sender.Tag; 160 | if (gen != searchGeneration) 161 | { 162 | retval = false; 163 | } 164 | else 165 | { 166 | listViewResults.BeginUpdate(); 167 | foreach (Result r in results) 168 | { 169 | listViewResults.UniqueItemAdd(new List.ListViewItem(r)); 170 | } 171 | listViewResults.EndUpdate(); 172 | 173 | this.Text = "MagnetX (" + listViewResults.Items.Count + "个结果)"; 174 | 175 | retval = true; 176 | } 177 | })); 178 | return retval; 179 | } 180 | 181 | #endregion 182 | 183 | #region ToolStrip 184 | 185 | private void 数据源ToolStripMenuItem_Click(object sender, EventArgs e) 186 | { 187 | new FormSource().ShowDialog(); 188 | } 189 | 190 | private void 保存纪录ToolStripMenuItem_Click(object sender, EventArgs e) 191 | { 192 | Utils.RecordHistory = !Utils.RecordHistory; 193 | } 194 | 195 | private void menuStrip1_MenuActivate(object sender, EventArgs e) 196 | { 197 | 保存纪录ToolStripMenuItem.Checked = Utils.RecordHistory; 198 | } 199 | 200 | private void githubToolStripMenuItem_Click(object sender, EventArgs e) 201 | { 202 | Process.Start("https://github.com/chanket/MagnetX/releases"); 203 | } 204 | #endregion 205 | } 206 | } 207 | -------------------------------------------------------------------------------- /FormMain.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 17, 17 122 | 123 | 124 | 211, 17 125 | 126 | -------------------------------------------------------------------------------- /FormSource.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace MagnetX 2 | { 3 | partial class FormSource 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose(bool disposing) 15 | { 16 | if (disposing && (components != null)) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose(disposing); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.listView1 = new System.Windows.Forms.ListView(); 32 | this.columnHeaderName = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 33 | this.columnHeaderResult = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); 34 | this.button1 = new System.Windows.Forms.Button(); 35 | this.button2 = new System.Windows.Forms.Button(); 36 | this.button3 = new System.Windows.Forms.Button(); 37 | this.SuspendLayout(); 38 | // 39 | // listView1 40 | // 41 | this.listView1.CheckBoxes = true; 42 | this.listView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { 43 | this.columnHeaderName, 44 | this.columnHeaderResult}); 45 | this.listView1.FullRowSelect = true; 46 | this.listView1.Location = new System.Drawing.Point(12, 12); 47 | this.listView1.Name = "listView1"; 48 | this.listView1.Size = new System.Drawing.Size(260, 237); 49 | this.listView1.TabIndex = 0; 50 | this.listView1.UseCompatibleStateImageBehavior = false; 51 | this.listView1.View = System.Windows.Forms.View.Details; 52 | // 53 | // columnHeaderName 54 | // 55 | this.columnHeaderName.Text = "源"; 56 | this.columnHeaderName.Width = 115; 57 | // 58 | // columnHeaderResult 59 | // 60 | this.columnHeaderResult.Text = "状态"; 61 | this.columnHeaderResult.Width = 123; 62 | // 63 | // button1 64 | // 65 | this.button1.Location = new System.Drawing.Point(197, 258); 66 | this.button1.Name = "button1"; 67 | this.button1.Size = new System.Drawing.Size(75, 23); 68 | this.button1.TabIndex = 1; 69 | this.button1.Text = "测试"; 70 | this.button1.UseVisualStyleBackColor = true; 71 | this.button1.Click += new System.EventHandler(this.button1_Click); 72 | // 73 | // button2 74 | // 75 | this.button2.Location = new System.Drawing.Point(12, 258); 76 | this.button2.Name = "button2"; 77 | this.button2.Size = new System.Drawing.Size(75, 23); 78 | this.button2.TabIndex = 2; 79 | this.button2.Text = "全选"; 80 | this.button2.UseVisualStyleBackColor = true; 81 | this.button2.Click += new System.EventHandler(this.button2_Click); 82 | // 83 | // button3 84 | // 85 | this.button3.Location = new System.Drawing.Point(93, 258); 86 | this.button3.Name = "button3"; 87 | this.button3.Size = new System.Drawing.Size(75, 23); 88 | this.button3.TabIndex = 3; 89 | this.button3.Text = "全不选"; 90 | this.button3.UseVisualStyleBackColor = true; 91 | this.button3.Click += new System.EventHandler(this.button3_Click); 92 | // 93 | // FormSource 94 | // 95 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F); 96 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 97 | this.ClientSize = new System.Drawing.Size(284, 293); 98 | this.Controls.Add(this.button3); 99 | this.Controls.Add(this.button2); 100 | this.Controls.Add(this.button1); 101 | this.Controls.Add(this.listView1); 102 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow; 103 | this.Name = "FormSource"; 104 | this.Text = "数据源"; 105 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FormSource_FormClosing); 106 | this.Load += new System.EventHandler(this.FormSource_Load); 107 | this.ResumeLayout(false); 108 | 109 | } 110 | 111 | #endregion 112 | 113 | private System.Windows.Forms.ListView listView1; 114 | private System.Windows.Forms.ColumnHeader columnHeaderName; 115 | private System.Windows.Forms.ColumnHeader columnHeaderResult; 116 | private System.Windows.Forms.Button button1; 117 | private System.Windows.Forms.Button button2; 118 | private System.Windows.Forms.Button button3; 119 | } 120 | } -------------------------------------------------------------------------------- /FormSource.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.ComponentModel; 4 | using System.Data; 5 | using System.Drawing; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading.Tasks; 9 | using System.Windows.Forms; 10 | 11 | namespace MagnetX 12 | { 13 | public partial class FormSource : Form 14 | { 15 | public FormSource() 16 | { 17 | InitializeComponent(); 18 | } 19 | 20 | private void FormSource_Load(object sender, EventArgs e) 21 | { 22 | foreach (var s in Utils.GetAllSearchers()) 23 | { 24 | ListViewItem lvi = new ListViewItem(s.Name); 25 | lvi.SubItems.Add(""); 26 | lvi.Tag = s; 27 | listView1.Items.Add(lvi); 28 | if (Utils.GetSearcherEnabled(s)) lvi.Checked = true; 29 | } 30 | } 31 | 32 | private void FormSource_FormClosing(object sender, FormClosingEventArgs e) 33 | { 34 | foreach (ListViewItem lvi in listView1.Items) 35 | { 36 | Utils.SetSearcherEnabled(lvi.Tag as Searcher.Searcher, lvi.Checked); 37 | } 38 | } 39 | 40 | private void button1_Click(object sender, EventArgs e) 41 | { 42 | button1.Enabled = false; 43 | foreach (ListViewItem lvi in listView1.Items) 44 | { 45 | lvi.SubItems[1].Text = "测试中"; 46 | } 47 | 48 | int count = listView1.Items.Count; 49 | foreach (ListViewItem lvi in listView1.Items) 50 | { 51 | Searcher.Searcher s = lvi.Tag as Searcher.Searcher; 52 | if (s != null) 53 | { 54 | Task.Run(async () => 55 | { 56 | var result = await s.TestAsync(); 57 | this.Invoke(new MethodInvoker(() => { 58 | switch (result) 59 | { 60 | case Searcher.TestResults.OK: 61 | lvi.SubItems[1].Text = "可用"; 62 | break; 63 | case Searcher.TestResults.Timeout: 64 | lvi.SubItems[1].Text = "超时"; 65 | break; 66 | case Searcher.TestResults.FormatError: 67 | lvi.SubItems[1].Text = "解析错误"; 68 | break; 69 | case Searcher.TestResults.ServerError: 70 | lvi.SubItems[1].Text = "请求错误"; 71 | break; 72 | case Searcher.TestResults.UnknownError: 73 | lvi.SubItems[1].Text = "未知错误"; 74 | break; 75 | } 76 | 77 | if (--count == 0) 78 | { 79 | button1.Enabled = true; 80 | } 81 | })); 82 | }); 83 | } 84 | } 85 | } 86 | 87 | private void button2_Click(object sender, EventArgs e) 88 | { 89 | foreach (ListViewItem lvi in listView1.Items) 90 | { 91 | lvi.Checked = true; 92 | } 93 | } 94 | 95 | private void button3_Click(object sender, EventArgs e) 96 | { 97 | foreach (ListViewItem lvi in listView1.Items) 98 | { 99 | lvi.Checked = false; 100 | } 101 | } 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /FormSource.resx: -------------------------------------------------------------------------------- 1 |  2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /List/ListView.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace MagnetX.List 9 | { 10 | /// 11 | /// 继承自, 12 | /// 使用作为基本元素, 13 | /// 并且提供了 14 | /// 和方法, 15 | /// 用于添加hash值唯一的元素。 16 | /// 17 | class ListView : System.Windows.Forms.ListView 18 | { 19 | public ListView() 20 | { 21 | SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true); 22 | UpdateStyles(); 23 | } 24 | 25 | #region UniqueItem 26 | /// 27 | /// 清空所有元素,并清空判断唯一元素的哈希表。 28 | /// 29 | public void UniqueItemClear() 30 | { 31 | base.Items.Clear(); 32 | Hash.Clear(); 33 | } 34 | 35 | /// 36 | /// 添加唯一元素。 37 | /// 38 | /// 39 | /// 40 | /// 41 | public bool UniqueItemAdd(ListViewItem item) 42 | { 43 | if (Hash.Add(item.Result.Magnet)) 44 | { 45 | Items.Add(item); 46 | return true; 47 | } 48 | else 49 | { 50 | return false; 51 | } 52 | } 53 | 54 | protected HashSet Hash { get; set; } = new HashSet(); 55 | #endregion 56 | 57 | #region Sort 58 | /// 59 | /// 描述的排序方法。 60 | /// 61 | public enum ListViewSortTypes 62 | { 63 | /// 64 | /// 不排序。 65 | /// 66 | None = 0, 67 | 68 | /// 69 | /// 资源名升序。 70 | /// 71 | NameAsc = Name | Asc, 72 | 73 | /// 74 | /// 资源名降序。 75 | /// 76 | NameDesc = Name | Desc, 77 | 78 | /// 79 | /// 大小升序。 80 | /// 81 | SizeAsc = Size | Asc, 82 | 83 | /// 84 | /// 大小降序。 85 | /// 86 | SizeDesc = Size | Desc, 87 | 88 | /// 89 | /// 源升序。 90 | /// 91 | FromAsc = From | Asc, 92 | 93 | /// 94 | /// 源降序。 95 | /// 96 | FromDesc = From | Desc, 97 | 98 | Asc = 1, 99 | Desc = 2, 100 | Name = 4, 101 | Size = 8, 102 | From = 16, 103 | } 104 | 105 | private ListViewSortTypes listViewSortType = ListViewSortTypes.None; 106 | 107 | /// 108 | /// 获取或设置的排序方法。 109 | /// 110 | public ListViewSortTypes ListViewSortType 111 | { 112 | get 113 | { 114 | return listViewSortType; 115 | } 116 | set 117 | { 118 | listViewSortType = value; 119 | 120 | if (listViewSortType.HasFlag(ListViewSortTypes.Name)) 121 | { 122 | StringComparer stringComparer = StringComparer.CurrentCulture; 123 | if (listViewSortType.HasFlag(ListViewSortTypes.Asc)) 124 | { 125 | base.ListViewItemSorter = Comparer.Create(new Comparison((ListViewItem a, ListViewItem b) => { 126 | return stringComparer.Compare(a.Result.Name, b.Result.Name); 127 | })); 128 | } 129 | else if (listViewSortType.HasFlag(ListViewSortTypes.Desc)) 130 | { 131 | base.ListViewItemSorter = Comparer.Create(new Comparison((ListViewItem a, ListViewItem b) => { 132 | return -stringComparer.Compare(a.Result.Name, b.Result.Name); 133 | })); 134 | } 135 | else 136 | { 137 | base.ListViewItemSorter = null; 138 | } 139 | } 140 | else if (listViewSortType.HasFlag(ListViewSortTypes.Size)) 141 | { 142 | StringComparer stringComparer = StringComparer.CurrentCulture; 143 | if (listViewSortType.HasFlag(ListViewSortTypes.Asc)) 144 | { 145 | base.ListViewItemSorter = Comparer.Create(new Comparison((ListViewItem a, ListViewItem b) => { 146 | return stringComparer.Compare(a.Result.Size, b.Result.Size); 147 | })); 148 | } 149 | else if (listViewSortType.HasFlag(ListViewSortTypes.Desc)) 150 | { 151 | base.ListViewItemSorter = Comparer.Create(new Comparison((ListViewItem a, ListViewItem b) => { 152 | return -stringComparer.Compare(a.Result.Size, b.Result.Size); 153 | })); 154 | } 155 | else 156 | { 157 | base.ListViewItemSorter = null; 158 | } 159 | } 160 | else if (listViewSortType.HasFlag(ListViewSortTypes.From)) 161 | { 162 | StringComparer stringComparer = StringComparer.CurrentCulture; 163 | if (listViewSortType.HasFlag(ListViewSortTypes.Asc)) 164 | { 165 | base.ListViewItemSorter = Comparer.Create(new Comparison((ListViewItem a, ListViewItem b) => { 166 | return stringComparer.Compare(a.Result.From, b.Result.From); 167 | })); 168 | } 169 | else if (listViewSortType.HasFlag(ListViewSortTypes.Desc)) 170 | { 171 | base.ListViewItemSorter = Comparer.Create(new Comparison((ListViewItem a, ListViewItem b) => { 172 | return -stringComparer.Compare(a.Result.From, b.Result.From); 173 | })); 174 | } 175 | else 176 | { 177 | base.ListViewItemSorter = null; 178 | } 179 | } 180 | else 181 | { 182 | base.ListViewItemSorter = null; 183 | } 184 | 185 | this.Sort(); 186 | } 187 | } 188 | #endregion 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /List/ListViewItem.cs: -------------------------------------------------------------------------------- 1 | using MagnetX.Searcher; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | 8 | namespace MagnetX.List 9 | { 10 | /// 11 | /// 表示中的元素,描述一项搜索结果。 12 | /// 13 | class ListViewItem : System.Windows.Forms.ListViewItem 14 | { 15 | public Result Result { get; } 16 | 17 | public ListViewItem(Result r) 18 | { 19 | Result = r; 20 | this.SubItems[0] = new ListViewSubItem(this, r.Name); 21 | this.SubItems.Add(r.Size); 22 | this.SubItems.Add(r.From); 23 | } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /MagnetX.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {C305EE09-CEDF-45E0-A3C3-F4D53D3EF4F9} 8 | WinExe 9 | Properties 10 | MagnetX 11 | MagnetX 12 | v4.5 13 | 512 14 | 15 | 16 | AnyCPU 17 | true 18 | full 19 | false 20 | bin\Debug\ 21 | DEBUG;TRACE 22 | prompt 23 | 4 24 | false 25 | 26 | 27 | AnyCPU 28 | pdbonly 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | false 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | Component 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | Form 70 | 71 | 72 | FormMain.cs 73 | 74 | 75 | Form 76 | 77 | 78 | FormSource.cs 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | FormMain.cs 90 | 91 | 92 | FormSource.cs 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 107 | -------------------------------------------------------------------------------- /MagnetX.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chanket/MagnetX/c1940f07ef692739636d8761a87e73b844b43f1e/MagnetX.png -------------------------------------------------------------------------------- /MagnetX.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 14 4 | VisualStudioVersion = 14.0.25420.1 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MagnetX", "MagnetX.csproj", "{C305EE09-CEDF-45E0-A3C3-F4D53D3EF4F9}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {C305EE09-CEDF-45E0-A3C3-F4D53D3EF4F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {C305EE09-CEDF-45E0-A3C3-F4D53D3EF4F9}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {C305EE09-CEDF-45E0-A3C3-F4D53D3EF4F9}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {C305EE09-CEDF-45E0-A3C3-F4D53D3EF4F9}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | EndGlobal 23 | -------------------------------------------------------------------------------- /Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Threading.Tasks; 6 | using System.Windows.Forms; 7 | 8 | namespace MagnetX 9 | { 10 | static class Program 11 | { 12 | /// 13 | /// 应用程序的主入口点。 14 | /// 15 | [STAThread] 16 | static void Main() 17 | { 18 | Application.EnableVisualStyles(); 19 | Application.SetCompatibleTextRenderingDefault(false); 20 | Application.Run(new FormMain()); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("MagnetX")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("MagnetX")] 13 | [assembly: AssemblyCopyright("Copyright © 2017")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | //将 ComVisible 设置为 false 将使此程序集中的类型 18 | //对 COM 组件不可见。 如果需要从 COM 访问此程序集中的类型, 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("c305ee09-cedf-45e0-a3c3-f4d53d3ef4f9")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值, 33 | // 方法是按如下所示使用“*”: : 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.0.0.1")] 36 | [assembly: AssemblyFileVersion("1.0.0.1")] 37 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MagnetX 2 | 找磁力链接、找种子的小工具。它具备以下特点:
3 |
    √异步、多线程地实时爬取多个网站。
4 |
    √可以非明文地缓存历史搜索结果,在本地历史纪录中更快速地搜索关键字。
5 |
    √绿色天然无公害,远离弹窗,远离广告。
6 | 7 | # Example 8 | 9 | 10 | # Customize 11 | MagnetX提供了一个不错的框架,如果你有兴趣也可以实现自己的数据源,自给自足,丰衣足食。
12 | 只要在程序集下的类同时具有以下3个特点,你定义的源的实现即可通过C#的Reflection机制直接被识别:
13 | 1.继承自`MagnetX.Searcher.Searcher`类
14 | 2.类具有`MagnetX.Searcher.SearcherEnabledAttribute`属性
15 | 3.具有无参数构造函数
16 | ## 继承MagnetX.Searcher.SimpleWebSearcher类 17 | 对于网页爬虫源,最快捷的实现方式为继承`MagnetX.Searcher.SimpleWebSearcher`类,并给出解析源的关键实现。 18 | ```csharp 19 | [SearcherEnabled] //标记源为启用的属性 20 | class FooWebSearcher : SimpleWebSearcher //通过SimpleWebSearcher间接继承Searcher类 21 | { 22 | //必须覆盖的方法 23 | //定义word关键词第i页结果所在的URL 24 | protected override async Task GetURLAsync(string word, int page) 25 | { 26 | string name = Uri.EscapeUriString(word); 27 | return "https://www.foo.biz/s/" + name + "_rel_" + page + ".html"; 28 | } 29 | 30 | //必须实现的无参数构造函数 31 | //通过传递给基类5个参数快速实现一个网页爬虫源。 32 | public CilibaWebSearcher() 33 | : base("foo.biz", //源的友好名称。 34 | "
", //每一个搜索结果的前导特征字符串。基类会对结果用这个字符串进行切割,并处理从下标1开始的字串。 35 | new Regex("target=\"_blank\">(.+?)", RegexOptions.Compiled), //资源名称的正则表达式。 36 | new Regex("(.+?)<", RegexOptions.Compiled)) //资源文件大小的正则表达式。 38 | { 39 | 40 | } 41 | 42 | //可选的覆盖方法 43 | //在这里可以对基类得到的结果进行进一步处理,例如去除一些标签。 44 | //有时正则表达式无法直接得到最终结果(例如,需要参考资源详情页面才能获得资源哈希值), 45 | //也可以在这个方法里做进一步处理。 46 | protected override async Task GetResultAsync(string part) 47 | { 48 | Result result = await base.GetResultAsync(part).ConfigureAwait(false); //获得基类的得到的中间结果 49 | if (result == null) return null; //注意基类结果发生错误时结果为null 50 | 51 | result.Name = result.Name.Replace("", "").Replace("", ""); 52 | return result; 53 | } 54 | } 55 | ``` 56 | -------------------------------------------------------------------------------- /Searcher/HistorySearcher/HistoryRecorder.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.OleDb; 4 | using System.IO; 5 | using System.IO.Compression; 6 | using System.Linq; 7 | using System.Text; 8 | using System.Threading; 9 | using System.Threading.Tasks; 10 | 11 | namespace MagnetX.Searcher.HistorySearcher 12 | { 13 | /// 14 | /// 历史记录的记录类。 15 | /// 16 | class HistoryRecorder 17 | { 18 | /// 19 | /// 记录的文件流。 20 | /// 21 | protected BufferedStream Stream { get; } = new BufferedStream(Utils.HistoryStreamForWrite); 22 | 23 | /// 24 | /// 判断重复记录的哈希表。 25 | /// 26 | protected HashSet Set { get; } = new HashSet(); 27 | 28 | /// 29 | /// 单线程插入的信号量。 30 | /// 31 | protected SemaphoreSlim Lock { get; } = new SemaphoreSlim(0); 32 | 33 | protected async void Prepare() 34 | { 35 | using (Stream stream = new BufferedStream(Utils.HistoryStreamForRead)) 36 | { 37 | Result result = await Utils.ReadResult(stream).ConfigureAwait(false); 38 | while (result != null) 39 | { 40 | Set.Add(result.Magnet); 41 | 42 | result = await Utils.ReadResult(stream).ConfigureAwait(false); 43 | } 44 | } 45 | 46 | Lock.Release(); 47 | } 48 | 49 | public HistoryRecorder() 50 | { 51 | Prepare(); 52 | } 53 | 54 | /// 55 | /// 插入一组历史纪录。 56 | /// 57 | public async Task Insert(IEnumerable results) 58 | { 59 | await Lock.WaitAsync().ConfigureAwait(false); 60 | { 61 | int count = 0; 62 | Stream.Seek(0, SeekOrigin.End); 63 | foreach (Result result in results) 64 | { 65 | if (!Set.Contains(result.Magnet)) 66 | { 67 | await Utils.WriteResult(Stream, result).ConfigureAwait(false); 68 | count++; 69 | } 70 | } 71 | if (count != 0) await Stream.FlushAsync().ConfigureAwait(false); 72 | } 73 | Lock.Release(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Searcher/HistorySearcher/HistorySearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using System.Data.OleDb; 7 | using System.Threading; 8 | using System.Windows.Forms; 9 | using System.IO; 10 | using System.IO.Compression; 11 | 12 | namespace MagnetX.Searcher.HistorySearcher 13 | { 14 | /// 15 | /// 历史记录的搜索类。 16 | /// 17 | [SearcherEnabled] 18 | class HistorySearcher : Searcher 19 | { 20 | protected bool Matches(string[] words, string name) 21 | { 22 | foreach(string word in words) 23 | { 24 | if (name.IndexOf(word) == -1) return false; 25 | } 26 | return true; 27 | } 28 | 29 | public override string Name 30 | { 31 | get 32 | { 33 | return "本地记录"; 34 | } 35 | } 36 | 37 | public override async void SearchAsync(string word) 38 | { 39 | string[] words = word.Split(' ', '\t'); 40 | List list = new List(); 41 | try 42 | { 43 | using (BufferedStream fs = new BufferedStream(Utils.HistoryStreamForRead)) 44 | { 45 | while (true) 46 | { 47 | Result result = await Utils.ReadResult(fs).ConfigureAwait(false); 48 | if (result == null) break; 49 | 50 | result.From = Name; 51 | if (Matches(words,result.Name)) 52 | { 53 | list.Add(result); 54 | } 55 | if (list.Count == 100) 56 | { 57 | if (OnResults == null) break; 58 | if (!OnResults.Invoke(this, list)) break; 59 | list.Clear(); 60 | } 61 | } 62 | } 63 | } 64 | catch { } 65 | 66 | try 67 | { 68 | if (list.Count != 0) 69 | { 70 | if (OnResults != null) OnResults.Invoke(this, list); 71 | list.Clear(); 72 | } 73 | } 74 | catch { } 75 | } 76 | 77 | public override async Task TestAsync() 78 | { 79 | return TestResults.OK; 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Searcher/HistorySearcher/Utils.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Data.OleDb; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Threading.Tasks; 7 | using System.IO; 8 | using System.IO.Compression; 9 | 10 | namespace MagnetX.Searcher.HistorySearcher 11 | { 12 | /// 13 | /// 历史纪录的工具类。 14 | /// 提供了对历史文件流的操作。 15 | /// 16 | static class Utils 17 | { 18 | private static string History { get; } = "History.bin"; 19 | private static Encoding Encoding { get; } = Encoding.UTF8; 20 | public static FileStream HistoryStreamForRead { get { return new FileStream(History, FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite); } } 21 | public static FileStream HistoryStreamForWrite { get { return new FileStream(History, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.Read); } } 22 | 23 | public static async Task ReadResult(Stream stream) 24 | { 25 | try 26 | { 27 | int size = (stream.ReadByte() << 24) 28 | + (stream.ReadByte() << 16) 29 | + (stream.ReadByte() << 8) 30 | + stream.ReadByte(); 31 | byte[] buffer = new byte[size]; 32 | 33 | await stream.ReadAsync(buffer, 0, size).ConfigureAwait(false); 34 | using (BinaryReader br = new BinaryReader(new DeflateStream(new MemoryStream(buffer), CompressionMode.Decompress), Encoding)) 35 | { 36 | Result result = new Result(); 37 | result.Name = br.ReadString(); 38 | result.Magnet = br.ReadString(); 39 | result.Size = br.ReadString(); 40 | 41 | return result; 42 | } 43 | } 44 | catch (Exception ex) 45 | { 46 | return null; 47 | } 48 | } 49 | 50 | public static async Task WriteResult(Stream stream, Result result) 51 | { 52 | try 53 | { 54 | using (MemoryStream ms = new MemoryStream()) 55 | { 56 | using (BinaryWriter bw = new BinaryWriter(new DeflateStream(ms, CompressionMode.Compress, true), Encoding)) 57 | { 58 | bw.Write(result.Name); 59 | bw.Write(result.Magnet); 60 | bw.Write(result.Size); 61 | } 62 | 63 | ms.Seek(0, SeekOrigin.Begin); 64 | int size = (int)ms.Length; 65 | await stream.WriteAsync(new byte[] { 66 | (byte)(size >> 24), 67 | (byte)(size >> 16), 68 | (byte)(size >> 8), 69 | (byte)(size), 70 | }, 0, 4).ConfigureAwait(false); 71 | await ms.CopyToAsync(stream).ConfigureAwait(false); 72 | 73 | return true; 74 | } 75 | } 76 | catch (Exception ex) 77 | { 78 | return false; 79 | } 80 | } 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Searcher/Searcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | 7 | namespace MagnetX.Searcher 8 | { 9 | /// 10 | /// 搜索结果。 11 | /// 12 | public class Result 13 | { 14 | public string Name { get; set; } 15 | public string Magnet { get; set; } 16 | public string Size { get; set; } 17 | public string From { get; set; } 18 | } 19 | 20 | /// 21 | /// 的状态。 22 | /// 23 | public enum TestResults 24 | { 25 | OK, 26 | Timeout, 27 | ServerError, 28 | FormatError, 29 | UnknownError, 30 | } 31 | 32 | /// 33 | /// 标记为启用状态的属性。 34 | /// 35 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)] 36 | public class SearcherEnabledAttribute : System.Attribute 37 | { 38 | 39 | } 40 | 41 | /// 42 | /// 返回搜索结果的事件委托。 43 | /// 44 | /// 返回搜索结果的对象。 45 | /// 搜索结果的列表。 46 | /// 指示是否继续搜索。 47 | delegate bool SearcherResultsDelegate(Searcher sender, List results); 48 | 49 | /// 50 | /// 数据源的抽象类。 51 | /// 52 | abstract class Searcher 53 | { 54 | public SearcherResultsDelegate OnResults = null; 55 | 56 | public object Tag { get; set; } = null; 57 | public abstract string Name { get; } 58 | public abstract void SearchAsync(string word); 59 | public abstract Task TestAsync(); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/Bt177WebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace MagnetX.Searcher.WebSearcher 9 | { 10 | [SearcherEnabled] 11 | class Bt177WebSearcher : SimpleWebSearcher 12 | { 13 | protected override async Task GetURLAsync(string word, int page) 14 | { 15 | string text = Uri.EscapeUriString(word); 16 | return "http://www.bt177.biz/word/" + text + "_" + page + ".html"; 17 | } 18 | 19 | public Bt177WebSearcher() 20 | : base("bt177.biz", "
  • ", 21 | new Regex("title=\"(.+?)\"", RegexOptions.Compiled), 22 | new Regex("href=\"/read/(.+?)\\.html", RegexOptions.Compiled), 23 | new Regex("大小.+?>(.+?)", RegexOptions.Compiled)) 24 | { 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/BtcatWebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text.RegularExpressions; 4 | using System.Threading.Tasks; 5 | 6 | namespace MagnetX.Searcher.WebSearcher 7 | { 8 | [SearcherEnabled] 9 | class BtcatWebSearcher : SimpleWebSearcher 10 | { 11 | protected override async Task GetURLAsync(string word, int page) 12 | { 13 | string text = Uri.EscapeUriString(word); 14 | return "https://btcat.org/search/" + text + "/rela-" + page + ".html"; 15 | } 16 | 17 | public BtcatWebSearcher() 18 | : base("btcat.org", "
    ", 19 | new Regex("(.+?)<", RegexOptions.Compiled)) 22 | { 23 | 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/BtsoWebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Text.RegularExpressions; 5 | using System.Threading.Tasks; 6 | 7 | namespace MagnetX.Searcher.WebSearcher 8 | { 9 | [SearcherEnabled] 10 | class BtsoWebSearcher : SimpleWebSearcher 11 | { 12 | protected override async Task GetURLAsync(string word, int page) 13 | { 14 | string text = Uri.EscapeUriString(word); 15 | return "https://btso.pw/search/" + text + "/page/" + page; 16 | } 17 | 18 | public BtsoWebSearcher() 19 | : base("btso.pw", "
    ", 20 | new Regex("title=\"(.+?)\"", RegexOptions.Compiled), 21 | new Regex("/hash/(.+?)\"", RegexOptions.Compiled), 22 | new Regex("size\">(.+?)<", RegexOptions.Compiled)) 23 | { 24 | 25 | } 26 | 27 | protected override HttpClient CreateHttpClient() 28 | { 29 | HttpClient httpClient = base.CreateHttpClient(); 30 | httpClient.DefaultRequestHeaders.Add("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8"); 31 | return httpClient; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/BturlWebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace MagnetX.Searcher.WebSearcher 9 | { 10 | [SearcherEnabled] 11 | class BturlWebSearcher : SimpleWebSearcher 12 | { 13 | protected override async Task GetURLAsync(string word, int page) 14 | { 15 | string name = Uri.EscapeUriString(word); 16 | return "https://www.bturl.cc/search/" + name + "_click_" + page + ".html"; 17 | } 18 | 19 | public BturlWebSearcher() 20 | : base("bturl.cc", "

    ", 21 | new Regex("
    (.+)(
    |\n)", RegexOptions.Compiled), 22 | new Regex("href=\"/(.+?)\\.html", RegexOptions.Compiled), 23 | new Regex("文件大小.+?>(.+?)", RegexOptions.Compiled)) 24 | { 25 | 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/CilibaWebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace MagnetX.Searcher.WebSearcher 9 | { 10 | [SearcherEnabled] 11 | class CilibaWebSearcher : SimpleWebSearcher 12 | { 13 | protected override async Task GetURLAsync(string word, int page) 14 | { 15 | string name = Uri.EscapeUriString(word); 16 | return "https://www.ciliba.biz/s/" + name + "_rel_" + page + ".html"; 17 | } 18 | 19 | public CilibaWebSearcher() 20 | : base("ciliba.biz", "
    ", 21 | new Regex("target=\"_blank\">(.+?)", RegexOptions.Compiled), 22 | new Regex("(.+?)<", RegexOptions.Compiled)) 24 | { 25 | 26 | } 27 | 28 | protected override async Task GetResultAsync(string part) 29 | { 30 | Result result = await base.GetResultAsync(part).ConfigureAwait(false); 31 | if (result == null) return null; 32 | 33 | result.Name = result.Name.Replace("", "").Replace("", ""); 34 | return result; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/CililianxWebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Net.Http; 5 | using System.Text; 6 | using System.Text.RegularExpressions; 7 | using System.Threading.Tasks; 8 | 9 | namespace MagnetX.Searcher.WebSearcher 10 | { 11 | [SearcherEnabled] 12 | class CililianxWebSearcher : SimpleWebSearcher 13 | { 14 | protected override async Task GetURLAsync(string word, int page) 15 | { 16 | string name = Uri.EscapeUriString(word); 17 | return "http://cililianx.com/list/" + name + "/" + page + ".html"; 18 | } 19 | 20 | public CililianxWebSearcher() 21 | : base("cililianx.com", "
    ", 22 | new Regex("(.+?)", RegexOptions.Compiled), 23 | new Regex("/xiangxi/(.+?)\"", RegexOptions.Compiled), 24 | new Regex("种子大小[\\D]+\\>\\s*(\\d[^\\<]+)", RegexOptions.Compiled)) 25 | { 26 | 27 | } 28 | 29 | protected override async Task GetResultAsync(string part) 30 | { 31 | Result result = await base.GetResultAsync(part).ConfigureAwait(false); 32 | if (result == null) return null; 33 | 34 | result.Name = result.Name.Replace("", "").Replace("", ""); 35 | return result; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /Searcher/WebSearcher/CilimaoWebSearcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Text; 5 | using System.Text.RegularExpressions; 6 | using System.Threading.Tasks; 7 | 8 | namespace MagnetX.Searcher.WebSearcher 9 | { 10 | [SearcherEnabled] 11 | class CilimaoWebSearcher : SimpleWebSearcher 12 | { 13 | protected override async Task GetURLAsync(string word, int page) 14 | { 15 | string name = Uri.EscapeUriString(word); 16 | return "https://www.cilimao.me/search?word=" + name + "&sortProperties=download_count&page=" + page; 17 | } 18 | 19 | public CilimaoWebSearcher() 20 | : base("cilimao.me", "
    (.+?)", RegexOptions.Compiled), 22 | new Regex("href=\"/information/(.+?)\\?", RegexOptions.Compiled), 23 | new Regex("文件大小.+?-->(.+?)