Browse Source

Add/Update 添加专辑图片下载插件;更新某些代码;

Zony 1 year ago
parent
commit
e39d1c773c

+ 84 - 0
LibMusicAlbumImage/LibMusicAlbumImage.cs

@@ -0,0 +1,84 @@
+using LibPlugins;
+using LibPlugins.Enum;
+using LibNet.Http;
+using System.Text;
+using Newtonsoft.Json.Linq;
+using System.Net;
+using ID3;
+using System.IO;
+using static ID3.ID3v2Frames.BinaryFrames.AttachedPictureFrame;
+
+namespace LibMusicAlbumImage
+{
+    [PluginsInfo("专辑下载插件", "Zony", "从网易云下载该歌曲的专辑", 1000, NativePluginsType.AlbumImg)]
+    public class LibMusicAlbumImage : IExpPlug
+    {
+        public PluginsInfo Info { get; set; }
+        private ResourceShareModel model;
+        private NetUtils m_netUtil = new NetUtils();
+
+        public void Init(ref ResourceShareModel model)
+        {
+            this.model = model;
+            downAlbumImage();
+        }
+
+        private void downAlbumImage()
+        {
+            foreach(var item in model.MusicFiles)
+            {
+                if(!item.Value.Image)
+                {
+                    string _songName = m_netUtil.URL_Encoding(item.Value.SongName, "utf-8");
+                    string _artist = m_netUtil.URL_Encoding(item.Value.Artist, "utf-8");
+                    string _key = string.Format("{0}+{1}", _artist, _songName);
+
+                    // 搜索歌曲ID
+                    string _requestUrl = @"http://music.163.com/api/search/get/web?csrf_token=";
+                    string _postData = "&s=" + _key + "&type=1&offset=0&total=true&limit=5";
+                    string _result = m_netUtil.HttpPost(_requestUrl, "http://music.163.com", Encoding.UTF8, _postData);
+
+                    string _sid = getSID(_result);
+                    if (_sid == null) item.Value.Image = false;
+
+                    //获得专辑图像
+                    string songURL = "http://music.163.com/api/song/detail/?id=" + _sid + "&ids=%5B" + _sid + "%5D";
+                    _result = m_netUtil.HttpGet(songURL,"",Encoding.UTF8);
+
+                    string _imgUrl = getImage(_result);
+                    byte[] _imgData = new WebClient().DownloadData(_imgUrl);
+                    ID3Info _info = new ID3Info(item.Value.Path, true);
+                    if(_info.ID3v2Info.AttachedPictureFrames.Count == 0)
+                    {
+                        _info.ID3v2Info.AttachedPictureFrames.Add(new ID3.ID3v2Frames.BinaryFrames.AttachedPictureFrame(0,"",TextEncodings.Ascii, "image/jpeg",PictureTypes.Media, new MemoryStream(_imgData)));
+                    }
+                    else
+                    {
+                        _info.ID3v2Info.AttachedPictureFrames.Items[0].Data = new MemoryStream(_imgData);
+                    }
+
+                    _info.ID3v2Info.Save();
+                }
+            }
+        }
+
+        private string getSID(string json)
+        {
+            JObject _jsonSid = JObject.Parse(json);
+            if (!json.Contains("result")) return null;
+            if (_jsonSid["result"]["songCount"].Value<int>() == 0)
+            {
+                return null;
+            }
+
+            JArray _jarraySID = (JArray)_jsonSid["result"]["songs"];
+            return _jarraySID[0]["id"].ToString();
+        }
+
+        private string getImage(string json)
+        {
+            JArray _songs = (JArray)JObject.Parse(json)["songs"];
+            return _songs[0]["album"]["picUrl"].ToString();
+        }
+    }
+}

+ 77 - 0
LibMusicAlbumImage/LibMusicAlbumImage.csproj

@@ -0,0 +1,77 @@
+<?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>{183EA70D-BB26-4AD1-80EC-904D68C3AD98}</ProjectGuid>
+    <OutputType>Library</OutputType>
+    <AppDesignerFolder>Properties</AppDesignerFolder>
+    <RootNamespace>LibMusicAlbumImage</RootNamespace>
+    <AssemblyName>LibMusicAlbumImage</AssemblyName>
+    <TargetFrameworkVersion>v4.5.1</TargetFrameworkVersion>
+    <FileAlignment>512</FileAlignment>
+  </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="ID3">
+      <HintPath>..\ZonyLrcDownLoad 4\DLL\ID3.dll</HintPath>
+    </Reference>
+    <Reference Include="Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
+      <HintPath>..\packages\Newtonsoft.Json.9.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
+      <Private>True</Private>
+    </Reference>
+    <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="LibMusicAlbumImage.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>
+  <ItemGroup>
+    <None Include="packages.config" />
+  </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
LibMusicAlbumImage/Properties/AssemblyInfo.cs

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

