Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dotnet-standard'
Browse files Browse the repository at this point in the history
  • Loading branch information
marihachi committed Jun 16, 2018
2 parents f441aae + 52a5a85 commit 8e4422f
Show file tree
Hide file tree
Showing 13 changed files with 110 additions and 197 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="15.0" 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>{78712AFD-200B-4EBE-83D6-900AD6987343}</ProjectGuid>
<ProjectGuid>{442F1894-255A-4012-B20D-89A4AF86CC1C}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AlbumArtExtraction.CommandLine</RootNamespace>
<AssemblyName>AlbumArtExtraction.CommandLine</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
Expand All @@ -22,6 +22,7 @@
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand All @@ -31,6 +32,7 @@
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
Expand All @@ -48,20 +50,15 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="App.config">
<SubType>Designer</SubType>
</None>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\AlbumArtExtraction\AlbumArtExtraction.csproj">
<Project>{89bd928a-0196-47d5-be87-9deb0947b9a5}</Project>
<Project>{43b10c95-8bc7-4191-bc76-b7cce291af84}</Project>
<Name>AlbumArtExtraction</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>
9 changes: 6 additions & 3 deletions AlbumArtExtraction.CommandLine/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
</startup>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6"/>
</startup>
</configuration>
47 changes: 32 additions & 15 deletions AlbumArtExtraction.CommandLine/Program.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;

