Skip to content

Commit

Permalink
Support for Deezer Web Player added
Browse files Browse the repository at this point in the history
FetchYoutube is now FetchBrowser and takes a website as a parameter

Deezer Desktop App won't work as Deezer Desktop App doesn't change the title of the window.
Deezer API won't work as there is no endpoint for the currently playing song.
  • Loading branch information
Cyklan committed Jun 16, 2019
1 parent f7cff7a commit f7bde09
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 22 deletions.
1 change: 1 addition & 0 deletions Songify Slim/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@
<ComboBoxItem Content = "Nightbot"/>
<ComboBoxItem Content="VLC"/>
<ComboBoxItem Content="foobar2000"/>
<ComboBoxItem Content="Deezer (Chrome)" />
</ComboBox>
</Grid>
</controls:MetroWindow>
28 changes: 26 additions & 2 deletions Songify Slim/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -222,10 +222,10 @@ private void GetCurrentSong()

case 1:

#region Chrome
#region YouTube
// Fetching the song thats currently playing on youtube
// and updating the output on success
_temp = sf.FetchYoutube();
_temp = sf.FetchBrowser("YouTube");
if (string.IsNullOrWhiteSpace(_temp))
{
if (!string.IsNullOrWhiteSpace(_prevSong))
Expand Down Expand Up @@ -261,21 +261,45 @@ private void GetCurrentSong()
#endregion Nightbot

case 3:

#region VLC
currentlyPlaying = sf.FetchDesktopPlayer("vlc");
if (currentlyPlaying != null)
{
WriteSong(currentlyPlaying[0], currentlyPlaying[1], currentlyPlaying[2]);
}
break;

#endregion VLC

case 4:

#region foobar2000
currentlyPlaying = sf.FetchDesktopPlayer("foobar2000");
if (currentlyPlaying != null)
{
WriteSong(currentlyPlaying[0], currentlyPlaying[1], currentlyPlaying[2]);
}
break;

#endregion foobar2000

case 5:

#region Deezer
_temp = sf.FetchBrowser("Deezer");
if (string.IsNullOrWhiteSpace(_temp))
{
if (!string.IsNullOrWhiteSpace(_prevSong))
{
WriteSong(_prevSong, "", "");
}
break;
}
WriteSong(_temp, "", "");
break;

#endregion Deezer
}
}

Expand Down
69 changes: 49 additions & 20 deletions Songify Slim/SongFetcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public string[] FetchDesktopPlayer(string player)
/// </summary>
/// <param name="browser"></param>
/// <returns>Returns String with Youtube Video Title</returns>
public string FetchYoutube(string browser = "chrome")
public string FetchBrowser(string website, string browser = "chrome")
{
Process[] procsChrome = Process.GetProcessesByName(browser);
foreach (Process chrome in procsChrome)
Expand All @@ -156,26 +156,55 @@ public string FetchYoutube(string browser = "chrome")
foreach (AutomationElement elem in elementCollection)
{
// if the Tabitem Name contains Youtube
if (elem.Current.Name.Contains("YouTube"))
switch (website)
{
_parent = TreeWalker.RawViewWalker.GetParent(elem);
Console.WriteLine(elem.Current.Name);
// Regex pattern to replace the notification in front of the tab (1) - (99+)
string temp = Regex.Replace(elem.Current.Name, @"^\([\d]*(\d+)[\d]*\+*\)", "");
int index = temp.LastIndexOf("- YouTube", StringComparison.Ordinal);
// Remove everything after the last "-" int the string
// which is "- Youtube" and info that music is playing on this tab
if (index > 0)
temp = temp.Substring(0, index);
temp = temp.Trim();
Console.WriteLine(temp);

// Making sure that temp is not empty
// this makes sure that the output is not empty
if (!String.IsNullOrWhiteSpace(temp))
{
return temp;
}
case "YouTube":
if (elem.Current.Name.Contains("YouTube"))
{
_parent = TreeWalker.RawViewWalker.GetParent(elem);
Console.WriteLine(elem.Current.Name);
// Regex pattern to replace the notification in front of the tab (1) - (99+)
string temp = Regex.Replace(elem.Current.Name, @"^\([\d]*(\d+)[\d]*\+*\)", "");
int index = temp.LastIndexOf("- YouTube", StringComparison.Ordinal);
// Remove everything after the last "-" int the string
// which is "- Youtube" and info that music is playing on this tab
if (index > 0)
temp = temp.Substring(0, index);
temp = temp.Trim();
Console.WriteLine(temp);

// Making sure that temp is not empty
// this makes sure that the output is not empty
if (!String.IsNullOrWhiteSpace(temp))
{
return temp;
}
}
break;

case "Deezer":
if (elem.Current.Name.Contains("Deezer"))
{
_parent = TreeWalker.RawViewWalker.GetParent(elem);
Console.WriteLine(elem.Current.Name);
// Regex pattern to replace the notification in front of the tab (1) - (99+)
string temp = Regex.Replace(elem.Current.Name, @"^\([\d]*(\d+)[\d]*\+*\)", "");
int index = temp.LastIndexOf("- Deezer", StringComparison.Ordinal);
// Remove everything after the last "-" int the string
// which is "- Youtube" and info that music is playing on this tab
if (index > 0)
temp = temp.Substring(0, index);
temp = temp.Trim();
Console.WriteLine(temp);

// Making sure that temp is not empty
// this makes sure that the output is not empty
if (!String.IsNullOrWhiteSpace(temp))
{
return temp;
}
}
break;
}
}
}
Expand Down

0 comments on commit f7bde09

Please sign in to comment.