+ 4 - 0
LibMusicAlbumImage/packages.config

@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<packages>
+  <package id="Newtonsoft.Json" version="9.0.1" targetFramework="net451" />
+</packages>

+ 2 - 4
LibMusicInfoRead/LibMusicInfoRead.cs

@@ -26,10 +26,8 @@ namespace LibMusicInfoRead
                 string _name = _info.ID3v1Info.Title == null ? _info.ID3v2Info.GetTextFrame("TIT2") : _info.ID3v1Info.Title;
                 string _artist = _info.ID3v1Info.Artist == null ? _info.ID3v2Info.GetTextFrame("TPE1") : _info.ID3v1Info.Artist;
 
-                if(_name.Equals(""))
-                    _name = Path.GetFileNameWithoutExtension(_path);
-                if(_artist.Equals(""))
-                    _name = Path.GetFileNameWithoutExtension(_path);
+                if(_name.Equals("")) _name = Path.GetFileNameWithoutExtension(_path);
+                if(_artist.Equals("")) _name = Path.GetFileNameWithoutExtension(_path);
 
                 item.Value.SongName = _name;
                 item.Value.Artist = _artist;

+ 1 - 1
LibPlugins/ResourceShareModel.cs

@@ -35,7 +35,7 @@ namespace LibPlugins
         /// <summary>
         /// 专辑图像
         /// </summary>
-        public string Image { get; set; }
+        public bool Image { get; set; }
     }
 
     /// <summary>

+ 6 - 0
ZonyLrcDownLoad 4.sln

@@ -15,6 +15,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibLrcNetease", "LibLrcNete
 EndProject
 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibLrcBaiDu.cs", "LibLrcBaiDu.cs\LibLrcBaiDu.cs.csproj", "{9058E9CD-2BC0-44F9-B994-8A9041AFFFB7}"
 EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMusicAlbumImage", "LibMusicAlbumImage\LibMusicAlbumImage.csproj", "{183EA70D-BB26-4AD1-80EC-904D68C3AD98}"
+EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
 		Debug|Any CPU = Debug|Any CPU
