Zony 1 year ago
parent
commit
511e6c0e08

+ 39 - 0
LibLrcBaiDu.cs/LibLrcBaiDu.cs

@@ -0,0 +1,39 @@
+using System.Text;
+using LibPlugins;
+using LibPlugins.Enum;
+using LibNet.Http;
+using System.Text.RegularExpressions;
+
+namespace LibLrcBaiDu.cs
+{
+    [PluginsInfo("百度音乐歌词下载","Zony","可以从百度音乐搜索下载歌词.",1000,NativePluginsType.LrcSource)]
+    public class LibLrcBaiDu : ILrcPlug
+    {
+        private NetUtils m_netUtils = new NetUtils();
+        public PluginsInfo Info { get; set; }
+
+        public bool DownLoad(string artistName, string songName, ref byte[] data)
+        {
+            // 请求URL构建
+            const string Request_Url = "http://music.baidu.com/search/lrc?key=";
+            const string ResponseUrl = "http://music.baidu.com";
+
+            string _key = artistName + "+" + songName;
+            string _result = m_netUtils.HttpGet(Request_Url + _key, "", Encoding.UTF8);
+
+            if(!string.IsNullOrWhiteSpace(_result))
+            {
+                Regex _reg = new Regex("/data2/lrc/\\d*/\\d*.lrc");
+                string _lrcURL = _reg.Match(_result).ToString();
+
+                string _lrcData = m_netUtils.HttpGet(ResponseUrl + _lrcURL,"",Encoding.UTF8);
+                data = Encoding.UTF8.GetBytes(_lrcData);
+                return true;
+            }
+            else
+            {
+                return false;
+            }
+        }
+    }
+}

+ 68 - 0
LibLrcBaiDu.cs/LibLrcBaiDu.cs.csproj

