Browse Source

BatchProcess: upgrade project to net5; add in_dir lib mode

HOME 2 years ago
parent
commit
cecc66fdf3

+ 7 - 75
BatchProcess/BatchProcess.csproj

@@ -1,80 +1,12 @@
-<?xml version="1.0" encoding="utf-8"?>
-<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
-  <Import Project="C:\NuGetLocalRepo\ILRepack.2.0.18\build\ILRepack.props" Condition="Exists('C:\NuGetLocalRepo\ILRepack.2.0.18\build\ILRepack.props')" />
-  <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+<Project Sdk="Microsoft.NET.Sdk">
+
   <PropertyGroup>
-    <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
-    <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProjectGuid>{165C4021-2755-49B9-AB25-3EDAB449E2D5}</ProjectGuid>
     <OutputType>Exe</OutputType>
-    <RootNamespace>BatchProcess</RootNamespace>
-    <AssemblyName>BatchProcess</AssemblyName>
-    <TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
-    <FileAlignment>512</FileAlignment>
-    <AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
-    <NuGetPackageImportStamp>
-    </NuGetPackageImportStamp>
-    <TargetFrameworkProfile />
+    <TargetFramework>net5.0</TargetFramework>
   </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugSymbols>true</DebugSymbols>
-    <DebugType>full</DebugType>
-    <Optimize>false</Optimize>
-    <OutputPath>bin\Debug\</OutputPath>
-    <DefineConstants>DEBUG;TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <LangVersion>latest</LangVersion>
-  </PropertyGroup>
-  <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
-    <PlatformTarget>AnyCPU</PlatformTarget>
-    <DebugType>pdbonly</DebugType>
-    <Optimize>true</Optimize>
-    <OutputPath>bin\Release\</OutputPath>
-    <DefineConstants>TRACE</DefineConstants>
-    <ErrorReport>prompt</ErrorReport>
-    <WarningLevel>4</WarningLevel>
-    <LangVersion>latest</LangVersion>
-  </PropertyGroup>
-  <PropertyGroup>
-    <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
-  </PropertyGroup>
-  <ItemGroup>
-    <Reference Include="policy.2.0.taglib-sharp, Version=0.0.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
-      <HintPath>C:\NuGetLocalRepo\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.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" />
-    <Reference Include="taglib-sharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=db62eba44689b5b0, processorArchitecture=MSIL">
-      <HintPath>C:\NuGetLocalRepo\taglib.2.1.0.0\lib\taglib-sharp.dll</HintPath>
-      <Private>True</Private>
-    </Reference>
-  </ItemGroup>
-  <ItemGroup>
-    <Compile Include="Program.cs" />
-    <Compile Include="Properties\AssemblyInfo.cs" />
-  </ItemGroup>
+
   <ItemGroup>
-    <None Include="app.config" />
-    <None Include="packages.config" />
+    <PackageReference Include="taglib-sharp-netstandard2.0" Version="2.1.0" />
   </ItemGroup>
-  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
-  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
-    <PropertyGroup>
-      <ErrorText>这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。</ErrorText>
-    </PropertyGroup>
-    <Error Condition="!Exists('C:\NuGetLocalRepo\ILRepack.2.0.18\build\ILRepack.props')" Text="$([System.String]::Format('$(ErrorText)', 'C:\NuGetLocalRepo\ILRepack.2.0.18\build\ILRepack.props'))" />
-  </Target>
-  <PropertyGroup>
-    <PostBuildEvent>if $(ConfigurationName) == Release if not exist $(TargetDir)Packed md $(TargetDir)Packed
-if $(ConfigurationName) == Release $(ILRepack) /ndebug /out:$(TargetDir)Packed\$(TargetFileName) $(TargetPath) $(TargetDir)taglib-sharp.dll</PostBuildEvent>
-  </PropertyGroup>
-</Project>
+
+</Project>

+ 43 - 5
BatchProcess/Program.cs

@@ -33,7 +33,7 @@ namespace BatchProcess
             }
             catch (Exception e)
             {
-                Console.WriteLine($"ERROR:{e.GetType().Name},{e.Message}");
+                Console.WriteLine($"ERROR:{e}");
             }
 
             Console.WriteLine();
@@ -52,28 +52,30 @@ namespace BatchProcess
         private const string OP_EMB_LRC = "emblrc";
         private const string OP_CONVERT_FLAC_TO_AAC = "convert_flac_to_aac";
         private const string OP_CONVERT_LIB_FLAC_TO_AAC = "convert_lib_flac_to_aac";