@@ -45,6 +47,10 @@ Global
 		{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
+		{183EA70D-BB26-4AD1-80EC-904D68C3AD98}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+		{183EA70D-BB26-4AD1-80EC-904D68C3AD98}.Debug|Any CPU.Build.0 = Debug|Any CPU
+		{183EA70D-BB26-4AD1-80EC-904D68C3AD98}.Release|Any CPU.ActiveCfg = Release|Any CPU
+		{183EA70D-BB26-4AD1-80EC-904D68C3AD98}.Release|Any CPU.Build.0 = Release|Any CPU
 	EndGlobalSection
 	GlobalSection(SolutionProperties) = preSolution
 		HideSolutionNode = FALSE

+ 10 - 10
ZonyLrcDownLoad 4/Windows/WindowDonate.Designer.cs

@@ -44,7 +44,7 @@
             // 
             // button1
             // 
-            this.button1.Location = new System.Drawing.Point(77, 327);
+            this.button1.Location = new System.Drawing.Point(118, 327);
             this.button1.Name = "button1";
             this.button1.Size = new System.Drawing.Size(75, 23);
             this.button1.TabIndex = 7;
@@ -59,7 +59,7 @@
             this.groupBox3.Controls.Add(this.label2);
             this.groupBox3.Location = new System.Drawing.Point(21, 225);
             this.groupBox3.Name = "groupBox3";
-            this.groupBox3.Size = new System.Drawing.Size(200, 96);
+            this.groupBox3.Size = new System.Drawing.Size(268, 96);
             this.groupBox3.TabIndex = 6;
             this.groupBox3.TabStop = false;
             this.groupBox3.Text = "作者信息";
@@ -67,7 +67,7 @@
             // label4
             // 
             this.label4.AutoSize = true;
-            this.label4.Location = new System.Drawing.Point(16, 70);
+            this.label4.Location = new System.Drawing.Point(57, 70);
             this.label4.Name = "label4";
             this.label4.Size = new System.Drawing.Size(161, 12);
             this.label4.TabIndex = 2;
@@ -76,7 +76,7 @@
             // label3
             // 
             this.label3.AutoSize = true;
-            this.label3.Location = new System.Drawing.Point(28, 49);
+            this.label3.Location = new System.Drawing.Point(69, 49);
             this.label3.Name = "label3";
             this.label3.Size = new System.Drawing.Size(137, 12);
             this.label3.TabIndex = 1;
@@ -85,7 +85,7 @@
             // label2
             // 
             this.label2.AutoSize = true;
-            this.label2.Location = new System.Drawing.Point(54, 27);
+            this.label2.Location = new System.Drawing.Point(95, 27);
             this.label2.Name = "label2";
             this.label2.Size = new System.Drawing.Size(77, 12);
             this.label2.TabIndex = 0;
@@ -96,7 +96,7 @@
             this.groupBox2.Controls.Add(this.textBox_DonateUsers);
             this.groupBox2.Location = new System.Drawing.Point(21, 84);
             this.groupBox2.Name = "groupBox2";
-            this.groupBox2.Size = new System.Drawing.Size(200, 135);
+            this.groupBox2.Size = new System.Drawing.Size(274, 135);
             this.groupBox2.TabIndex = 5;
             this.groupBox2.TabStop = false;
             this.groupBox2.Text = "十分感谢以下捐赠者";
@@ -109,7 +109,7 @@
             this.textBox_DonateUsers.Name = "textBox_DonateUsers";
             this.textBox_DonateUsers.ReadOnly = true;
             this.textBox_DonateUsers.ScrollBars = System.Windows.Forms.ScrollBars.Both;
-            this.textBox_DonateUsers.Size = new System.Drawing.Size(186, 109);
+            this.textBox_DonateUsers.Size = new System.Drawing.Size(260, 109);
             this.textBox_DonateUsers.TabIndex = 0;
             // 
             // groupBox1
@@ -117,7 +117,7 @@
             this.groupBox1.Controls.Add(this.label1);
             this.groupBox1.Location = new System.Drawing.Point(21, 13);
             this.groupBox1.Name = "groupBox1";
-            this.groupBox1.Size = new System.Drawing.Size(200, 65);
+            this.groupBox1.Size = new System.Drawing.Size(274, 65);
             this.groupBox1.TabIndex = 4;
             this.groupBox1.TabStop = false;
             this.groupBox1.Text = "作者的话";
@@ -126,7 +126,7 @@
             // 
             this.label1.Location = new System.Drawing.Point(6, 17);
             this.label1.Name = "label1";
-            this.label1.Size = new System.Drawing.Size(188, 42);
+            this.label1.Size = new System.Drawing.Size(262, 42);
             this.label1.TabIndex = 2;
             this.label1.Text = "如果您觉得本工具帮助到您了,可以选择捐赠作者来让工具更加完善,作者也十分感谢您的支持。";
             // 
@@ -134,7 +134,7 @@
             // 
             this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
-            this.ClientSize = new System.Drawing.Size(242, 362);
+            this.ClientSize = new System.Drawing.Size(315, 362);
             this.Controls.Add(this.button1);
             this.Controls.Add(this.groupBox3);
             this.Controls.Add(this.groupBox2);

+ 19 - 6
ZonyLrcDownLoad 4/Windows/WindowMain.cs

@@ -10,6 +10,7 @@ using System.Threading;
 using System.IO;
 using System.Text;
 using System.Collections.Generic;
+using LibPlugins.Enum;
 
 namespace ZonyLrcDownLoad_4.Windows
 {
@@ -23,7 +24,11 @@ namespace ZonyLrcDownLoad_4.Windows
         #region 界面交互
         private void toolStripButton_DownLoad_Click(object sender, EventArgs e)
         {
-            
+            foreach (var item in Longlife.ExpManager.Plugins)
+            {
+                if (item.Info.Type == NativePluginsType.AlbumImg)
+                    item.Init(ref Longlife.ShareResource);
+            }
         }
 
         private void WindowMain_Load(object sender, EventArgs e)
@@ -104,10 +109,7 @@ namespace ZonyLrcDownLoad_4.Windows
                     }).Start();
 
                 }
-                else
-                {
-                    setBottomStateText("错误", "扫描文件时发生错误!");
-                }
+                else setBottomStateText("错误", "扫描文件时发生错误!");
             }
 
             #region 启用控件
@@ -170,7 +172,11 @@ namespace ZonyLrcDownLoad_4.Windows
         /// </summary>
         private void getMusicName()
         {
-            Longlife.ExpManager.Plugins[0].Init(ref Longlife.ShareResource);
+            foreach(var item in Longlife.ExpManager.Plugins)
+            {
+                if (item.Info.Type == NativePluginsType.Mp3Tag)
+                    item.Init(ref Longlife.ShareResource);
+            }
         }
         #endregion
 
@@ -190,5 +196,12 @@ namespace ZonyLrcDownLoad_4.Windows
             }
         }
         #endregion
+
+        #region [私有方法]-读取专辑信息
+        private void getMusicAlbumInfo()
+        {
+
+        }
+        #endregion
     }
 }