Skip to content

Commit

Permalink
Dev (#11)
Browse files Browse the repository at this point in the history
* Implemented option to keep Subloader window always on top plus some refactorings

* #10 : Implemented feature that allows users to download multiple files in directory where video file is located or in separate Subs folder

* style fixes

* Refactored settings logic

* Some folder reorganization

* Main Control UI refactor plus fix save search by settings

* Tiny task refactors

* Added overwrite same language file option, and updated readme

* settings screenshot update
  • Loading branch information
Valyreon committed Dec 15, 2020
1 parent 6319b78 commit d9feca4
Show file tree
Hide file tree
Showing 23 changed files with 347 additions and 229 deletions.
35 changes: 20 additions & 15 deletions .editorconfig
Expand Up @@ -101,10 +101,10 @@ visual_basic_preferred_modifier_order = Partial,Default,Private,Protected,Public
dotnet_style_readonly_field = true:warning
# Parentheses preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#parentheses-preferences
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:warning
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:suggestion
dotnet_style_parentheses_in_arithmetic_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_relational_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_binary_operators = always_for_clarity:silent
dotnet_style_parentheses_in_other_operators = never_if_unnecessary:warning
# Expression-level preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-level-preferences
dotnet_style_object_initializer = true:warning
Expand All @@ -114,8 +114,8 @@ dotnet_style_prefer_inferred_tuple_names = true:warning
dotnet_style_prefer_inferred_anonymous_type_member_names = true:warning
dotnet_style_prefer_auto_properties = true:warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:warning
dotnet_style_prefer_conditional_expression_over_assignment = false:suggestion
dotnet_style_prefer_conditional_expression_over_return = false:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:suggestion
dotnet_style_prefer_conditional_expression_over_return = true:suggestion
dotnet_style_prefer_compound_assignment = true:warning
# Null-checking preferences
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#null-checking-preferences
Expand All @@ -140,18 +140,21 @@ csharp_style_var_when_type_is_apparent = true:warning
csharp_style_var_elsewhere = true:warning
# Expression-bodied members
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#expression-bodied-members
csharp_style_expression_bodied_methods = true:warning
csharp_style_expression_bodied_constructors = true:warning
csharp_style_expression_bodied_operators = true:warning
csharp_style_expression_bodied_properties = true:warning
csharp_style_expression_bodied_indexers = true:warning
csharp_style_expression_bodied_accessors = true:warning
csharp_style_expression_bodied_lambdas = true:warning
csharp_style_expression_bodied_local_functions = true:warning
csharp_style_expression_bodied_accessors = when_on_single_line:warning
csharp_style_expression_bodied_constructors = false:warning
csharp_style_expression_bodied_indexers = when_on_single_line:warning
csharp_style_expression_bodied_lambdas = when_on_single_line:warning
csharp_style_expression_bodied_local_functions = when_on_single_line:warning
csharp_style_expression_bodied_methods = false:warning
csharp_style_expression_bodied_operators = when_on_single_line:warning
csharp_style_expression_bodied_properties = when_on_single_line:warning
# Pattern matching
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#pattern-matching
csharp_style_pattern_matching_over_is_with_cast_check = true:warning
csharp_style_pattern_matching_over_as_with_null_check = true:warning
csharp_style_prefer_not_pattern = true:warning
csharp_style_prefer_pattern_matching = true:warning
csharp_style_prefer_switch_expression = true:warning
# Inlined variable declarations
# https://docs.microsoft.com/visualstudio/ide/editorconfig-language-conventions#inlined-variable-declarations
csharp_style_inlined_variable_declaration = true:warning
Expand Down Expand Up @@ -435,7 +438,9 @@ dotnet_naming_rule.parameters_rule.severity = warning
##########################################

# IDE0002: Name can be simplified
# dotnet_diagnostic.IDE0002.severity = warning
dotnet_diagnostic.IDE0002.severity = warning

# IDE0005: Remove unnecessary imports
dotnet_diagnostic.IDE0005.severity = warning
dotnet_diagnostic.IDE0058.severity = none
dotnet_diagnostic.IDE1006.severity = none
31 changes: 22 additions & 9 deletions README.md
Expand Up @@ -3,42 +3,55 @@
# Subloader
![](https://img.shields.io/badge/Price-Free-brightgreen.svg)
![](https://img.shields.io/badge/License-MIT-blue.svg)
![](https://img.shields.io/badge/Release-1.3.0-blue.svg)
![](https://img.shields.io/badge/Release-1.4.0-blue.svg)

**Subloader** is a simple and minimalistic software written in **C#** and **.NET Core 3.1** that enables you to quickly find and download subtitles for your movies and TV Shows. It interfaces with **Opensubtitles** database by using REST API for searching and downloading subtitles.

Subloader searches subtitles by using a special file hash. This enables the user to get the best possible search results for their video file. **Installer** will also add an entry to **right click context menu** of **.avi**, **.mkv** and **.mp4** files for easy access. It will also follow Windows 10 accent color for UI main color.

Search and download is provided by **[Opensubtitles](http://www.opensubtitles.org/)**. Big thanks to their team for this great project. Please consider showing your appreciation by **[supporting them](https://www.opensubtitles.org/en/support)**.
Search and download is provided by **[Opensubtitles](http://www.opensubtitles.org/)**. Big thanks to their team, please consider showing your appreciation by **[supporting them](https://www.opensubtitles.org/en/support)**.

### Installation

Subloader requires **[.NET Core 3.1 Runtime](https://dotnet.microsoft.com/download)** to run. It was developed in Visual Studio Community 2019.

Download the **[latest version of Subloader](https://github.com/Valyreon/Subloader/releases)**, run the setup and that's it. You can now right click your video file and get your subtitles in a matter of seconds. Enjoy!

#### Manual installation

To compile Subloader yourself you don't have to install Visual Studio, just .NET Core 3.1 SDK. Go to the Subloader folder that contains the solution, open terminal and run:

```
dotnet publish SubloaderWpf -p:PublishSingleFile=true --no-self-contained -r win-x64 -o .
```

This will output the compiled exe file in the current directory. Generated pdb files are not neccessary.

### Usage

Subloader can be opened from Start Menu, and then using the 'Open' button you can choose a video file. Search will begin immediately.
Subloader can be opened from Start Menu, and then using the 'Open' button you can choose a video file. Search will begin immediately. Installer will also add 'Find subtitles' menu in right click context menu of .avi, .mkv and .mp4 files for easy access.

After the search is complete, you can select a subtitle from the list and click 'Download' or doubleclick the subtitle.

When you click 'Download' Subloader will download subtitle in the same directory where video file is, under the same name and appropriate extension. If there is an existing subtitle with the same name, it will overwrite it.
When you click 'Download' or double click an item in the table Subloader will download the subtitle. The name and location of the file depends on Settings, default (without options below checked) behaviour is to download subtitles into a file that is the same name as the video file with a different extension.

Depending on the time of day, Opensubtitles server will sometimes be busy and you will get a 'Service temporarily unavailable'. In that case, try clicking 'Refresh' a few times.

Installer will also add 'Find subtitles' menu in right click context menu of .avi, .mkv and .mp4 files for easy access.
In **Settings** you can configure wanted **subtitle languages** as well as other options:

SubLoader now has a working UI for configuring wanted subtitle languages. You can access it via 'Settings' button on the main form in the bottom right corner.
* **Always on top** - When checked, Subloader will stay above other windows.
* **Allow multiple downloads** - If this option is checked Subloader will allow downloading multiple subtitle files named *movie-title.lang-id.format*, for example: *matrix-reloaded.eng.srt*. If user downloads multiple subtitles from the same language, the files will be named *movie-name.(1).lang-id.format*.
* **Download to Subs folder** - This option allows user to download subtitles into a separate Subs folder in the same directory as the file. This option can be used only if option above is checked as well. The naming of the files is the same as for the option above.
* **Overwrite same language files** - If checked, when user downloads multiple subtitles of the same language Subloader won't create multiple files named *movie-name.(1).lang-id.format*, *movie-name.(2).lang-id.format* etc. but overwrite the existing *movie-title.lang-id.format* file with the last downloaded subtitle.

### Acknowledgments

Icon made by **[Freepik](https://www.flaticon.com/authors/freepik)** from **[Flaticon](https://www.flaticon.com )**.

### Screenshots
| | | |
|:-------------------------:|:-------------------------:|:-------------------------:|
|<img width="1604" alt="screenshot 1" src="https://raw.githubusercontent.com/Valyreon/Subloader/master/screenshot.png"> | <img width="1604" alt="screen shot 2017-08-07 at 12 18 15 pm" src="https://raw.githubusercontent.com/Valyreon/Subloader/master/screenshot2.png">|<img width="1604" alt="screen shot 2017-08-07 at 12 18 15 pm" src="https://raw.githubusercontent.com/Valyreon/Subloader/master/screenshot3.png">|
| | |
|:-------------------------:|:-------------------------:|
| <img width="1604" alt="screen shot 2017-08-07 at 12 18 15 pm" src="https://raw.githubusercontent.com/Valyreon/Subloader/master/screenshot3.png">|<img width="1604" alt="screen shot 2017-08-07 at 12 18 15 pm" src="https://raw.githubusercontent.com/Valyreon/Subloader/master/screenshot2.png">|

### To do
- ~~**Language settings window**~~
Expand Down
4 changes: 2 additions & 2 deletions SubloaderWpf/App.xaml.cs
@@ -1,7 +1,6 @@
using System;
using System.Threading;
using System.Windows;
using SubloaderWpf.Models;
using SubloaderWpf.Utilities;

namespace SubloaderWpf
Expand All @@ -13,6 +12,8 @@ public partial class App : Application

public string PathArg { get; set; }

public static Settings Settings { get; } = SettingsParser.Load();

protected override void OnStartup(StartupEventArgs e)
{
if (e.Args.Length > 0)
Expand Down Expand Up @@ -47,7 +48,6 @@ protected override void OnStartup(StartupEventArgs e)

private void ApplicationExit(object sender, ExitEventArgs e)
{
ApplicationSettings.Instance.SaveIfDirty();
Cleanup();
}

Expand Down
@@ -1,4 +1,4 @@
namespace SubloaderWpf.ViewModels
namespace SubloaderWpf.Interfaces
{
public interface INavigator
{
Expand Down
132 changes: 0 additions & 132 deletions SubloaderWpf/Models/ApplicationSettings.cs

This file was deleted.

21 changes: 21 additions & 0 deletions SubloaderWpf/Models/Settings.cs
@@ -0,0 +1,21 @@
using System.Collections.Generic;

namespace SubloaderWpf.Utilities
{
public class Settings
{
public bool IsByNameChecked { get; set; } = false;

public bool IsByHashChecked { get; set; } = true;

public bool KeepWindowOnTop { get; set; } = true;

public bool DownloadToSubsFolder { get; set; } = false;

public bool AllowMultipleDownloads { get; set; } = false;

public bool OverwriteSameLanguageSub { get; set; } = false;

public IEnumerable<SubtitleLanguage> WantedLanguages { get; set; } = new List<SubtitleLanguage>();
}
}
11 changes: 8 additions & 3 deletions SubloaderWpf/Models/SubtitleEntry.cs
@@ -1,11 +1,14 @@
using System.ComponentModel;
using SuppliersLibrary;

namespace SubloaderWpf.Models
namespace SubloaderWpf.Utilities
{
public class SubtitleEntry : INotifyPropertyChanged
{
public SubtitleEntry(ISubtitleResultItem item) => Model = item;
public SubtitleEntry(ISubtitleResultItem item)
{
Model = item;
}

public event PropertyChangedEventHandler PropertyChanged;

Expand All @@ -15,7 +18,9 @@ public class SubtitleEntry : INotifyPropertyChanged

public ISubtitleResultItem Model { get; }

protected void OnPropertyChanged(string name) =>
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
}
}
2 changes: 1 addition & 1 deletion SubloaderWpf/Models/SubtitleLanguage.cs
@@ -1,6 +1,6 @@
using System.Collections.Generic;

namespace SubloaderWpf.Models
namespace SubloaderWpf.Utilities
{
public class SubtitleLanguage
{
Expand Down
9 changes: 6 additions & 3 deletions SubloaderWpf/Utilities/InstanceMediator.cs
Expand Up @@ -15,11 +15,11 @@ public class InstanceMediator

public void StartListening()
{
var x = Task.Run(() =>
Task.Run(() =>
{
while (true)
{
using var server = new NamedPipeServerStream(NamedPipeName as string);
using var server = new NamedPipeServerStream(NamedPipeName);
server.WaitForConnection();
using var reader = new StreamReader(server);
Expand All @@ -30,7 +30,10 @@ public void StartListening()
}, tokenSource.Token);
}

public void StopListening() => tokenSource.Cancel();
public void StopListening()
{
tokenSource.Cancel();
}

public static void SendArgumentToRunningInstance(string arg)
{
Expand Down

0 comments on commit d9feca4

Please sign in to comment.