├── version.txt ├── SetupLinux └── AppImage │ └── AppDir │ ├── .DirIcon │ ├── swaglyrics_pfp.png │ ├── AppRun │ └── SwagLyricsGUI.desktop ├── Images ├── guidark.png ├── guilight.png └── guiswaglyrics.png ├── inno_compile.ps1 ├── SwagLyricsGUI ├── swaglyrics_pfp.ico ├── Assets │ ├── swaglyrics_pfp.ico │ ├── Fonts │ │ └── Roboto-Regular.ttf │ └── Styles │ │ └── SwagLyricsTheme.xaml ├── app.config ├── ViewModels │ ├── ViewModelBase.cs │ └── MainWindowViewModel.cs ├── Events │ ├── NewSongEventArgs.cs │ └── LyricsLoadedEventArgs.cs ├── Models │ ├── MathEx.cs │ ├── Fact.cs │ ├── Command.cs │ ├── RandomFactsFetcher.cs │ ├── ThemeManager.cs │ ├── BridgeManager.cs │ ├── PrerequisitesChecker.cs │ └── SwagLyricsBridge.cs ├── nuget.config ├── Bridge │ ├── swaglyrics_installer.py │ └── swaglyrics_api_bridge.py ├── App.xaml ├── App.xaml.cs ├── ViewLocator.cs ├── Program.cs ├── Views │ ├── MainWindow.xaml.cs │ └── MainWindow.xaml └── SwagLyricsGUI.csproj ├── SwagLyricsGUITests ├── ModelsTests │ └── MathExTests.cs └── SwagLyricsGUITests.csproj ├── LICENSE.md ├── README.md ├── setup_script_win_x64.iss ├── .github └── workflows │ ├── linux-setup-files.yml │ └── win-installer-action.yml ├── SwagLyricsGUI.sln └── .gitignore /version.txt: -------------------------------------------------------------------------------- 1 | v0.4.1 -------------------------------------------------------------------------------- /SetupLinux/AppImage/AppDir/.DirIcon: -------------------------------------------------------------------------------- 1 | swaglyrics_pfp.png -------------------------------------------------------------------------------- /Images/guidark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/Images/guidark.png -------------------------------------------------------------------------------- /Images/guilight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/Images/guilight.png -------------------------------------------------------------------------------- /Images/guiswaglyrics.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/Images/guiswaglyrics.png -------------------------------------------------------------------------------- /inno_compile.ps1: -------------------------------------------------------------------------------- 1 | & "$env:userprofile\.nuget\packages\tools.innosetup\6.0.5\tools\ISCC.exe" setup_script_win_x64.iss -------------------------------------------------------------------------------- /SwagLyricsGUI/swaglyrics_pfp.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/SwagLyricsGUI/swaglyrics_pfp.ico -------------------------------------------------------------------------------- /SwagLyricsGUI/Assets/swaglyrics_pfp.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/SwagLyricsGUI/Assets/swaglyrics_pfp.ico -------------------------------------------------------------------------------- /SetupLinux/AppImage/AppDir/swaglyrics_pfp.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/SetupLinux/AppImage/AppDir/swaglyrics_pfp.png -------------------------------------------------------------------------------- /SwagLyricsGUI/Assets/Fonts/Roboto-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/SwagLyrics/SwagLyricsGUI/HEAD/SwagLyricsGUI/Assets/Fonts/Roboto-Regular.ttf -------------------------------------------------------------------------------- /SetupLinux/AppImage/AppDir/AppRun: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | HERE="$(dirname "$(readlink -f "${0}")")" 3 | export PATH="${HERE}"/usr/bin/:"${PATH}" 4 | EXEC=$(grep -e '^Exec=.*' "${HERE}"/*.desktop | head -n 1 | cut -d "=" -f 2 | cut -d " " -f 1) 5 | exec "${EXEC}" $@ 6 | -------------------------------------------------------------------------------- /SwagLyricsGUI/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /SwagLyricsGUI/ViewModels/ViewModelBase.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using ReactiveUI; 5 | 6 | namespace SwagLyricsGUI.ViewModels 7 | { 8 | public class ViewModelBase : ReactiveObject 9 | { 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Events/NewSongEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SwagLyricsGUI.Models 4 | { 5 | public class NewSongEventArgs : EventArgs 6 | { 7 | public string Song { get; set; } 8 | 9 | public NewSongEventArgs(string song) 10 | { 11 | Song = song; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SetupLinux/AppImage/AppDir/SwagLyricsGUI.desktop: -------------------------------------------------------------------------------- 1 | # Desktop Entry Specification: https://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html 2 | [Desktop Entry] 3 | Type=Application 4 | Name=SwagLyricsGUI 5 | Comment=Automatic lyrics fetcher for current spotify songs. 6 | Icon=swaglyrics_pfp 7 | Exec=SwagLyricsGUI 8 | Categories=Audio; 9 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Events/LyricsLoadedEventArgs.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace SwagLyricsGUI.Models 4 | { 5 | public class LyricsLoadedEventArgs : EventArgs 6 | { 7 | public string Lyrics { get; set; } 8 | 9 | public LyricsLoadedEventArgs(string lyrics) 10 | { 11 | Lyrics = lyrics; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/MathEx.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace SwagLyricsGUI.Models 6 | { 7 | public static class MathEx 8 | { 9 | public static double Lerp(double start, double end, double t) 10 | { 11 | return (1 - t) * start + t * end; 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /SwagLyricsGUI/nuget.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Bridge/swaglyrics_installer.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import subprocess 3 | import pkg_resources 4 | 5 | required = {'swaglyrics'} 6 | installed = {pkg.key for pkg in pkg_resources.working_set} 7 | missing = required - installed 8 | 9 | print("Launching...") 10 | 11 | if missing: 12 | python = sys.executable 13 | print("Installing swaglyrics...") 14 | subprocess.check_call([python, '-m', 'pip', 'install', *missing]) 15 | 16 | print("Press any key to continue.") -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/Fact.cs: -------------------------------------------------------------------------------- 1 | using System.Text.Json.Serialization; 2 | 3 | namespace SwagLyricsGUI.Models 4 | { 5 | public class Fact 6 | { 7 | [JsonPropertyName("text")] 8 | public string Text { get; set; } 9 | 10 | public Fact(string text) 11 | { 12 | Text = text; 13 | } 14 | 15 | public Fact() 16 | { 17 | 18 | } 19 | 20 | public override string ToString() => Text.ToString(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /SwagLyricsGUITests/ModelsTests/MathExTests.cs: -------------------------------------------------------------------------------- 1 | using SwagLyricsGUI.Models; 2 | using System; 3 | using Xunit; 4 | 5 | namespace SwagLyricsGUITests.Models 6 | { 7 | public class MathExTests 8 | { 9 | [Theory] 10 | [InlineData(0,1)] 11 | [InlineData(1,2)] 12 | [InlineData(100,300)] 13 | public void TestThatLerpReturnsMidpoint(double start, double end) 14 | { 15 | double result = MathEx.Lerp(start, end, 0.5); 16 | double expected = (start + end) / 2; 17 | Assert.Equal(expected, result); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /SwagLyricsGUI/App.xaml: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /SwagLyricsGUI/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls.ApplicationLifetimes; 3 | using Avalonia.Markup.Xaml; 4 | using SwagLyricsGUI.ViewModels; 5 | using SwagLyricsGUI.Views; 6 | 7 | namespace SwagLyricsGUI 8 | { 9 | public class App : Application 10 | { 11 | public override void Initialize() 12 | { 13 | AvaloniaXamlLoader.Load(this); 14 | } 15 | 16 | public override void OnFrameworkInitializationCompleted() 17 | { 18 | if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) 19 | { 20 | desktop.MainWindow = new MainWindow 21 | { 22 | DataContext = new MainWindowViewModel(), 23 | }; 24 | } 25 | 26 | base.OnFrameworkInitializationCompleted(); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /SwagLyricsGUI/ViewLocator.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avalonia.Controls; 3 | using Avalonia.Controls.Templates; 4 | using SwagLyricsGUI.ViewModels; 5 | 6 | namespace SwagLyricsGUI 7 | { 8 | public class ViewLocator : IDataTemplate 9 | { 10 | public bool SupportsRecycling => false; 11 | 12 | public IControl Build(object data) 13 | { 14 | var name = data.GetType().FullName.Replace("ViewModel", "View"); 15 | var type = Type.GetType(name); 16 | 17 | if (type != null) 18 | { 19 | return (Control)Activator.CreateInstance(type); 20 | } 21 | else 22 | { 23 | return new TextBlock { Text = "Not Found: " + name }; 24 | } 25 | } 26 | 27 | public bool Match(object data) 28 | { 29 | return data is ViewModelBase; 30 | } 31 | } 32 | } -------------------------------------------------------------------------------- /SwagLyricsGUI/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Avalonia; 3 | using Avalonia.Controls.ApplicationLifetimes; 4 | using Avalonia.Logging.Serilog; 5 | using Avalonia.ReactiveUI; 6 | 7 | namespace SwagLyricsGUI 8 | { 9 | class Program 10 | { 11 | // Initialization code. Don't use any Avalonia, third-party APIs or any 12 | // SynchronizationContext-reliant code before AppMain is called: things aren't initialized 13 | // yet and stuff might break. 14 | public static void Main(string[] args) => BuildAvaloniaApp() 15 | .StartWithClassicDesktopLifetime(args); 16 | 17 | // Avalonia configuration, don't remove; also used by visual designer. 18 | public static AppBuilder BuildAvaloniaApp() 19 | => AppBuilder.Configure() 20 | .UsePlatformDetect() 21 | .LogToDebug() 22 | .UseReactiveUI(); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /SwagLyricsGUITests/SwagLyricsGUITests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | netcoreapp3.1 5 | 6 | false 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | all 15 | runtime; build; native; contentfiles; analyzers; buildtransitive 16 | 17 | 18 | all 19 | runtime; build; native; contentfiles; analyzers; buildtransitive 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/Command.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Windows.Input; 5 | 6 | namespace SwagLyricsGUI.Models 7 | { 8 | public class Command : ICommand 9 | { 10 | private Action? _execute; 11 | private Predicate? _canExecute; 12 | 13 | public event EventHandler CanExecuteChanged; 14 | 15 | #pragma warning disable CS8618 16 | public Command(Action? execute = null, Predicate? canExecute = null) 17 | #pragma warning restore CS8618 18 | { 19 | _execute = execute; 20 | _canExecute = canExecute; 21 | } 22 | 23 | public virtual void NotifyCanExecuteChanged() 24 | { 25 | CanExecuteChanged?.Invoke(this, EventArgs.Empty); 26 | } 27 | 28 | public bool CanExecute(object parameter) 29 | { 30 | return _canExecute?.Invoke(parameter) ?? true; 31 | } 32 | 33 | public void Execute(object parameter) 34 | { 35 | _execute?.Invoke(parameter); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/RandomFactsFetcher.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Net; 5 | using System.Text; 6 | using System.Text.Json; 7 | using System.Threading.Tasks; 8 | 9 | namespace SwagLyricsGUI.Models 10 | { 11 | public static class RandomFactsFetcher 12 | { 13 | public const string FactsUrl = @"https://uselessfacts.jsph.pl/random.json?language=en"; 14 | public static Fact GetRandomFact() 15 | { 16 | WebRequest request = WebRequest.Create(FactsUrl); 17 | var response = request.GetResponse(); 18 | Fact result; 19 | 20 | using (Stream dataStream = response.GetResponseStream()) 21 | { 22 | // Open the stream using a StreamReader for easy access. 23 | StreamReader reader = new StreamReader(dataStream); 24 | // Read the content. 25 | result = JsonSerializer.Deserialize(reader.ReadToEnd()); 26 | } 27 | 28 | // Close the response. 29 | response.Close(); 30 | return result; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2020 The SwagLyrics Project 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Bridge/swaglyrics_api_bridge.py: -------------------------------------------------------------------------------- 1 | import time 2 | import sys 3 | import base64 4 | import os 5 | import tempfile 6 | 7 | from swaglyrics import cli 8 | from SwSpotify import spotify, SpotifyNotRunning 9 | 10 | paused = False 11 | 12 | def print_encoded(data): 13 | print(base64.b64encode(data.encode('utf-8')), flush=True) 14 | 15 | def print_lyrics(song, artist): 16 | print_encoded(f"{song} by {artist}:") 17 | lyrics = cli.get_lyrics(song, artist) 18 | if lyrics is None: 19 | lyrics = "Couldn't get lyrics" 20 | print_encoded(lyrics) 21 | sys.stdout.flush() 22 | 23 | last_song = "" 24 | last_artist = "" 25 | new_song = "" 26 | new_artist = "" 27 | 28 | while True: 29 | try: 30 | new_song, new_artist = spotify.current() 31 | except SpotifyNotRunning: 32 | print("SpotifyNotRunning", file=sys.stderr, flush=True) 33 | paused = True 34 | sys.stderr.flush() 35 | else: 36 | if new_song != last_song or new_artist != last_artist: 37 | print_lyrics(new_song, new_artist) 38 | last_song = new_song 39 | last_artist = new_artist 40 | paused = False 41 | elif paused: 42 | print_encoded("Resumed") 43 | if not os.path.exists(os.path.join(tempfile.gettempdir(), "SwagLyricsGUI", "swaglyricsGUIOn.txt")): # kills the process if GUI is off and not closed it properly 44 | sys.exit() 45 | time.sleep(2) -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/ThemeManager.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Markup.Xaml.Styling; 3 | using Avalonia.Styling; 4 | using SwagLyricsGUI.ViewModels; 5 | using SwagLyricsGUI.Views; 6 | using System; 7 | using System.Collections.Generic; 8 | using System.Configuration; 9 | using System.IO; 10 | using System.Net; 11 | 12 | 13 | namespace SwagLyricsGUI.Models 14 | { 15 | public class ThemeManager 16 | { 17 | public List Themes { get; set; } 18 | 19 | public void LoadThemes() 20 | { 21 | var dark = new StyleInclude(new Uri("resm:Styles?assembly=SwagLyricsGUI")) 22 | { 23 | Source = new Uri("resm:Avalonia.Themes.Default.Accents.BaseDark.xaml?assembly=Avalonia.Themes.Default") 24 | }; 25 | var light = new StyleInclude(new Uri("resm:Styles?assembly=SwagLyricsGUI")) 26 | { 27 | Source = new Uri("resm:Avalonia.Themes.Default.Accents.BaseLight.xaml?assembly=Avalonia.Themes.Default") 28 | }; 29 | 30 | Themes = new List() 31 | { 32 | light.Loaded, 33 | dark.Loaded, 34 | Application.Current.Styles[0] 35 | }; 36 | } 37 | 38 | public void ChangeTheme(int index) 39 | { 40 | if (index > Themes.Count - 1 || index < 0) return; 41 | if (MainWindow.Current.Styles.Count == 0) 42 | { 43 | MainWindow.Current.Styles.Add(Themes[index]); 44 | } 45 | else 46 | { 47 | MainWindow.Current.Styles[0] = Themes[index]; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/BridgeManager.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.IO; 4 | using System.Linq; 5 | using System.Reflection; 6 | using System.Text; 7 | 8 | namespace SwagLyricsGUI.Models 9 | { 10 | public class BridgeManager 11 | { 12 | public static string BridgeFilesPath { get; private set; } = ""; 13 | public Assembly ExecutingAssembly { get; set; } 14 | public string TempFolderPath { get; set; } 15 | public const string TempDirectoryName = "SwagLyricsGUI"; 16 | public BridgeManager() 17 | { 18 | ExecutingAssembly = Assembly.GetExecutingAssembly(); 19 | TempFolderPath = Path.GetTempPath(); 20 | } 21 | 22 | public void InitTempDirectory() 23 | { 24 | Directory.CreateDirectory(Path.Join(TempFolderPath, TempDirectoryName)); 25 | } 26 | 27 | public void LoadEmbeddedScriptsToTempFolder() 28 | { 29 | BridgeFilesPath = Path.Combine(TempFolderPath, TempDirectoryName); 30 | LoadEmbeddedScript("swaglyrics_api_bridge.py"); 31 | LoadEmbeddedScript("swaglyrics_installer.py"); 32 | } 33 | 34 | private void LoadEmbeddedScript(string scriptName) 35 | { 36 | if (File.Exists(Path.Join(BridgeFilesPath, scriptName))) return; 37 | 38 | string resourceName = ExecutingAssembly.GetManifestResourceNames() 39 | .Single(str => str.EndsWith(scriptName)); 40 | 41 | using (Stream stream = ExecutingAssembly.GetManifestResourceStream(resourceName)) 42 | using (StreamReader reader = new StreamReader(stream)) 43 | { 44 | string result = reader.ReadToEnd(); 45 | File.WriteAllText(Path.Join(BridgeFilesPath, scriptName), result); 46 | } 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [![Discord Server](https://badgen.net/badge/discord/join%20chat/7289DA?icon=discord)](https://discord.gg/DSUZGK4) 2 | 3 | # SwagLyricsGUI 4 | 5 | A cross-platform, real-time lyrics fetching application. 6 | 7 | ![screenshot](https://github.com/SwagLyrics/SwagLyricsGUI/blob/master/Images/guidark.png) 8 | 9 | # About 10 | 11 | SwagLyricsGUI is a GUI wrapper for super fast [SwagLyrics-For-Spotify](https://github.com/SwagLyrics/SwagLyrics-For-Spotify) library. It contains 3 themes and auto scroll. 12 | 13 | # Installing 14 | 15 | Download appropriate file for your system [here](https://github.com/SwagLyrics/SwagLyricsGUI/releases/latest). 16 | 17 | Make sure you have installed `Python 3.6+`, if not download it [here](https://www.python.org/downloads/) 18 | 19 | ## Windows 20 | 21 | Follow setup and simply open SwagLyricsGUI application 22 | 23 | ## Linux 24 | 25 | Currently pre-built binaries are wrapped in `AppImage`. 26 | 27 | Running file should work out of the box, but sometimes you might get `Permissions denied`, 28 | or `Could not display SwagLyricsGUI.AppImage`, in that case use `chmod +x SwagLyricsGUI-x86_64.AppImage`. 29 | 30 | # Build from source 31 | 32 | SwagLyricsGUI is a multilingual application. It means that it uses multiple programming languages in it's core, `C#` for controlling UI and `Python` for lyrics fetching backend. 33 | 34 | Application is written in AvaloniaUI framework. 35 | 36 | ## Prerequisites 37 | 38 | - `.NET Core 3.1 SDK` 39 | - Minimum `Python 3.6` 40 | - Optionally download [SwagLyrics-For-Spotify](https://github.com/SwagLyrics/SwagLyrics-For-Spotify) library, but application will do that for you in first run. 41 | 42 | ## Building 43 | 44 | Open .sln file in Visual Studio and hit Start or use CLI .NET Core `dotnet build` in root directory and `dotnet run` for selected project (Tests or GUI). 45 | 46 | ### Example for running GUI using dotnet 47 | 48 | `dotnet build` in root git directory 49 | 50 | `cd SwagLyricsGUI` 51 | 52 | `dotnet run` 53 | 54 | 55 | # Contributing 56 | 57 | Feel free to contribute! We don't have any guide for this yet, but with application growth it might show up :) 58 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Views/MainWindow.xaml.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using Avalonia.Controls; 3 | using Avalonia.Markup.Xaml; 4 | using Serilog.Parsing; 5 | using SwagLyricsGUI.ViewModels; 6 | using System.Configuration; 7 | 8 | namespace SwagLyricsGUI.Views 9 | { 10 | public class MainWindow : Window 11 | { 12 | public static MainWindow Current { get; set; } 13 | private ScrollViewer sv; 14 | public double ScrollViewerVieportHeight => sv.Viewport.Height; 15 | public MainWindow() 16 | { 17 | InitializeComponent(); 18 | this.Closing += MainWindow_Closing; 19 | this.Opened += MainWindow_Opened; 20 | Current = this; 21 | #if DEBUG 22 | this.AttachDevTools(); 23 | #endif 24 | sv = this.Find("scrollViewer"); 25 | } 26 | 27 | private void MainWindow_Opened(object sender, System.EventArgs e) 28 | { 29 | MaxHeight = Screens.Primary.Bounds.Height; 30 | Height = Screens.Primary.Bounds.Height - 100; 31 | SetPosition(); 32 | } 33 | 34 | private void SetPosition() 35 | { 36 | string x = MainWindowViewModel.Current.Config.AppSettings.Settings["PosX"].Value; 37 | string y = MainWindowViewModel.Current.Config.AppSettings.Settings["PosY"].Value; 38 | if(x != "defualt" && y != "default") 39 | { 40 | Position = new PixelPoint(int.Parse(x), int.Parse(y)); 41 | } 42 | else 43 | { 44 | WindowStartupLocation = WindowStartupLocation.CenterScreen; 45 | Position = new PixelPoint(Position.X, 0); 46 | } 47 | } 48 | 49 | private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e) 50 | { 51 | var config = MainWindowViewModel.Current.Config; 52 | config.AppSettings.Settings["PosX"].Value = Position.X.ToString(); 53 | MainWindowViewModel.Current.Config.AppSettings.Settings["PosY"].Value = Position.Y.ToString(); 54 | config.Save(); 55 | ConfigurationManager.RefreshSection("appSettings"); 56 | } 57 | 58 | private void InitializeComponent() 59 | { 60 | AvaloniaXamlLoader.Load(this); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /SwagLyricsGUI/SwagLyricsGUI.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | WinExe 4 | netcoreapp3.1 5 | win-x64;win-x86;osx-x64;linux-x64 6 | swaglyrics_pfp.ico 7 | 0.4 8 | Krzysztof Krysiński 9 | SwagLyrics 10 | LICENSE.md 11 | https://github.com/SwagLyrics/SwagLyricsGUI 12 | A cross-platform, real-time lyrics fetching application. 13 | © The SwagLyrics Project 2020 14 | swaglyrics_pfp.ico 15 | 16 | 17 | 18 | %(Filename) 19 | 20 | 21 | Designer 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | True 31 | 32 | 33 | 34 | True 35 | 36 | 37 | 38 | 39 | 40 | Never 41 | 42 | 43 | Never 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | Always 56 | 57 | 58 | 59 | -------------------------------------------------------------------------------- /setup_script_win_x64.iss: -------------------------------------------------------------------------------- 1 | ; Script generated by the Inno Setup Script Wizard. 2 | ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! 3 | 4 | #define MyAppName "SwagLyricsGUI" 5 | #define VerFile FileOpen("version.txt") 6 | #define MyAppVersion FileRead(VerFile) 7 | #expr FileClose(VerFile) 8 | #undef VerFile 9 | #define MyAppPublisher "The SwagLyrics Project" 10 | #define MyAppURL "http://swaglyrics.dev/" 11 | #define MyAppExeName "SwagLyricsGUI.exe" 12 | 13 | [Setup] 14 | ; NOTE: The value of AppId uniquely identifies this application. Do not use the same AppId value in installers for other applications. 15 | ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) 16 | AppId={{BAFCA32F-E9E7-435C-B023-55E322D81CEA} 17 | AppName={#MyAppName} 18 | AppVersion={#MyAppVersion} 19 | ;AppVerName={#MyAppName} {#MyAppVersion} 20 | AppPublisher={#MyAppPublisher} 21 | AppPublisherURL={#MyAppURL} 22 | AppSupportURL={#MyAppURL} 23 | AppUpdatesURL={#MyAppURL} 24 | DefaultDirName={autopf}\{#MyAppName} 25 | DisableProgramGroupPage=yes 26 | ; The [Icons] "quicklaunchicon" entry uses {userappdata} but its [Tasks] entry has a proper IsAdminInstallMode Check. 27 | UsedUserAreasWarning=no 28 | LicenseFile=LICENSE.md 29 | ; Remove the following line to run in administrative install mode (install for all users.) 30 | PrivilegesRequired=lowest 31 | PrivilegesRequiredOverridesAllowed=dialog 32 | OutputDir=Installer\win-x64\ 33 | OutputBaseFilename=SwagLyricsGUI-setup-x64 34 | SetupIconFile=SwagLyricsGUI\swaglyrics_pfp.ico 35 | Compression=lzma 36 | SolidCompression=yes 37 | WizardStyle=modern 38 | 39 | [Languages] 40 | Name: "english"; MessagesFile: "compiler:Default.isl" 41 | 42 | [Tasks] 43 | Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked 44 | Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 6.1; Check: not IsAdminInstallMode 45 | 46 | [Files] 47 | Source: "Builds\win-x64\SwagLyricsGUI.exe"; DestDir: "{app}"; Flags: ignoreversion 48 | Source: "Builds\win-x64\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs 49 | ; NOTE: Don't use "Flags: ignoreversion" on any shared system files 50 | 51 | [Icons] 52 | Name: "{autoprograms}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}" 53 | Name: "{autodesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon 54 | Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: quicklaunchicon 55 | 56 | [Run] 57 | Filename: "{app}\{#MyAppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent 58 | 59 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Views/MainWindow.xaml: -------------------------------------------------------------------------------- 1 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | Light 34 | Dark 35 | SwagLyrics 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/PrerequisitesChecker.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.IO; 5 | using System.Text; 6 | 7 | namespace SwagLyricsGUI.Models 8 | { 9 | public class PrerequisitesChecker 10 | { 11 | public static string PythonCmdPostFix { get; set; } = ""; 12 | public bool SupportedPythonVersionInstalled() 13 | { 14 | return CheckPythonInstalled(""); 15 | } 16 | 17 | public void InstallSwagLyricsIfMissing() 18 | { 19 | string path = Path.Join(BridgeManager.BridgeFilesPath, "swaglyrics_installer.py"); 20 | ProcessStartInfo start = new ProcessStartInfo 21 | { 22 | FileName = $"python{PythonCmdPostFix}", 23 | Arguments = path, 24 | UseShellExecute = false, 25 | }; 26 | Process process = new Process() { StartInfo = start }; 27 | process.Start(); 28 | process.WaitForExit(); 29 | process.Kill(); 30 | } 31 | 32 | private bool CheckPythonInstalled(string postfix) 33 | { 34 | bool result = false; 35 | ProcessStartInfo start = new ProcessStartInfo 36 | { 37 | FileName = $"python{postfix}", 38 | Arguments = "--version", 39 | UseShellExecute = false, 40 | RedirectStandardOutput = true, 41 | RedirectStandardError = true, 42 | CreateNoWindow = true 43 | }; 44 | 45 | using (Process process = Process.Start(start)) 46 | { 47 | using (StreamReader reader = process.StandardError) 48 | { 49 | var res = reader.ReadToEnd(); 50 | if (res != "" && postfix != "") 51 | { 52 | return false; 53 | } 54 | } 55 | using (StreamReader reader = process.StandardOutput) 56 | { 57 | var res = reader.ReadToEnd(); 58 | if (res == "") 59 | { 60 | result = false; 61 | } 62 | else 63 | { 64 | var version = res.Split(" ")[1].Split('.'); 65 | int ver0 = int.Parse(version[0]); 66 | result = (ver0 == 3 && int.Parse(version[1]) >= 6) || ver0 > 3; 67 | } 68 | } 69 | 70 | if(!result && postfix == "") 71 | { 72 | result = CheckPythonInstalled("3"); 73 | if (result) 74 | PythonCmdPostFix = "3"; 75 | } 76 | } 77 | return result; 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /.github/workflows/linux-setup-files.yml: -------------------------------------------------------------------------------- 1 | name: Build Release Asset - Linux x64 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | tags: 7 | - 'v*' 8 | 9 | jobs: 10 | build: 11 | 12 | runs-on: ubuntu-latest 13 | 14 | steps: 15 | - uses: actions/checkout@v2 16 | - uses: dorny/paths-filter@v2.2.0 17 | id: filter 18 | with: 19 | filters: | 20 | version: 21 | - 'version.txt' 22 | 23 | - name: Cancel workflow 24 | if: steps.filter.outputs.version == 'false' 25 | uses: andymckay/cancel-action@0.2 26 | 27 | - name: Setup .NET Core 28 | uses: actions/setup-dotnet@v1 29 | with: 30 | dotnet-version: 3.1.101 31 | - name: Install dependencies 32 | run: dotnet restore 33 | - name: Build 34 | run: dotnet build --configuration Release --no-restore 35 | - name: Test 36 | run: dotnet test --no-restore --verbosity normal 37 | - name: Publish Release 38 | run: dotnet publish SwagLyricsGUI --self-contained true -p:PublishTrimmed=true -p:PublishSingleFile=true -o Builds/linux-x64/ -r linux-x64 -c Release 39 | - name: Build executables 40 | run: ./build_linux_assets.sh 41 | - name: Set version env 42 | run: echo ::set-env name=RELEASE_VER::$(cat version.txt) 43 | - name: Check if release exist 44 | run: echo ::set-env name=LATEST_TAG::$(curl https://api.github.com/repos/SwagLyrics/SwagLyricsGUI/releases/latest | jq '.tag_name' | tr -d \") 45 | - name: Create Release 46 | id: create_release 47 | uses: actions/create-release@v1 48 | if: ${{ env.RELEASE_VER != env.LATEST_TAG }} 49 | env: 50 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 | with: 52 | tag_name: ${{ env.RELEASE_VER }} 53 | release_name: Release ${{ env.RELEASE_VER }} 54 | draft: false 55 | prerelease: false 56 | - name: Set Assets url 57 | if: ${{ env.RELEASE_VER != env.LATEST_TAG }} 58 | run: echo "::set-env name=UPLOAD_URL::${{ steps.create_release.outputs.upload_url }}" 59 | - name: Get the upload URL for a release 60 | if: ${{ env.RELEASE_VER == env.LATEST_TAG }} 61 | run: echo ::set-env name=UPLOAD_URL::$(curl https://api.github.com/repos/SwagLyrics/SwagLyricsGUI/releases/latest | jq '.upload_url' | tr -d \") 62 | - name: Upload a Release Asset 63 | id: upload-release-asset 64 | uses: actions/upload-release-asset@v1.0.2 65 | env: 66 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 67 | with: 68 | # The URL for uploading assets to the release 69 | upload_url: ${{ env.UPLOAD_URL }} 70 | # The path to the asset you want to upload 71 | asset_path: OutputFiles/SwagLyricsGUI-x86_64.AppImage 72 | # The name of the asset you want to upload 73 | asset_name: SwagLyricsGUI-x86_64.AppImage 74 | # The content-type of the asset you want to upload. See the supported Media Types here: https://www.iana.org/assignments/media-types/media-types.xhtml for more information 75 | asset_content_type: application 76 | 77 | -------------------------------------------------------------------------------- /.github/workflows/win-installer-action.yml: -------------------------------------------------------------------------------- 1 | name: Build Release Asset - Windows x64 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | tags: 7 | - 'v*' 8 | 9 | jobs: 10 | build: 11 | runs-on: windows-latest 12 | 13 | steps: 14 | - uses: actions/checkout@v2 15 | - uses: dorny/paths-filter@v2.2.0 16 | id: filter 17 | with: 18 | filters: | 19 | version: 20 | - 'version.txt' 21 | 22 | - name: Cancel workflow 23 | if: steps.filter.outputs.version == 'false' 24 | uses: andymckay/cancel-action@0.2 25 | - name: Setup .NET Core 26 | uses: actions/setup-dotnet@v1 27 | with: 28 | dotnet-version: 3.1.101 29 | - name: Install dependencies 30 | run: dotnet restore 31 | - name: Build 32 | run: dotnet build --configuration Release --no-restore 33 | - name: Test 34 | run: dotnet test --no-restore --verbosity normal 35 | - name: Publish x64 release 36 | run: dotnet publish SwagLyricsGUI --self-contained true -p:PublishTrimmed=true -o Builds\win-x64\ -r win-x64 -c Release 37 | - name: Compile setup script 38 | shell: powershell 39 | run: .\inno_compile.ps1 40 | - name: Set version env 41 | run: echo ::set-env name=RELEASE_VER::$(cat version.txt) 42 | - name: Check if release exist 43 | shell: powershell 44 | run: echo ::set-env name=LATEST_TAG::$($WebResponse = curl https://api.github.com/repos/SwagLyrics/SwagLyricsGUI/releases/latest; $WebResponse.Content | ConvertFrom-Json | Select tag_name | foreach {$_.tag_name}) 45 | - name: Create Release 46 | id: create_release 47 | uses: actions/create-release@v1 48 | if: ${{ env.RELEASE_VER != env.LATEST_TAG }} 49 | env: 50 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 51 | with: 52 | tag_name: ${{ env.RELEASE_VER }} 53 | release_name: Release ${{ env.RELEASE_VER }} 54 | draft: false 55 | prerelease: false 56 | - name: Set Assets url 57 | if: ${{ env.RELEASE_VER != env.LATEST_TAG }} 58 | run: echo "::set-env name=UPLOAD_URL::${{ steps.create_release.outputs.upload_url }}" 59 | - name: Get release URL 60 | id: release_url 61 | shell: powershell 62 | if: ${{ env.RELEASE_VER == env.LATEST_TAG }} 63 | run: echo "::set-env name=UPLOAD_URL::$($WebResponse = curl https://api.github.com/repos/SwagLyrics/SwagLyricsGUI/releases/latest; $WebResponse.Content | ConvertFrom-Json | Select upload_url | foreach {$_.upload_url})" 64 | - name: Upload a Release Asset 65 | id: upload-release-asset 66 | uses: actions/upload-release-asset@v1.0.2 67 | env: 68 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 69 | with: 70 | # The URL for uploading assets to the release 71 | upload_url: ${{ env.UPLOAD_URL }} 72 | # The path to the asset you want to upload 73 | asset_path: Installer\win-x64\SwagLyricsGUI-setup-x64.exe 74 | # The name of the asset you want to upload 75 | asset_name: SwagLyricsGUI-setup-x64.exe 76 | # The content-type of the asset you want to upload. See the supported Media Types here: https://www.iana.org/assignments/media-types/media-types.xhtml for more information 77 | asset_content_type: application 78 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Models/SwagLyricsBridge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.IO; 4 | using System.Text; 5 | 6 | namespace SwagLyricsGUI.Models 7 | { 8 | public class SwagLyricsBridge 9 | { 10 | public event EventHandler OnNewSong; 11 | public event EventHandler OnLyricsLoaded; 12 | public event EventHandler OnError; 13 | public event EventHandler OnResumed; 14 | public event EventHandler OnAdvertisement; 15 | 16 | public string BridgeFileOnPath => Path.Combine(BridgeManager.BridgeFilesPath, "swaglyricsGUIOn.txt"); 17 | 18 | public bool IsAdvertisement { get; private set; } = false; 19 | public Process LyricsProcess { get; set; } 20 | 21 | public void StartLyricsBridge() 22 | { 23 | File.Create(BridgeFileOnPath); 24 | string path = Path.Join(BridgeManager.BridgeFilesPath, "swaglyrics_api_bridge.py"); 25 | LyricsProcess = new Process 26 | { 27 | StartInfo = new ProcessStartInfo 28 | { 29 | FileName = $"python{PrerequisitesChecker.PythonCmdPostFix}", 30 | Arguments = path, 31 | UseShellExecute = false, 32 | RedirectStandardOutput = true, 33 | RedirectStandardError = true, 34 | CreateNoWindow = true, 35 | }, 36 | EnableRaisingEvents = true 37 | }; 38 | LyricsProcess.OutputDataReceived += Process_OutputDataReceived; 39 | LyricsProcess.ErrorDataReceived += Process_ErrorDataReceived; 40 | 41 | LyricsProcess.Start(); 42 | LyricsProcess.BeginOutputReadLine(); 43 | LyricsProcess.BeginErrorReadLine(); 44 | Console.Read(); 45 | } 46 | 47 | private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e) 48 | { 49 | if (e.Data == null) return; 50 | OnError?.Invoke(this, new LyricsLoadedEventArgs(e.Data)); 51 | } 52 | 53 | private void Process_OutputDataReceived(object sender, DataReceivedEventArgs e) 54 | { 55 | if (e.Data == null) return; 56 | string data = DecodeFrom64(e.Data); 57 | if (data.EndsWith(':') && data.Contains("by")) 58 | { 59 | string song = data.Split(":")[0]; 60 | string[] songArtist = song.Split("by"); 61 | 62 | if (songArtist[0].Trim() == "Advertisement" && (songArtist[1].Trim() == "" || songArtist[1].Trim() == ".")) 63 | { 64 | IsAdvertisement = true; 65 | OnAdvertisement?.Invoke(this, EventArgs.Empty); 66 | } 67 | else 68 | { 69 | IsAdvertisement = false; 70 | OnNewSong?.Invoke(this, new NewSongEventArgs(song)); 71 | } 72 | } 73 | else if(data == "Resumed") 74 | { 75 | OnResumed?.Invoke(this, EventArgs.Empty); 76 | } 77 | else if(!IsAdvertisement) 78 | { 79 | OnLyricsLoaded?.Invoke(this, new LyricsLoadedEventArgs($"\n{data}\n")); // \n are "Margins" 80 | } 81 | 82 | } 83 | 84 | public static string DecodeFrom64(string input) 85 | { 86 | input = input.Replace("b'", ""); 87 | input = input.Replace("'", ""); 88 | byte[] encodedDataAsBytes = 89 | System.Convert.FromBase64String(input); 90 | string returnValue = 91 | Encoding.UTF8.GetString(encodedDataAsBytes); 92 | return returnValue; 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /SwagLyricsGUI/Assets/Styles/SwagLyricsTheme.xaml: -------------------------------------------------------------------------------- 1 | 59 | -------------------------------------------------------------------------------- /SwagLyricsGUI.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30204.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwagLyricsGUI", "SwagLyricsGUI\SwagLyricsGUI.csproj", "{28A60E1C-5F91-4EF8-BA45-F955263F747F}" 7 | EndProject 8 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SwagLyricsGUITests", "SwagLyricsGUITests\SwagLyricsGUITests.csproj", "{66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|ARM = Debug|ARM 14 | Debug|ARM64 = Debug|ARM64 15 | Debug|x64 = Debug|x64 16 | Debug|x86 = Debug|x86 17 | Release|Any CPU = Release|Any CPU 18 | Release|ARM = Release|ARM 19 | Release|ARM64 = Release|ARM64 20 | Release|x64 = Release|x64 21 | Release|x86 = Release|x86 22 | EndGlobalSection 23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 24 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 25 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|Any CPU.Build.0 = Debug|Any CPU 26 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|ARM.ActiveCfg = Debug|Any CPU 27 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|ARM.Build.0 = Debug|Any CPU 28 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|ARM64.ActiveCfg = Debug|Any CPU 29 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|ARM64.Build.0 = Debug|Any CPU 30 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|x64.ActiveCfg = Debug|Any CPU 31 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|x64.Build.0 = Debug|Any CPU 32 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|x86.ActiveCfg = Debug|Any CPU 33 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Debug|x86.Build.0 = Debug|Any CPU 34 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|Any CPU.ActiveCfg = Release|Any CPU 35 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|Any CPU.Build.0 = Release|Any CPU 36 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|ARM.ActiveCfg = Release|Any CPU 37 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|ARM.Build.0 = Release|Any CPU 38 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|ARM64.ActiveCfg = Release|Any CPU 39 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|ARM64.Build.0 = Release|Any CPU 40 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|x64.ActiveCfg = Release|Any CPU 41 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|x64.Build.0 = Release|Any CPU 42 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|x86.ActiveCfg = Release|Any CPU 43 | {28A60E1C-5F91-4EF8-BA45-F955263F747F}.Release|x86.Build.0 = Release|Any CPU 44 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 45 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|Any CPU.Build.0 = Debug|Any CPU 46 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|ARM.ActiveCfg = Debug|Any CPU 47 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|ARM.Build.0 = Debug|Any CPU 48 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|ARM64.ActiveCfg = Debug|Any CPU 49 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|ARM64.Build.0 = Debug|Any CPU 50 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|x64.ActiveCfg = Debug|Any CPU 51 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|x64.Build.0 = Debug|Any CPU 52 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|x86.ActiveCfg = Debug|Any CPU 53 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Debug|x86.Build.0 = Debug|Any CPU 54 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|Any CPU.ActiveCfg = Release|Any CPU 55 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|Any CPU.Build.0 = Release|Any CPU 56 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|ARM.ActiveCfg = Release|Any CPU 57 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|ARM.Build.0 = Release|Any CPU 58 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|ARM64.ActiveCfg = Release|Any CPU 59 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|ARM64.Build.0 = Release|Any CPU 60 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|x64.ActiveCfg = Release|Any CPU 61 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|x64.Build.0 = Release|Any CPU 62 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|x86.ActiveCfg = Release|Any CPU 63 | {66E8ED9B-6C7E-4EB2-9C06-3D4BA27B4C57}.Release|x86.Build.0 = Release|Any CPU 64 | EndGlobalSection 65 | GlobalSection(SolutionProperties) = preSolution 66 | HideSolutionNode = FALSE 67 | EndGlobalSection 68 | GlobalSection(ExtensibilityGlobals) = postSolution 69 | SolutionGuid = {04DAE56D-0777-4D5F-AF50-5BE217BBA367} 70 | EndGlobalSection 71 | EndGlobal 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Aa][Rr][Mm]/ 27 | [Aa][Rr][Mm]64/ 28 | bld/ 29 | [Bb]in/ 30 | [Oo]bj/ 31 | [Ll]og/ 32 | 33 | # Visual Studio 2015/2017 cache/options directory 34 | .vs/ 35 | # Uncomment if you have tasks that create the project's static files in wwwroot 36 | #wwwroot/ 37 | 38 | # Visual Studio 2017 auto generated files 39 | Generated\ Files/ 40 | 41 | # MSTest test Results 42 | [Tt]est[Rr]esult*/ 43 | [Bb]uild[Ll]og.* 44 | 45 | # NUnit 46 | *.VisualState.xml 47 | TestResult.xml 48 | nunit-*.xml 49 | 50 | # Build Results of an ATL Project 51 | [Dd]ebugPS/ 52 | [Rr]eleasePS/ 53 | dlldata.c 54 | 55 | # Benchmark Results 56 | BenchmarkDotNet.Artifacts/ 57 | 58 | # .NET Core 59 | project.lock.json 60 | project.fragment.lock.json 61 | artifacts/ 62 | 63 | # StyleCop 64 | StyleCopReport.xml 65 | 66 | # Files built by Visual Studio 67 | *_i.c 68 | *_p.c 69 | *_h.h 70 | *.ilk 71 | *.meta 72 | *.obj 73 | *.iobj 74 | *.pch 75 | *.pdb 76 | *.ipdb 77 | *.pgc 78 | *.pgd 79 | *.rsp 80 | *.sbr 81 | *.tlb 82 | *.tli 83 | *.tlh 84 | *.tmp 85 | *.tmp_proj 86 | *_wpftmp.csproj 87 | *.log 88 | *.vspscc 89 | *.vssscc 90 | .builds 91 | *.pidb 92 | *.svclog 93 | *.scc 94 | 95 | # Chutzpah Test files 96 | _Chutzpah* 97 | 98 | # Visual C++ cache files 99 | ipch/ 100 | *.aps 101 | *.ncb 102 | *.opendb 103 | *.opensdf 104 | *.sdf 105 | *.cachefile 106 | *.VC.db 107 | *.VC.VC.opendb 108 | 109 | # Visual Studio profiler 110 | *.psess 111 | *.vsp 112 | *.vspx 113 | *.sap 114 | 115 | # Visual Studio Trace Files 116 | *.e2e 117 | 118 | # TFS 2012 Local Workspace 119 | $tf/ 120 | 121 | # Guidance Automation Toolkit 122 | *.gpState 123 | 124 | # ReSharper is a .NET coding add-in 125 | _ReSharper*/ 126 | *.[Rr]e[Ss]harper 127 | *.DotSettings.user 128 | 129 | # JustCode is a .NET coding add-in 130 | .JustCode 131 | 132 | # TeamCity is a build add-in 133 | _TeamCity* 134 | 135 | # DotCover is a Code Coverage Tool 136 | *.dotCover 137 | 138 | # AxoCover is a Code Coverage Tool 139 | .axoCover/* 140 | !.axoCover/settings.json 141 | 142 | # Visual Studio code coverage results 143 | *.coverage 144 | *.coveragexml 145 | 146 | # NCrunch 147 | _NCrunch_* 148 | .*crunch*.local.xml 149 | nCrunchTemp_* 150 | 151 | # MightyMoose 152 | *.mm.* 153 | AutoTest.Net/ 154 | 155 | # Web workbench (sass) 156 | .sass-cache/ 157 | 158 | # Installshield output folder 159 | [Ee]xpress/ 160 | 161 | # DocProject is a documentation generator add-in 162 | DocProject/buildhelp/ 163 | DocProject/Help/*.HxT 164 | DocProject/Help/*.HxC 165 | DocProject/Help/*.hhc 166 | DocProject/Help/*.hhk 167 | DocProject/Help/*.hhp 168 | DocProject/Help/Html2 169 | DocProject/Help/html 170 | 171 | # Click-Once directory 172 | publish/ 173 | 174 | # Publish Web Output 175 | *.[Pp]ublish.xml 176 | *.azurePubxml 177 | # Note: Comment the next line if you want to checkin your web deploy settings, 178 | # but database connection strings (with potential passwords) will be unencrypted 179 | *.pubxml 180 | *.publishproj 181 | 182 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 183 | # checkin your Azure Web App publish settings, but sensitive information contained 184 | # in these scripts will be unencrypted 185 | PublishScripts/ 186 | 187 | # NuGet Packages 188 | *.nupkg 189 | # NuGet Symbol Packages 190 | *.snupkg 191 | # The packages folder can be ignored because of Package Restore 192 | **/[Pp]ackages/* 193 | # except build/, which is used as an MSBuild target. 194 | !**/[Pp]ackages/build/ 195 | # Uncomment if necessary however generally it will be regenerated when needed 196 | #!**/[Pp]ackages/repositories.config 197 | # NuGet v3's project.json files produces more ignorable files 198 | *.nuget.props 199 | *.nuget.targets 200 | 201 | # Microsoft Azure Build Output 202 | csx/ 203 | *.build.csdef 204 | 205 | # Microsoft Azure Emulator 206 | ecf/ 207 | rcf/ 208 | 209 | # Windows Store app package directories and files 210 | AppPackages/ 211 | BundleArtifacts/ 212 | Package.StoreAssociation.xml 213 | _pkginfo.txt 214 | *.appx 215 | *.appxbundle 216 | *.appxupload 217 | 218 | # Visual Studio cache files 219 | # files ending in .cache can be ignored 220 | *.[Cc]ache 221 | # but keep track of directories ending in .cache 222 | !?*.[Cc]ache/ 223 | 224 | # Others 225 | ClientBin/ 226 | ~$* 227 | *~ 228 | *.dbmdl 229 | *.dbproj.schemaview 230 | *.jfm 231 | *.pfx 232 | *.publishsettings 233 | orleans.codegen.cs 234 | 235 | # Including strong name files can present a security risk 236 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 237 | #*.snk 238 | 239 | # Since there are multiple workflows, uncomment next line to ignore bower_components 240 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 241 | #bower_components/ 242 | 243 | # RIA/Silverlight projects 244 | Generated_Code/ 245 | 246 | # Backup & report files from converting an old project file 247 | # to a newer Visual Studio version. Backup files are not needed, 248 | # because we have git ;-) 249 | _UpgradeReport_Files/ 250 | Backup*/ 251 | UpgradeLog*.XML 252 | UpgradeLog*.htm 253 | ServiceFabricBackup/ 254 | *.rptproj.bak 255 | 256 | # SQL Server files 257 | *.mdf 258 | *.ldf 259 | *.ndf 260 | 261 | # Business Intelligence projects 262 | *.rdl.data 263 | *.bim.layout 264 | *.bim_*.settings 265 | *.rptproj.rsuser 266 | *- [Bb]ackup.rdl 267 | *- [Bb]ackup ([0-9]).rdl 268 | *- [Bb]ackup ([0-9][0-9]).rdl 269 | 270 | # Microsoft Fakes 271 | FakesAssemblies/ 272 | 273 | # GhostDoc plugin setting file 274 | *.GhostDoc.xml 275 | 276 | # Node.js Tools for Visual Studio 277 | .ntvs_analysis.dat 278 | node_modules/ 279 | 280 | # Visual Studio 6 build log 281 | *.plg 282 | 283 | # Visual Studio 6 workspace options file 284 | *.opt 285 | 286 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 287 | *.vbw 288 | 289 | # Visual Studio LightSwitch build output 290 | **/*.HTMLClient/GeneratedArtifacts 291 | **/*.DesktopClient/GeneratedArtifacts 292 | **/*.DesktopClient/ModelManifest.xml 293 | **/*.Server/GeneratedArtifacts 294 | **/*.Server/ModelManifest.xml 295 | _Pvt_Extensions 296 | 297 | # Paket dependency manager 298 | .paket/paket.exe 299 | paket-files/ 300 | 301 | # FAKE - F# Make 302 | .fake/ 303 | 304 | # CodeRush personal settings 305 | .cr/personal 306 | 307 | # Python Tools for Visual Studio (PTVS) 308 | __pycache__/ 309 | *.pyc 310 | 311 | # Cake - Uncomment if you are using it 312 | # tools/** 313 | # !tools/packages.config 314 | 315 | # Tabs Studio 316 | *.tss 317 | 318 | # Telerik's JustMock configuration file 319 | *.jmconfig 320 | 321 | # BizTalk build output 322 | *.btp.cs 323 | *.btm.cs 324 | *.odx.cs 325 | *.xsd.cs 326 | 327 | # OpenCover UI analysis results 328 | OpenCover/ 329 | 330 | # Azure Stream Analytics local run output 331 | ASALocalRun/ 332 | 333 | # MSBuild Binary and Structured Log 334 | *.binlog 335 | 336 | # NVidia Nsight GPU debugger configuration file 337 | *.nvuser 338 | 339 | # MFractors (Xamarin productivity tool) working folder 340 | .mfractor/ 341 | 342 | # Local History for Visual Studio 343 | .localhistory/ 344 | 345 | # BeatPulse healthcheck temp database 346 | healthchecksdb 347 | 348 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 349 | MigrationBackup/ 350 | -------------------------------------------------------------------------------- /SwagLyricsGUI/ViewModels/MainWindowViewModel.cs: -------------------------------------------------------------------------------- 1 | using Avalonia; 2 | using ReactiveUI; 3 | using SwagLyricsGUI.Models; 4 | using SwagLyricsGUI.Views; 5 | using System; 6 | using System.Configuration; 7 | using System.Diagnostics; 8 | using System.IO; 9 | using System.Reflection; 10 | using System.Runtime.InteropServices; 11 | using System.Threading.Tasks; 12 | using System.Windows.Input; 13 | 14 | namespace SwagLyricsGUI.ViewModels 15 | { 16 | public class MainWindowViewModel : ViewModelBase 17 | { 18 | public ICommand CloseAppCommand { get; set; } 19 | public static MainWindowViewModel Current { get; set; } 20 | public ThemeManager ThemeManager { get; set; } 21 | System.Timers.Timer _timer = new System.Timers.Timer(20) 22 | { 23 | AutoReset = true, 24 | }; 25 | System.Timers.Timer _loadingTimer = new System.Timers.Timer(100) 26 | { 27 | AutoReset = true, 28 | }; 29 | public char[] LoadingASCII; 30 | private int _lastLoadingIndex = 0; 31 | public double ScrollSpeed = 1.1; 32 | private double t = 0; 33 | 34 | 35 | private int _themeIndex = 2; 36 | public int ThemeIndex 37 | { 38 | get => _themeIndex; 39 | set 40 | { 41 | this.RaiseAndSetIfChanged(ref _themeIndex, value); 42 | ThemeManager.ChangeTheme(value); 43 | Config.AppSettings.Settings["Theme"].Value = $"{value}"; 44 | Config.Save(); 45 | ConfigurationManager.RefreshSection("appSettings"); 46 | } 47 | } 48 | 49 | private bool _autoScroll = true; 50 | public bool AutoScroll 51 | { 52 | get => _autoScroll; 53 | set 54 | { 55 | _autoScroll = value; 56 | this.RaisePropertyChanged("AutoScroll"); 57 | } 58 | } 59 | 60 | private Avalonia.Layout.HorizontalAlignment _lyricsAlignment = Avalonia.Layout.HorizontalAlignment.Left; 61 | public Avalonia.Layout.HorizontalAlignment LyricsAlignment 62 | { 63 | get => _lyricsAlignment; 64 | set => this.RaiseAndSetIfChanged(ref _lyricsAlignment, value); 65 | } 66 | 67 | private Vector _scrollBarOffset; 68 | 69 | public Vector ScrollBarOffset 70 | { 71 | get => _scrollBarOffset; 72 | set => this.RaiseAndSetIfChanged(ref _scrollBarOffset, value); 73 | } 74 | 75 | 76 | private string _lyrics = ""; 77 | public string Lyrics 78 | { 79 | get => _lyrics; 80 | set 81 | { 82 | this.RaiseAndSetIfChanged(ref _lyrics, value); 83 | } 84 | } 85 | 86 | private string _song = "Nothing is playing"; 87 | public string Song 88 | { 89 | get => _song; 90 | set => this.RaiseAndSetIfChanged(ref _song, value); 91 | } 92 | public SwagLyricsBridge Bridge = new SwagLyricsBridge(); 93 | public Configuration Config; 94 | PrerequisitesChecker checker = new PrerequisitesChecker(); 95 | public BridgeManager Manager = new BridgeManager(); 96 | 97 | public MainWindowViewModel() 98 | { 99 | CloseAppCommand = new Command(OnClose); 100 | bool pythonInstalled = checker.SupportedPythonVersionInstalled(); 101 | if (pythonInstalled) 102 | { 103 | Manager.InitTempDirectory(); 104 | Manager.LoadEmbeddedScriptsToTempFolder(); 105 | checker.InstallSwagLyricsIfMissing(); 106 | Current = this; 107 | ThemeManager = new ThemeManager(); 108 | ThemeManager.LoadThemes(); 109 | Bridge.StartLyricsBridge(); 110 | Bridge.OnNewSong += Bridge_OnNewSong; 111 | Bridge.OnLyricsLoaded += Bridge_OnLyricsLoaded; 112 | Bridge.OnError += Bridge_OnError; 113 | Bridge.OnResumed += Bridge_OnResumed; 114 | Bridge.OnAdvertisement += Bridge_OnAdvertisement; 115 | _timer.Elapsed += _timer_Elapsed; 116 | _loadingTimer.Elapsed += _loadingTimer_Elapsed; 117 | LoadingASCII = "|/-\\".ToCharArray(); 118 | 119 | Config = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location); 120 | if (Config.AppSettings.Settings["Theme"]?.Value is string theme) 121 | { 122 | ThemeIndex = int.Parse(theme); 123 | } 124 | } 125 | else 126 | { 127 | Song = "Unsupported Python Version!"; 128 | Lyrics = "Minimal supported version is Python 3.6.\nDownload at " + @"https://www.python.org/downloads/"; 129 | } 130 | } 131 | 132 | private void Bridge_OnAdvertisement(object sender, EventArgs e) 133 | { 134 | System.Timers.Timer factTimer = new System.Timers.Timer(15000) 135 | { 136 | AutoReset = true 137 | }; 138 | Song = "Advertisement time. Catch some fun facts"; 139 | Lyrics = RandomFactsFetcher.GetRandomFact().ToString(); 140 | factTimer.Elapsed += (s, e) => 141 | { 142 | if (!Bridge.IsAdvertisement) { factTimer.Stop(); } 143 | else { Lyrics = RandomFactsFetcher.GetRandomFact().ToString(); } 144 | }; 145 | factTimer.Start(); 146 | } 147 | 148 | private void _loadingTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 149 | { 150 | Lyrics = LoadingASCII[_lastLoadingIndex].ToString(); 151 | if (_lastLoadingIndex == LoadingASCII.Length - 1) _lastLoadingIndex = -1; 152 | _lastLoadingIndex++; 153 | } 154 | 155 | private void OnClose(object obj) 156 | { 157 | Bridge?.LyricsProcess.Kill(true); 158 | File.Delete(Bridge.BridgeFileOnPath); 159 | } 160 | 161 | private void Bridge_OnResumed(object sender, System.EventArgs e) 162 | { 163 | _timer.Start(); 164 | } 165 | 166 | private void Bridge_OnError(object sender, LyricsLoadedEventArgs e) 167 | { 168 | if (e.Lyrics == "SpotifyNotRunning") 169 | { 170 | _timer.Stop(); 171 | } 172 | else 173 | { 174 | Lyrics = e.Lyrics; 175 | } 176 | } 177 | 178 | private void Bridge_OnLyricsLoaded(object sender, LyricsLoadedEventArgs e) 179 | { 180 | LyricsAlignment = Avalonia.Layout.HorizontalAlignment.Left; 181 | _loadingTimer.Stop(); 182 | Lyrics = e.Lyrics; 183 | Task.Delay(20000).ContinueWith((task) => { _timer.Start(); }); 184 | } 185 | 186 | private void Bridge_OnNewSong(object sender, NewSongEventArgs e) 187 | { 188 | LyricsAlignment = Avalonia.Layout.HorizontalAlignment.Center; 189 | Song = e.Song; 190 | _loadingTimer.Start(); 191 | ScrollBarOffset = new Vector(0, 0); 192 | t = 0; 193 | _timer.Stop(); 194 | } 195 | 196 | private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) 197 | { 198 | if (AutoScroll) 199 | { 200 | ScrollBarOffset = new Vector(0, MathEx.Lerp(0, MainWindow.Current.ScrollViewerVieportHeight, t)); 201 | } 202 | t += ScrollSpeed * 0.0001; 203 | } 204 | } 205 | } 206 | --------------------------------------------------------------------------------