@@ -0,0 +1,68 @@
+<?xml version="1.0" encoding="utf-8"?>
+<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
+  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+  <PropertyGroup>
+    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
+    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
+    <ProjectGuid>{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>LibLrcBaiDu.cs</RootNamespace>
+    <AssemblyName>LibLrcBaiDu.cs</AssemblyName>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
+    <DebugSymbols>true</DebugSymbols>
+    <DebugType>full</DebugType>
+    <Optimize>false</Optimize>
+    <OutputPath>bin\Debug\</OutputPath>
+    <DefineConstants>DEBUG;TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
+    <DebugType>pdbonly</DebugType>
+    <Optimize>true</Optimize>
+    <OutputPath>bin\Release\</OutputPath>
+    <DefineConstants>TRACE</DefineConstants>
+    <ErrorReport>prompt</ErrorReport>
+    <WarningLevel>4</WarningLevel>
+  </PropertyGroup>
+  <ItemGroup>
+    <Reference Include="System" />
+    <Reference Include="System.Core" />
+    <Reference Include="System.Xml.Linq" />
+    <Reference Include="System.Data.DataSetExtensions" />
+    <Reference Include="Microsoft.CSharp" />
+    <Reference Include="System.Data" />
+    <Reference Include="System.Net.Http" />
+    <Reference Include="System.Xml" />
+  </ItemGroup>
+  <ItemGroup>
+    <Compile Include="LibLrcBaiDu.cs" />
+    <Compile Include="Properties\AssemblyInfo.cs" />
+  </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\LibNet\LibNet.csproj">
+      <Project>{226bb4d9-f34a-4a8a-a63d-482fa3c5e011}</Project>
+      <Name>LibNet</Name>
+    </ProjectReference>
+    <ProjectReference Include="..\LibPlugins\LibPlugins.csproj">
+      <Project>{491a4b32-0ee8-4dc8-9c53-dacd904ba142}</Project>
+      <Name>LibPlugins</Name>
+    </ProjectReference>
+  </ItemGroup>
+  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
+  <PropertyGroup>
+    <PostBuildEvent>copy "$(TargetDir)$(TargetFileName)" "$(SolutionDir)$(SolutionName)\bin\Debug\Plugins"</PostBuildEvent>
+  </PropertyGroup>
+  <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
+       Other similar extension points exist, see Microsoft.Common.targets.
+  <Target Name="BeforeBuild">
+  </Target>
+  <Target Name="AfterBuild">
+  </Target>
+  -->
+</Project>

+ 36 - 0
LibLrcBaiDu.cs/Properties/AssemblyInfo.cs

@@ -0,0 +1,36 @@
+using System.Reflection;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+
+// 有关程序集的一般信息由以下
+// 控制。更改这些特性值可修改
+// 与程序集关联的信息。
+[assembly: AssemblyTitle("LibLrcBaiDu.cs")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("")]
+[assembly: AssemblyProduct("LibLrcBaiDu.cs")]
+[assembly: AssemblyCopyright("Copyright ©  2016")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+//将 ComVisible 设置为 false 将使此程序集中的类型
+//对 COM 组件不可见。  如果需要从 COM 访问此程序集中的类型,
+//请将此类型的 ComVisible 特性设置为 true。
+[assembly: ComVisible(false)]
+
+// 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID
+[assembly: Guid("9058e9cd-2bc0-44f9-b994-8a9041afffb7")]
+
+// 程序集的版本信息由下列四个值组成: 
+//
+//      主版本
+//      次版本
+//      生成号
+//      修订号
+//
+//可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值,
+// 方法是按如下所示使用“*”: :
+// [assembly: AssemblyVersion("1.0.*")]
+[assembly: AssemblyVersion("1.0.0.0")]
+[assembly: AssemblyFileVersion("1.0.0.0")]

+ 5 - 4
LibLrcNetease/LibLrcNetease.cs

@@ -1,13 +1,14 @@
 using System.Text;
-using LibPlugins;
-using LibNet.Http;
-using Newtonsoft.Json.Linq;
 using System.Text.RegularExpressions;
 using System.Collections.Generic;
+using Newtonsoft.Json.Linq;
+using LibPlugins.Enum;
+using LibPlugins;
+using LibNet.Http;
 
 namespace LibLrcNetease
 {
-    [PluginsInfo("网易云歌词下载插件","Zony","从网易云API下载指定歌词.",1200,0)]
+    [PluginsInfo("网易云歌词下载插件","Zony","从网易云API下载指定歌词.",1200,NativePluginsType.LrcSource)]
     public class LibLrcNetease : ILrcPlug
     {
         private NetUtils m_netUtils = new NetUtils();

+ 2 - 1
LibLrcNetease/LibLrcNetease.csproj

@@ -9,8 +9,9 @@
     <AppDesignerFolder>Properties</AppDesignerFolder>
     <RootNamespace>LibLrcNetease</RootNamespace>
     <AssemblyName>LibLrcNetease</AssemblyName>
-    <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
+    <TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
     <FileAlignment>512</FileAlignment>
+    <TargetFrameworkProfile />
   </PropertyGroup>
   <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
     <DebugSymbols>true</DebugSymbols>

+ 4 - 10
LibMusicInfoRead/LibMusicInfoRead.cs

@@ -1,17 +1,11 @@
-/*
- * 描述:音乐文件信息读取。
- * 作者:Zony
- * 创建日期:2016/10/09
- * 最后修改日期:2016/10/09
- * 版本:v1.0
- */
-using LibPlugins;
+using System.IO;
 using ID3;
-using System.IO;
+using LibPlugins;
+using LibPlugins.Enum;
 
 namespace LibMusicInfoRead
 {
-    [PluginsInfo("音乐信息读取","Zony","读取音乐文件的ID3信息。",1000,1)]
+    [PluginsInfo("音乐信息读取","Zony","读取音乐文件的ID3信息。",1000,NativePluginsType.Mp3Tag)]
     public class LibMusicInfoRead : IExpPlug
     {
         public PluginsInfo Info { get; set; }

+ 25 - 0
LibPlugins/Enum/NativePluginsType.cs

@@ -0,0 +1,25 @@
+/*
+ * 描述:原生插件类型定义枚举。
+ * 作者:Zony
+ * 创建日期:2016/10/22
+ * 最后修改日期:2016/10/22
+ * 版本:v1.0
+ */
+namespace LibPlugins.Enum
+{
+    public enum NativePluginsType
+    {
+        /// <summary>
+        /// 歌词源插件
+        /// </summary>
+        LrcSource = 0x00000000,
+        /// <summary>
+        /// MP3IDv1、IDv2信息提取插件
+        /// </summary>
+        Mp3Tag = LrcSource + 0x01,
+        /// <summary>
+        /// 专辑下载插件
+        /// </summary>
+        AlbumImg = LrcSource + 0x02,
+    }
+}

+ 1 - 0
LibPlugins/LibPlugins.csproj

@@ -42,6 +42,7 @@
     <Reference Include="System.Xml" />
   </ItemGroup>
   <ItemGroup>
+    <Compile Include="Enum\NativePluginsType.cs" />
     <Compile Include="IExpPlug.cs" />
     <Compile Include="ILrcPlug.cs" />
     <Compile Include="ListView_NF.cs">

+ 4 - 3
LibPlugins/PluginsInfo.cs

@@ -7,6 +7,7 @@
  */
 
 using System;
+using LibPlugins.Enum;
 
 namespace LibPlugins
 {
@@ -16,7 +17,7 @@ namespace LibPlugins
     public class PluginsInfo : Attribute
     {
         public PluginsInfo() { }
-        public PluginsInfo(string PlugName,string Author,string Descript,int Version,int Type)
+        public PluginsInfo(string PlugName,string Author,string Descript,int Version,NativePluginsType Type)
         {
             _PlugName = PlugName;
             _Descript = Descript;
@@ -44,12 +45,12 @@ namespace LibPlugins
         /// <summary>
         /// 插件类型
         /// </summary>
-        public int Type { get { return _Version; } }
+        public NativePluginsType Type { get { return _Type; } }
 
         private string _PlugName;
         private string _Author;
         private string _Descript;
         private int _Version;
-        private int _Type;
+        private NativePluginsType _Type;
     }
 }

+ 6 - 0
ZonyLrcDownLoad 4.sln

@@ -13,6 +13,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMusicInfoRead", "LibMusi
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibLrcNetease", "LibLrcNetease\LibLrcNetease.csproj", "{93B81B27-0CC3-4455-852F-9448B941EA51}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibLrcBaiDu.cs", "LibLrcBaiDu.cs\LibLrcBaiDu.cs.csproj", "{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -39,6 +41,10 @@ Global
 		{93B81B27-0CC3-4455-852F-9448B941EA51}.Debug|Any CPU.Build.0 = Debug|Any CPU
 		{93B81B27-0CC3-4455-852F-9448B941EA51}.Release|Any CPU.ActiveCfg = Release|Any CPU
 		{93B81B27-0CC3-4455-852F-9448B941EA51}.Release|Any CPU.Build.0 = Release|Any CPU
+		{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 4 - 2
ZonyLrcDownLoad 4/Setting/Setting.cs

@@ -9,6 +9,7 @@ using System;
 using System.Text;
 using System.IO;
 using Newtonsoft.Json;
+using System.Collections.Generic;
 
 namespace ZonyLrcDownLoad_4.Setting
 {
@@ -26,7 +27,7 @@ namespace ZonyLrcDownLoad_4.Setting
         public static void SaveSetting()
         {
             string _ser = JsonConvert.SerializeObject(SetValue);
-            byte[] _data = Encoding.ASCII.GetBytes(_ser);
+            byte[] _data = Encoding.UTF8.GetBytes(_ser);
 
             using (m_confFile = new FileStream(m_confPath, FileMode.OpenOrCreate))
             {
@@ -74,8 +75,8 @@ namespace ZonyLrcDownLoad_4.Setting
             SetValue.WriteEncoding = 0;
             SetValue.UserDirectory = string.Empty;
             SetValue.IsCheckUpdate = false;
+            SetValue.PluginsStatus = new Dictionary<string, bool>();
         }
-
         #endregion
     }
 
@@ -88,6 +89,7 @@ namespace ZonyLrcDownLoad_4.Setting
         public string UserDirectory { get; set; }
         public string FileSuffixs { get; set; }
         public bool IsCheckUpdate { get; set; }
+        public Dictionary<string,bool> PluginsStatus { get; set; } 
     }
     #endregion
 }

+ 11 - 10
ZonyLrcDownLoad 4/Windows/WindowPlugins.Designer.cs

@@ -40,7 +40,7 @@
             this.columnHeader6 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.columnHeader7 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
             this.columnHeader8 = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader()));
-            this.button1 = new System.Windows.Forms.Button();
+            this.button_Save = new System.Windows.Forms.Button();
             this.SuspendLayout();
             // 
             // listView1
@@ -129,21 +129,22 @@
             this.columnHeader8.Text = "描述";
             this.columnHeader8.Width = 234;
             // 
-            // button1
+            // button_Save
             // 
-            this.button1.Location = new System.Drawing.Point(214, 414);
-            this.button1.Name = "button1";
-            this.button1.Size = new System.Drawing.Size(82, 32);
-            this.button1.TabIndex = 4;
-            this.button1.Text = "保存";
-            this.button1.UseVisualStyleBackColor = true;
+            this.button_Save.Location = new System.Drawing.Point(214, 414);
+            this.button_Save.Name = "button_Save";
+            this.button_Save.Size = new System.Drawing.Size(82, 32);
+            this.button_Save.TabIndex = 4;
+            this.button_Save.Text = "保存";
+            this.button_Save.UseVisualStyleBackColor = true;
+            this.button_Save.Click += new System.EventHandler(this.button_Save_Click);
             // 
             // WindowPlugins
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
             this.ClientSize = new System.Drawing.Size(504, 450);
-            this.Controls.Add(this.button1);
+            this.Controls.Add(this.button_Save);
             this.Controls.Add(this.listView2);
             this.Controls.Add(this.label2);
             this.Controls.Add(this.label1);
@@ -168,7 +169,7 @@
         private System.Windows.Forms.Label label1;
         private System.Windows.Forms.Label label2;
         private System.Windows.Forms.ListView listView2;
-        private System.Windows.Forms.Button button1;
+        private System.Windows.Forms.Button button_Save;
         private System.Windows.Forms.ColumnHeader columnHeader5;
         private System.Windows.Forms.ColumnHeader columnHeader6;
         private System.Windows.Forms.ColumnHeader columnHeader7;

+ 33 - 2
ZonyLrcDownLoad 4/Windows/WindowPlugins.cs

@@ -9,6 +9,7 @@ using System.Threading;
 using System.Threading.Tasks;
 using System.Windows.Forms;
 using ZonyLrcDownLoad_4.Plugin;
+using ZonyLrcDownLoad_4.Setting;
 using ZonyLrcDownLoad_4.Utils;
 
 namespace ZonyLrcDownLoad_4.Windows
@@ -25,16 +26,46 @@ namespace ZonyLrcDownLoad_4.Windows
             new Thread(() => 
             {
                 Longlife.ExpManager.LoadPlugins();
-                foreach(var item in Longlife.ExpManager.PluginInfos)
+                foreach (var item in Longlife.ExpManager.PluginInfos)
                 {
-                    listView1.Items.Add(new ListViewItem(new string[] { item.PlugName,item.Version.ToString(),item.Author,item.Descript}));
+                    listView1.Items.Add(new ListViewItem(new string[] { item.PlugName, item.Version.ToString(), item.Author, item.Descript }));
                 }
                 Longlife.LrcManager.LoadPlugins();
                 foreach (var item in Longlife.LrcManager.PluginInfos)
                 {
                     listView1.Items.Add(new ListViewItem(new string[] { item.PlugName, item.Version.ToString(), item.Author, item.Descript }));
                 }
+                initPluginsStatus();
             }).Start();
         }
+
+        private void button_Save_Click(object sender, EventArgs e)
+        {
+            initPluginsStatus();
+            ProgramSetting.SaveSetting();
+        }
+
+        private void initPluginsStatus()
+        {
+            if (ProgramSetting.SetValue.PluginsStatus.Count != 0)
+            {
+                for (int i = 0; i < listView1.Items.Count; i++)
+                {
+                    string _plugName = listView1.Items[i].SubItems[0].Text;
+                    listView1.Items[i].Checked = ProgramSetting.SetValue.PluginsStatus[_plugName];
+                }
+            }
+            else
+            {
+                foreach (var item in Longlife.ExpManager.PluginInfos)
+                {
+                    ProgramSetting.SetValue.PluginsStatus.Add(item.PlugName, true);
+                }
+                foreach (var item in Longlife.LrcManager.PluginInfos)
+                {
+                    ProgramSetting.SetValue.PluginsStatus.Add(item.PlugName, true);
+                }
+            }
+        }
     }
 }

+ 1 - 1
ZonyLrcDownLoad 4/Windows/WindowPlugins.resx

@@ -129,7 +129,7 @@
   <metadata name="listView2.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
-  <metadata name="button1.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
+  <metadata name="button_Save.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
     <value>True</value>
   </metadata>
   <metadata name="$this.Locked" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">