namespace AlbumArtExtraction.CommandLine {
class Program {
static void Main(string[] args) {
namespace AlbumArtExtraction.CommandLine
{
class Program
{
static void Main(string[] args)
{
var optionArgs =
from arg in args
where arg.StartsWith("-")
Expand All @@ -22,32 +26,40 @@ from arg in args
string inputPath, outputPath;

// inputPath
if (mainArgs.Count() == 1) {
if (mainArgs.Count() == 1)
{
inputPath = mainArgs.ElementAt(0);
outputPath = Path.Combine(Path.GetDirectoryName(inputPath), Path.GetFileNameWithoutExtension(inputPath));
}
// inputPath, outputPath
else if (mainArgs.Count() == 2) {
else if (mainArgs.Count() == 2)
{
inputPath = mainArgs.ElementAt(0);
outputPath = mainArgs.ElementAt(1);
}
else {
else
{
Usage();
return;
}

try {
try
{
var selector = new Selector();
var extractor = selector.SelectAlbumArtExtractor(inputPath);
Console.WriteLine($"selected extractor: {extractor}");

using (var albumArt = extractor.Extract(inputPath)) {
using (var source = extractor.Extract(inputPath))
{
var albumArt = new Bitmap(source);
var format = albumArt.RawFormat;
outputPath += (format == ImageFormat.Png) ? ".png" : ".jpg";
if (!noConfirm && File.Exists(outputPath)) {
if (!noConfirm && File.Exists(outputPath))
{
Console.Write("file name already exists. do you want to overwrite it? (y/n) ");
var input = Console.ReadLine();
if (!input.ToLower().StartsWith("y")) {
if (!input.ToLower().StartsWith("y"))
{
return;
}
}
Expand All @@ -58,30 +70,35 @@ from arg in args
Console.WriteLine($"file creation succeeded: {outputPath}");
Console.ResetColor();
}
catch(FileNotFoundException) {
catch (FileNotFoundException)
{
Error(() => Console.WriteLine($"input file is not found: {inputPath}"));
}
catch(NotSupportedException ex) {
catch (NotSupportedException ex)
{
Error(() => {
Console.WriteLine($"format of input file is not supported:");
Console.WriteLine(ex);
});
}
catch(Exception ex) {
catch (Exception ex)
{
Error(() => {
Console.WriteLine($"error:");
Console.WriteLine(ex);
});
}
}

static void Error(Action content) {
static void Error(Action content)
{
Console.ForegroundColor = ConsoleColor.Red;
content();
Console.ResetColor();
}

static void Usage() {
static void Usage()
{
Console.WriteLine();
Console.WriteLine("Usage:");
Console.WriteLine();
Expand Down
14 changes: 7 additions & 7 deletions AlbumArtExtraction.CommandLine/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,22 @@
// アセンブリに関する一般情報は以下の属性セットをとおして制御されます。
// アセンブリに関連付けられている情報を変更するには、
// これらの属性値を変更してください。
[assembly: AssemblyTitle("AlbumArtExtraction.CommandLine")]
[assembly: AssemblyTitle("AlbumArtExtraction.Console")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AlbumArtExtraction.CommandLine")]
[assembly: AssemblyCopyright("Copyright © 2017 Legato-Dev")]
[assembly: AssemblyProduct("AlbumArtExtraction.Console")]
[assembly: AssemblyCopyright("Copyright © 2018")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// ComVisible を false に設定すると、その型はこのアセンブリ内で COM コンポーネントから
// 参照不可能になります。COM からこのアセンブリ内の型にアクセスする場合は
// ComVisible を false に設定すると、このアセンブリ内の型は COM コンポーネントから
// 参照できなくなります。COM からこのアセンブリ内の型にアクセスする必要がある場合は
// その型の ComVisible 属性を true に設定してください。
[assembly: ComVisible(false)]

// このプロジェクトが COM に公開される場合、次の GUID が typelib の ID になります
[assembly: Guid("78712afd-200b-4ebe-83d6-900ad6987343")]
[assembly: Guid("442f1894-255a-4012-b20d-89a4af86cc1c")]

// アセンブリのバージョン情報は次の 4 つの値で構成されています:
//
Expand All @@ -29,7 +29,7 @@
// ビルド番号
// Revision
//
// すべての値を指定するか、下のように '*' を使ってビルドおよびリビジョン番号を
// すべての値を指定するか、次を使用してビルド番号とリビジョン番号を既定に設定できます
// 既定値にすることができます:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
Expand Down
27 changes: 15 additions & 12 deletions AlbumArtExtraction.sln
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
# Visual Studio 15
VisualStudioVersion = 15.0.27428.2043
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlbumArtExtraction", "AlbumArtExtraction\AlbumArtExtraction.csproj", "{89BD928A-0196-47D5-BE87-9DEB0947B9A5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AlbumArtExtraction", "AlbumArtExtraction\AlbumArtExtraction.csproj", "{43B10C95-8BC7-4191-BC76-B7CCE291AF84}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlbumArtExtraction.CommandLine", "AlbumArtExtraction.CommandLine\AlbumArtExtraction.CommandLine.csproj", "{78712AFD-200B-4EBE-83D6-900AD6987343}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AlbumArtExtraction.CommandLine", "AlbumArtExtraction.CommandLine\AlbumArtExtraction.CommandLine.csproj", "{442F1894-255A-4012-B20D-89A4AF86CC1C}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{89BD928A-0196-47D5-BE87-9DEB0947B9A5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{89BD928A-0196-47D5-BE87-9DEB0947B9A5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{89BD928A-0196-47D5-BE87-9DEB0947B9A5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{89BD928A-0196-47D5-BE87-9DEB0947B9A5}.Release|Any CPU.Build.0 = Release|Any CPU
{78712AFD-200B-4EBE-83D6-900AD6987343}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{78712AFD-200B-4EBE-83D6-900AD6987343}.Debug|Any CPU.Build.0 = Debug|Any CPU
{78712AFD-200B-4EBE-83D6-900AD6987343}.Release|Any CPU.ActiveCfg = Release|Any CPU
{78712AFD-200B-4EBE-83D6-900AD6987343}.Release|Any CPU.Build.0 = Release|Any CPU
{43B10C95-8BC7-4191-BC76-B7CCE291AF84}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{43B10C95-8BC7-4191-BC76-B7CCE291AF84}.Debug|Any CPU.Build.0 = Debug|Any CPU
{43B10C95-8BC7-4191-BC76-B7CCE291AF84}.Release|Any CPU.ActiveCfg = Release|Any CPU
{43B10C95-8BC7-4191-BC76-B7CCE291AF84}.Release|Any CPU.Build.0 = Release|Any CPU
{442F1894-255A-4012-B20D-89A4AF86CC1C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{442F1894-255A-4012-B20D-89A4AF86CC1C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{442F1894-255A-4012-B20D-89A4AF86CC1C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{442F1894-255A-4012-B20D-89A4AF86CC1C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DC603A10-E02A-463C-98AB-F1D8A3C0F4E4}
EndGlobalSection
EndGlobal
77 changes: 19 additions & 58 deletions AlbumArtExtraction/AlbumArtExtraction.csproj
Original file line number Diff line number Diff line change
@@ -1,62 +1,23 @@
<?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')" />
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{89BD928A-0196-47D5-BE87-9DEB0947B9A5}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>AlbumArtExtraction</RootNamespace>
<AssemblyName>AlbumArtExtraction</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<TargetFrameworkProfile />
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>false</GeneratePackageOnBuild>
<PackageRequireLicenseAcceptance>false</PackageRequireLicenseAcceptance>
<Description>A .NET library extracts album art from metadata such as FLAC, ID3, etc.</Description>
<Copyright>(C) 2018 Legato-Dev</Copyright>
<PackageLicenseUrl>https://github.com/Legato-Dev/AlbumArtExtraction/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/Legato-Dev/AlbumArtExtraction</PackageProjectUrl>
<PackageIconUrl>https://github.com/Legato-Dev/AlbumArtExtraction/raw/master/logo64.png</PackageIconUrl>
<PackageTags>ID3 MP3 FLAC AlbumArt Extraction NowPlaying CSharp</PackageTags>
<Version>1.0.0</Version>
</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>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard2.0\AlbumArtExtraction.xml</DocumentationFile>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Release\AlbumArtExtraction.xml</DocumentationFile>
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
<WarningLevel>2</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<Compile Include="DirectoryAlbumArtExtractor.cs" />
<Compile Include="StreamExtensions.cs" />
<Compile Include="IAlbumArtExtractor.cs" />
<Compile Include="FlacAlbumArtExtractor.cs" />
<Compile Include="ID3v22AlbumArtExtractor.cs" />
<Compile Include="ID3v2AlbumArtExtractor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Selector.cs" />
</ItemGroup>
<ItemGroup>
<None Include="AlbumArtExtraction.nuspec" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 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>

</Project>
18 changes: 0 additions & 18 deletions AlbumArtExtraction/AlbumArtExtraction.nuspec

This file was deleted.

10 changes: 7 additions & 3 deletions AlbumArtExtraction/DirectoryAlbumArtExtractor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;

Expand Down Expand Up @@ -39,13 +38,18 @@ public bool CheckType(string filePath) {
/// アルバムアートを抽出します
/// </summary>
/// <exception cref="FileNotFoundException" />
public Image Extract(string filePath) {
public Stream Extract(string filePath) {
if (!File.Exists(filePath))
throw new FileNotFoundException("指定されたファイルは存在しません");

var fileInfo = _GetFilesLikeAlbumArts(new FileInfo(filePath).Directory).ElementAt(0);

return Image.FromFile(fileInfo.FullName);
using (var file = new FileStream(fileInfo.FullName, FileMode.Open, FileAccess.Read))
{
var buf = new byte[file.Length];
file.Read(buf, 0, buf.Length);
return new MemoryStream(buf);
}
}
}
}
Loading

0 comments on commit 8e4422f

Please sign in to comment.