This repository has been archived by the owner on Oct 19, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
62,187 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
BeeDownloader/bin/ | ||
BeeDownloader/obj/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio 2013 | ||
VisualStudioVersion = 12.0.30501.0 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BeeDownloader", "BeeDownloader\BeeDownloader.csproj", "{39FAF62E-9B9A-4BB4-9504-A820DBEBE647}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Release|Any CPU = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{39FAF62E-9B9A-4BB4-9504-A820DBEBE647}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{39FAF62E-9B9A-4BB4-9504-A820DBEBE647}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{39FAF62E-9B9A-4BB4-9504-A820DBEBE647}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{39FAF62E-9B9A-4BB4-9504-A820DBEBE647}.Release|Any CPU.Build.0 = Release|Any CPU | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
EndGlobal |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project ToolsVersion="12.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>{39FAF62E-9B9A-4BB4-9504-A820DBEBE647}</ProjectGuid> | ||
<OutputType>Library</OutputType> | ||
<AppDesignerFolder>Properties</AppDesignerFolder> | ||
<RootNamespace>BeeDownloader</RootNamespace> | ||
<AssemblyName>mb_BeeDownloader</AssemblyName> | ||
<TargetFrameworkVersion>v4.0</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> | ||
<PlatformTarget>x86</PlatformTarget> | ||
</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="Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL"> | ||
<HintPath>..\packages\Newtonsoft.Json.5.0.8\lib\net40\Newtonsoft.Json.dll</HintPath> | ||
</Reference> | ||
<Reference Include="policy.2.0.taglib-sharp"> | ||
<HintPath>..\packages\taglib.2.1.0.0\lib\policy.2.0.taglib-sharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
<Reference Include="System.Drawing" /> | ||
<Reference Include="System.Windows.Forms" /> | ||
<Reference Include="System.Xml.Linq" /> | ||
<Reference Include="System.Data.DataSetExtensions" /> | ||
<Reference Include="Microsoft.CSharp" /> | ||
<Reference Include="System.Data" /> | ||
<Reference Include="System.Xml" /> | ||
<Reference Include="taglib-sharp"> | ||
<HintPath>..\packages\taglib.2.1.0.0\lib\taglib-sharp.dll</HintPath> | ||
</Reference> | ||
<Reference Include="YoutubeExtractor"> | ||
<HintPath>..\packages\YoutubeExtractor.0.10.1\lib\net35\YoutubeExtractor.dll</HintPath> | ||
</Reference> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="Downloader\DownloaderTask.cs" /> | ||
<Compile Include="Downloader\DownloadVideo.cs" /> | ||
<Compile Include="MusicBeePugin\BeeDownloaderPlugin.cs" /> | ||
<Compile Include="MusicBeePugin\MusicBeeInterface.cs" /> | ||
<Compile Include="PluginLogic.cs" /> | ||
<Compile Include="PluginSettings.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Properties\Resources.Designer.cs"> | ||
<AutoGen>True</AutoGen> | ||
<DesignTime>True</DesignTime> | ||
<DependentUpon>Resources.resx</DependentUpon> | ||
</Compile> | ||
<Compile Include="Views\DownloaderWindow.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="Views\DownloaderWindow.Designer.cs"> | ||
<DependentUpon>DownloaderWindow.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Views\SettingsWindow.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="Views\SettingsWindow.Designer.cs"> | ||
<DependentUpon>SettingsWindow.cs</DependentUpon> | ||
</Compile> | ||
<Compile Include="Views\TagEditor.cs"> | ||
<SubType>Form</SubType> | ||
</Compile> | ||
<Compile Include="Views\TagEditor.Designer.cs"> | ||
<DependentUpon>TagEditor.cs</DependentUpon> | ||
</Compile> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<EmbeddedResource Include="Properties\Resources.resx"> | ||
<Generator>ResXFileCodeGenerator</Generator> | ||
<LastGenOutput>Resources.Designer.cs</LastGenOutput> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Views\DownloaderWindow.resx"> | ||
<DependentUpon>DownloaderWindow.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Views\SettingsWindow.resx"> | ||
<DependentUpon>SettingsWindow.cs</DependentUpon> | ||
</EmbeddedResource> | ||
<EmbeddedResource Include="Views\TagEditor.resx"> | ||
<DependentUpon>TagEditor.cs</DependentUpon> | ||
</EmbeddedResource> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="Resources\swap.png" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> | ||
<PropertyGroup> | ||
<PostBuildEvent>REM xcopy /Y "$(TargetDir)$(TargetFileName)" "C:\Program Files (x86)\MusicBee\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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// (c) 2014 Kahlert | ||
// This code is licensed under MIT license (see LICENSE.md for details) | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using YoutubeExtractor; | ||
|
||
namespace BeeDownloader.Downloader | ||
{ | ||
public class DownloadVideo | ||
{ | ||
public readonly string Title; | ||
public readonly string Artist; | ||
public readonly VideoInfo Info; | ||
|
||
public DownloadVideo(string title, string artist, VideoInfo info) | ||
{ | ||
Title = title; | ||
Artist = artist; | ||
Info = info; | ||
} | ||
|
||
public string OriginalTitle { get { return Info.Title; } } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// (c) 2014 Kahlert | ||
// This code is licensed under MIT license (see LICENSE.md for details) | ||
using System; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using YoutubeExtractor; | ||
using System.IO; | ||
using MusicBeePlugin; | ||
using System.Text.RegularExpressions; | ||
using System.Windows.Forms; | ||
|
||
namespace BeeDownloader.Downloader | ||
{ | ||
public class DownloaderTask | ||
{ | ||
public delegate void StateChangeEvent(String status, double progress); | ||
public event StateChangeEvent ProgressEvent; | ||
|
||
private bool mRunning = true; | ||
private PluginSettings mSettings; | ||
private BackgroundWorker mWorker; | ||
private ConcurrentQueue<DownloadVideo> mPendingVideos; | ||
private DownloadVideo mCurrentVideoDownload; | ||
private Plugin.MusicBeeApiInterface mApi; | ||
|
||
public bool Running | ||
{ | ||
get { return mRunning; } | ||
set | ||
{ | ||
if(mRunning = value) | ||
{ | ||
if (!mPendingVideos.IsEmpty && !mWorker.IsBusy) | ||
mWorker.RunWorkerAsync(); | ||
}else | ||
{ | ||
if(mWorker.IsBusy) | ||
mWorker.CancelAsync(); | ||
} | ||
} | ||
} | ||
|
||
public DownloaderTask(Plugin.MusicBeeApiInterface api, PluginSettings settings) | ||
{ | ||
mApi = api; | ||
mSettings = settings; | ||
mPendingVideos = new ConcurrentQueue<DownloadVideo>(); | ||
mWorker = new BackgroundWorker(); | ||
mWorker.DoWork += Run; | ||
mWorker.RunWorkerCompleted += Completed; | ||
mWorker.WorkerSupportsCancellation = true; | ||
} | ||
|
||
public DownloadVideo CurrentVideo | ||
{ | ||
get { return mCurrentVideoDownload; } | ||
} | ||
|
||
public IEnumerable<DownloadVideo> PendingVideos | ||
{ | ||
get { return mPendingVideos.AsEnumerable(); } | ||
} | ||
|
||
public void AddVideo(DownloadVideo video) | ||
{ | ||
mPendingVideos.Enqueue(video); | ||
Running = true; | ||
} | ||
|
||
|
||
private void Run(object sender, DoWorkEventArgs e) | ||
{ | ||
BackgroundWorker worker = sender as BackgroundWorker; | ||
|
||
while(!mWorker.CancellationPending && mPendingVideos.TryDequeue(out mCurrentVideoDownload)) | ||
{ | ||
var video = mCurrentVideoDownload.Info; | ||
var target = Path.Combine(mSettings.DownloadFolder, FixFilePath(video.Title + video.AudioExtension)); | ||
var audioDownloader = new AudioDownloader(video, target); | ||
|
||
ProgressEvent("Start downloading...", 0.0); | ||
ProgressEvent("Target file: " + target, 0.0); | ||
|
||
// set events | ||
const double downloadPart = 0.95; | ||
|
||
audioDownloader.DownloadProgressChanged += | ||
(s, args) => | ||
{ | ||
if(worker.CancellationPending) | ||
args.Cancel = true; | ||
ProgressEvent(null, args.ProgressPercentage / 100.0 * downloadPart); | ||
}; | ||
|
||
audioDownloader.AudioExtractionProgressChanged += | ||
(s, args) => | ||
{ | ||
if (worker.CancellationPending) | ||
args.Cancel = true; | ||
ProgressEvent(null, downloadPart + args.ProgressPercentage / 100.0 * (1 - downloadPart)); | ||
}; | ||
|
||
audioDownloader.DownloadFinished += | ||
(s, args) => | ||
{ | ||
ProgressEvent("File downloaded!", downloadPart); | ||
ProgressEvent("Start extracting...", downloadPart); | ||
}; | ||
|
||
// Download and extract... | ||
try | ||
{ | ||
audioDownloader.Execute(); | ||
}catch(Exception ex) | ||
{ | ||
ProgressEvent("Error: " + ex.Message, 1.0); | ||
continue; | ||
} | ||
|
||
if(worker.CancellationPending) | ||
{ | ||
mPendingVideos.Enqueue(mCurrentVideoDownload); | ||
} | ||
else | ||
{ | ||
// Done | ||
ProgressEvent("Audio track extracted!", 1.0); | ||
|
||
if (mSettings.SetMediaTags) | ||
{ | ||
var tags = TagLib.File.Create(target); | ||
tags.Tag.Title = mCurrentVideoDownload.Title; | ||
tags.Tag.Performers = new string[] { mCurrentVideoDownload.Artist }; | ||
tags.Save(); | ||
} | ||
|
||
if (mSettings.MoveDownloadedFilesToInbox) | ||
{ | ||
ProgressEvent("Move audio file to inbox...", 1.0); | ||
mApi.Library_AddFileToLibrary(target, Plugin.LibraryCategory.Inbox); | ||
} | ||
|
||
ProgressEvent("Done.", 1.0); | ||
} | ||
|
||
|
||
mCurrentVideoDownload = null; | ||
} | ||
|
||
e.Cancel = worker.CancellationPending; | ||
} | ||
|
||
|
||
|
||
private void Completed(object sender, RunWorkerCompletedEventArgs e) | ||
{ | ||
if(e.Error != null) | ||
{ | ||
MessageBox.Show("Error in background worker: " + e.Error.Message); | ||
}else if(e.Cancelled) | ||
{ | ||
ProgressEvent("Downloading canceled!", 0.0); | ||
} | ||
else | ||
{ | ||
ProgressEvent("All videos downloaded! No pending videos left!", 0.0f); | ||
} | ||
} | ||
|
||
|
||
private string FixFilePath(string input) | ||
{ | ||
string regexSearch = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars()); | ||
Regex r = new Regex(string.Format("[{0}]", Regex.Escape(regexSearch))); | ||
return r.Replace(input, ""); | ||
} | ||
} | ||
} |
Oops, something went wrong.