Skip to content
This repository has been archived by the owner on Dec 6, 2022. It is now read-only.

Commit

Permalink
Prerelease fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
avdynut committed Aug 5, 2019
1 parent 4c0908f commit f478e1c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
1 change: 0 additions & 1 deletion AimpLyrics/AimpLyrics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
<Reference Include="AIMP.SDK, Version=4.50.2048.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\AimpSDK.4.50.2048\lib\net462\AIMP.SDK.dll</HintPath>
</Reference>
<Reference Include="Microsoft.CSharp" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
<Reference Include="System" />
Expand Down
7 changes: 6 additions & 1 deletion AimpLyrics/AimpLyricsPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,12 @@ private void AddMenuItem()
action.Id = "aimp.lyrics.open.window";
action.Name = "Open Lyrics";
action.GroupName = "Lyrics";
action.OnExecute += (sender, args) => _lyricsWindow.Show();

action.OnExecute += (sender, args) =>
{
_lyricsWindow.Show();
_lyricsWindow.Activate();
};

menuItem.Action = action;
Player.ActionManager.Register(action);
Expand Down
2 changes: 1 addition & 1 deletion AimpLyrics/LyricsWIndow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
<TextBox Grid.Row="1" Name="Lyrics" AcceptsReturn="True" VerticalScrollBarVisibility="Auto" TextWrapping="Wrap"
FontSize="{Binding ElementName=FontSize, Path=Text}" Margin="2"/>
<StackPanel Grid.Row="2" Orientation="Horizontal">
<TextBlock Text="Lyrics Source: "/>
<TextBlock Text="Lyrics Source: " Margin="2,0"/>
<TextBlock Name="Source"/>
</StackPanel>
<StackPanel Grid.Row="3" Orientation="Horizontal">
Expand Down
32 changes: 23 additions & 9 deletions AimpLyrics/LyricsWIndow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public LyricsWindow(IAimpPlayer player, AimpMessageHook hook)
#if DEBUG
BrowserPanel.Visibility = Visibility.Visible;
#endif
UpdateSongInfo();
Loaded += (s, e) => UpdateSongInfo();
}

private void UpdateSongInfo()
Expand All @@ -43,14 +43,10 @@ private void UpdateSongInfo()
Artist.Text = _fileInfo.Artist;
Title.Text = _fileInfo.Title;

if (!GetLyricsFromFile() && !string.IsNullOrEmpty(_fileInfo.Lyrics))
{
Lyrics.Text = _fileInfo.Lyrics;
_source = LyricsSource.Tag;
Source.Text = _source.ToString();
Trace.WriteLine("Lyrics received from lyrics tag");
}
else
bool found = GetLyricsFromFile();
if (!found)
found = GetLyricsFromTag();
if (!found)
SearchLyricsInGoogle();
}

Expand Down Expand Up @@ -78,6 +74,18 @@ private bool GetLyricsFromFile()
return true;
}

private bool GetLyricsFromTag()
{
if (string.IsNullOrEmpty(_fileInfo.Lyrics))
return false;

Lyrics.Text = _fileInfo.Lyrics;
_source = LyricsSource.Tag;
Source.Text = _source.ToString();
Trace.WriteLine("Lyrics received from lyrics tag");
return true;
}

private void SearchLyricsInGoogle()
{
string searchTerm = HttpUtility.UrlEncode($"{Artist.Text} {Title.Text} lyrics");
Expand Down Expand Up @@ -106,6 +114,11 @@ private void OnBrowserLoadCompleted(object sender, NavigationEventArgs e)
break;
}
}
if (_source == LyricsSource.None)
{
Trace.WriteLine("Lyrics not found");
Source.Text = "Not Found";
}
}

private void SaveLyricsToFile()
Expand Down Expand Up @@ -143,6 +156,7 @@ private void SaveLyrics(object sender, RoutedEventArgs e)
case LyricsSource.Google:
_filePath = Path.ChangeExtension(_fileInfo.FileName, "txt");
_source = LyricsSource.File;
Source.Text = Path.GetFileName(_filePath);
SaveLyricsToFile();
break;
}
Expand Down

0 comments on commit f478e1c

Please sign in to comment.