+        private const string OP_CONVERT_LIB_FLAC_TO_AAC_IN_DIR = "convert_lib_flac_to_aac_in_dir";
 
         private static void RealMain(string[] args)
         {
             if (0 == args.Length)
             {
-                Console.WriteLine($"Usage: {Path.GetFileName(Assembly.GetExecutingAssembly().CodeBase)} <op> [args...]");
+                Console.WriteLine($"Usage: {Path.GetFileName(AppDomain.CurrentDomain.FriendlyName)} <op> [args...]");
                 Console.WriteLine($"Prefix ops:");
                 Console.WriteLine($" *  --no-pause");
                 Console.WriteLine($"        Disable enter key to exit");
                 Console.WriteLine($"Available ops:");
                 Console.WriteLine($" *  {OP_COPY} <sourcePath> <targetPath>");
                 Console.WriteLine($"        Copy tags from source to target (replace)");
+                Console.WriteLine($"        Note: Only standard tags and front cover");
                 Console.WriteLine($" *  {OP_EMB_LRC} <inputPath> <lrcPath> <outputPath>");
                 Console.WriteLine($"        Embed lyrics into file(utf8)");
                 Console.WriteLine($" *  {OP_EMB_COVER}|{OP_EMB_COVER_IF_NOT_EMBEDDED} <inputPath> <coverPath> [outputPath] [mime-type]");
                 Console.WriteLine($"        Embed cover into file, default mine-type is {MediaTypeNames.Image.Jpeg}");
                 Console.WriteLine($" *  {OP_EMB_COVER_IF_NOT_EMBEDDED_COVER_DOT_JPG} <inputPath>");
                 Console.WriteLine($"        Embed cover into file if not embedded, same folder cover.jpg");
-                Console.WriteLine($" *  {OP_DIR_EMB_COVER_MP3} <inputDir> <outputDir> -- lookup dir, embed same file name jpg/jpeg into mp3");
+                Console.WriteLine($" *  {OP_DIR_EMB_COVER_MP3} <inputDir> <outputDir>");
                 Console.WriteLine($"        Lookup dir, embed same file name jpg/jpeg into mp3");
                 Console.WriteLine($"        Embed abc.jpg or abc.jpeg into abc.mp3 and save a copy to output dir.");
-                Console.WriteLine($" *  {OP_DIR_EMB_COVER_M4A} <inputDir> <outputDir> -- lookup dir, embed same file name jpg/jpeg into m4a");
+                Console.WriteLine($" *  {OP_DIR_EMB_COVER_M4A} <inputDir> <outputDir>");
                 Console.WriteLine($"        Lookup dir, embed same file name jpg/jpeg into m4a");
                 Console.WriteLine($"        Embed abc.jpg or abc.jpeg into abc.m4a and save a copy to output dir.");
                 Console.WriteLine($" *  {OP_CONVERT_FLAC_TO_AAC} <inputPath> <outputPath> [q value]");
@@ -82,7 +84,9 @@ namespace BatchProcess
                 Console.WriteLine($"        Convert to aac and copy tags to output, default q is 1.0");
                 Console.WriteLine($"        inputDir/Album/Track.flac -> outputDir/Album/Track.m4a");
                 Console.WriteLine($"        Also copy inputDir/Album/cover.jpg to outDir/Album/cover.jpg if found");
-
+                Console.WriteLine($" *  {OP_CONVERT_LIB_FLAC_TO_AAC_IN_DIR} <libDir> [q value]");
+                Console.WriteLine($"        Convert to aac and copy tags to output, default q is 1.0");
+                Console.WriteLine($"        libDir/Album/Track.flac -> libDir/Album/AAC_Q1.00/Track.m4a");
                 Console.WriteLine($"");
                 Console.WriteLine($" +  More on demand");
                 return;
@@ -112,11 +116,45 @@ namespace BatchProcess
 
                 case OP_CONVERT_FLAC_TO_AAC: ConvertFlacToAac(argsToOp); break;
                 case OP_CONVERT_LIB_FLAC_TO_AAC: ConvertLibFlacToAac(argsToOp); break;
+                case OP_CONVERT_LIB_FLAC_TO_AAC_IN_DIR: ConvertLibFlacToAacInDir(argsToOp); break;
             }
         }
 
         // impl
 
+        private static void ConvertLibFlacToAacInDir(string[] args)
+        {
+            if (args.Length < 1) throw new ArgumentException("args least need 1");
+            var libDir = args[0];
+
+            if (false == Directory.Exists(libDir)) throw new DirectoryNotFoundException($"lib dir `{libDir}' not found.");
+
+            var q = args.Length > 1 && float.TryParse(args[1], out var tq) && tq is >= 0 and <= 1
+                ? tq
+                : 1.0;
+
+            foreach (var albDir in Directory.GetDirectories(libDir))
+            {
+                var outAlbDir = Path.Combine(albDir, $"AAC_Q{q:N2}");
+
+                if (false == Directory.Exists(outAlbDir))
+                {
+                    Console.WriteLine($"Create dir:{outAlbDir}");
+                    Directory.CreateDirectory(outAlbDir);
+                }
+
+                foreach (var flacPath in Directory.GetFiles(albDir, "*.flac"))
+                {
+                    var outM4APath = Path.Combine(outAlbDir, Path.ChangeExtension(Path.GetFileName(flacPath), ".m4a"));
+                    Console.WriteLine(
+                        ConvertFlacToAac(new[] {flacPath, outM4APath, $"{q}"}) 
+                            ? $"Convert OK. -> {outM4APath}" 
+                            : $"Exist, Skipped. {outM4APath}"
+                    );
+                }
+            }
+        }
+
         private static void ConvertLibFlacToAac(string[] args)
         {
             if (args.Length < 2) throw new ArgumentException("args least need 2");

+ 0 - 35
BatchProcess/Properties/AssemblyInfo.cs

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

+ 0 - 5
BatchProcess/packages.config

@@ -1,5 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<packages>
-  <package id="ILRepack" version="2.0.18" targetFramework="net461" />
-  <package id="taglib" version="2.1.0.0" targetFramework="net461" />
-</packages>