Skip to content

Commit

Permalink
Merge pull request #37 from harlanx:feat/separate-update-for-text-mod…
Browse files Browse the repository at this point in the history
…ifiers

feat: Separate update for text modifiers on default profiles
  • Loading branch information
harlanx authored Oct 22, 2024
2 parents 0fe90ac + ebae7e5 commit 0af50ad
Show file tree
Hide file tree
Showing 15 changed files with 313 additions and 94 deletions.
93 changes: 93 additions & 0 deletions default_modifiers.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
[
{
"id": 0,
"replaceables": [
"\\bClean.Cam\\b",
"\\bTELESYNC\\b",
"\\bComplete\\b",
"\\bSubbed\\b",
"\\bDubbed\\b",
"\\bWEBRip\\b",
"\\bCAMRip\\b",
"\\bBluRay\\b",
"\\bWeb-Dl\\b",
"\\bBDRip\\b",
"\\bHDCam\\b",
"\\bDolby\\b",
"\\bAtmos\\b",
"\\bDual\\b,",
"\\bESub\\b,",
"\\bHEVC\\b",
"\\bDTS\\b",
"\\bAAC\\b",
"\\bSDR\\b",
"\\bHDR\\b",
"\\bWEB\\b",
"\\bUHD\\b",
"\\bRip\\b",
"\\bCAM\\b",
"\\bSD\\b",
"\\bHD\\b",
"\\bTS\\b"
],
"replacement": ""
},
{
"id": 1,
"replaceables": [
"\\b\\d{4}\\b",
"Season.\\d+|S.\\d+|Season \\d+|S \\d+",
"Episode.\\d+|E.\\d+|Episode \\d+|E \\d+|\\b\\d{2}\\b",
"\\d{3,4}p",
"x.\\d{3}|x\\d{3}",
"h.\\d{3}|h\\d{3}",
"[\\d]+bit",
"Part\\.\\d|Part\\s\\d",
"DD\\d+.\\d+|DDP\\d+.\\d+",
"TrueHD.\\d+.\\d+",
"\\[(.*?)\\]|\\((.*?)\\)",
"\\d+(?:\\.\\d+)?MB|\\d+(?:\\.\\d+)?GB",
"\\bAV\\d\\b",
"\\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\\b"
],
"replacement": ""
},
{
"id": 2,
"replaceables": [
"\\bTORRENTGALAXY\\b",
"\\bGalaxyRG265\\b",
"\\bSUNSCREEN\\b",
"\\bKONTRAST\\b",
"\\bGalaxyRG\\b",
"\\bGalaxyTV\\b",
"\\bPROTON\\b",
"\\bMeGusta\\b",
"\\bInfinity\\b",
"\\bELiTE\\b",
"\\bION265\\b",
"\\bION10\\b",
"\\bXEBEC\\b",
"\\bHULU\\b",
"\\bPCOK\\b",
"\\bFLUX\\b",
"\\bRARBG\\b",
"\\bMiNX\\b",
"\\bZMNT\\b",
"\\bYIFY\\b",
"\\bAMZN\\b",
"\\bTGx\\b",
"\\bNF\\b"
],
"replacement": ""
},
{
"id": 3,
"replaceables": [
".",
"_",
"-"
],
"replacement": " "
}
]
36 changes: 25 additions & 11 deletions lib/data/user_profiles_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ class UserProfilesNotifier extends ChangeNotifier {
UserProfile(
id: 0,
name: 'None',
isDefault: true,
),
UserProfile(
id: 1,
name: 'Default (Movie)',
name: 'Movie (Default)',
isDefault: true,
showTitleFormat: '%show_title%% (year)%',
videoTitleFormat: '%show_title%',
audioTitleFormat: '%language%',
Expand All @@ -31,7 +33,8 @@ class UserProfilesNotifier extends ChangeNotifier {
),
UserProfile(
id: 2,
name: 'Default (Series)',
name: 'Series (Default)',
isDefault: true,
showTitleFormat: '%show_title%',
videoTitleFormat:
'%show_title%% - Sseason_number%%Eepisode_number%% - episode_title%',
Expand All @@ -50,15 +53,17 @@ class UserProfilesNotifier extends ChangeNotifier {
];

void load() {
// Loads hard-coded default profiles
// Used only on initial usage of the app.
_items.addEntries(defaultProfiles.map((e) => MapEntry(e.id, e)));

final profilesJson = SharedPrefs.getStringList('UserProfiles');
if (profilesJson != null) {
_items.addAll({
for (var profile
in profilesJson.map((e) => UserProfile.fromJson(jsonDecode(e))))
profile.id: profile
});
// Loading saved profiles
// Hard-coded default profiles are replaced by the saved default profiles.
final userProfilesJson = SharedPrefs.getStringList('UserProfiles');
if (userProfilesJson != null) {
final userProfiles =
userProfilesJson.map((e) => UserProfile.fromJson(jsonDecode(e)));
_items.addEntries(userProfiles.map((e) => MapEntry(e.id, e)));
}
}

Expand All @@ -82,8 +87,7 @@ class UserProfilesNotifier extends ChangeNotifier {
Future<void> export(String path) async {
// Exclude default profiles.
final toBeSaved = <UserProfile>[
for (var item in _items.entries)
if (item.key >= 3) ...[item.value]
for (var item in _items.entries) item.value
];
final jsonString = jsonEncode(toBeSaved);
await File(path).writeAsString(jsonString);
Expand All @@ -100,4 +104,14 @@ class UserProfilesNotifier extends ChangeNotifier {
_items.remove(id);
notifyListeners();
}

void updateDefaultModifiers(String json) {
final List<dynamic> jsonList = jsonDecode(json);
final newModifiers = jsonList
.map((e) => TextModifier.fromJson(e as Map<String, dynamic>))
.toList();
_items[2]!.modifiers = newModifiers;
_items[2]!.modifiers = newModifiers;
notifyListeners();
}
}
4 changes: 3 additions & 1 deletion lib/l10n/intl_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,7 @@
"sameAsOutput": "Same as output file title",
"textAlgorithmSubstitute": "Text matching substitute algorithm",
"selectSubtitleLanguageToInclude": "Select subtitle languages to include and choose to set as default",
"selectAudioLanguageToInclude": "Select audio languages to include and choose to set as default"
"selectAudioLanguageToInclude": "Select audio languages to include and choose to set as default",
"newModifiersAvailable": "New text modifiers available!",
"modifiersUpdated": "Default profiles' text modifiers are updated to latest!"
}
4 changes: 3 additions & 1 deletion lib/l10n/intl_fil.arb
Original file line number Diff line number Diff line change
Expand Up @@ -267,5 +267,7 @@
"sameAsOutput": "Kapareho sa pangalan ng output file",
"textAlgorithmSubstitute": "Kapalit na pantugmang algoritmo sa text",
"selectSubtitleLanguageToInclude": "Piliin ang mga lengguwahe ng subtitle na isasama at pumili ng itatakdang default",
"selectAudioLanguageToInclude": "Piliin ang mga lengguwahe ng audio na isasama at pumili ng itatakdang default"
"selectAudioLanguageToInclude": "Piliin ang mga lengguwahe ng audio na isasama at pumili ng itatakdang default",
"newModifiersAvailable": "May bagong text modifiers na available!",
"modifiersUpdated": "Ang mga text modifiers ng default profiles ay updated na!"
}
13 changes: 13 additions & 0 deletions lib/models/app_update.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class AppUpdate {
AppUpdate({
required this.isOutdated,
required this.info,
required this.isModifiersOutdated,
required this.modifiersInfo,
});

final bool isOutdated;
final Map<String, dynamic> info;
final bool isModifiersOutdated;
final String modifiersInfo;
}
1 change: 1 addition & 0 deletions lib/models/models.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ export 'mkv_info.dart';
export 'show.dart';
export 'language_code.dart';
export 'scan_error.dart';
export 'app_update.dart';
19 changes: 16 additions & 3 deletions lib/models/user_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
UserProfile({
required this.id,
required this.name,
required this.isDefault,
this.showTitleFormat = '',
this.videoTitleFormat = '',
this.audioTitleFormat = '',
Expand Down Expand Up @@ -96,6 +97,8 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
r'\bHDCam\b',
r'\bDolby\b',
r'\bAtmos\b',
r'\bDual\b,',
r'\bESub\b,',
r'\bHEVC\b',
r'\bDTS\b',
r'\bAAC\b',
Expand All @@ -105,8 +108,8 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
r'\bUHD\b',
r'\bRip\b',
r'\bCAM\b',
r'\bSDb',
r'\bHDb',
r'\bSD\b',
r'\bHD\b',
r'\bTS\b',
],
replacement: '',
Expand All @@ -126,6 +129,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
r'TrueHD.\d+.\d+', // 'TrueHD.7.1', 'TrueHD.5.1', Atmos
r'\[(.*?)\]|\((.*?)\)', // [Anything with square brackets] (and Parentheses)
r'\d+(?:\.\d+)?MB|\d+(?:\.\d+)?GB', // 200MB, 150.20MB, 2GB, 2.5GB
r'\bAV\d\b',
r'\bM{0,4}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3})\b', // Roman numerals
],
replacement: '',
Expand All @@ -142,10 +146,11 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
r'\bPROTON\b',
r'\bMeGusta\b',
r'\bInfinity\b',
r'\b\bELiTEb',
r'\bELiTE\b',
r'\bION265\b',
r'\bION10\b',
r'\bXEBEC\b',
r'\bHULU\b',
r'\bPCOK\b',
r'\bFLUX\b',
r'\bRARBG\b',
Expand Down Expand Up @@ -186,6 +191,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {

int id;
String name;
bool isDefault;
String showTitleFormat;
String videoTitleFormat;
String audioTitleFormat;
Expand All @@ -206,6 +212,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
return UserProfile(
id: json['id'],
name: json['name'],
isDefault: json['isDefault'],
showTitleFormat: json['showTitleFormat'],
videoTitleFormat: json['videoTitleFormat'],
audioTitleFormat: json['audioTitleFormat'],
Expand All @@ -228,6 +235,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
Map<String, dynamic> toJson() => {
'id': id,
'name': name,
'isDefault': isDefault,
'showTitleFormat': showTitleFormat,
'videoTitleFormat': videoTitleFormat,
'audioTitleFormat': audioTitleFormat,
Expand All @@ -248,6 +256,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
UserProfile copyWith({
int? id,
String? name,
bool? isDefault,
String? showTitleFormat,
String? videoTitleFormat,
String? audioTitleFormat,
Expand All @@ -267,6 +276,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
UserProfile(
name: name ?? this.name,
id: id ?? this.id,
isDefault: isDefault ?? this.isDefault,
showTitleFormat: showTitleFormat ?? this.showTitleFormat,
videoTitleFormat: videoTitleFormat ?? this.videoTitleFormat,
audioTitleFormat: audioTitleFormat ?? this.audioTitleFormat,
Expand All @@ -290,6 +300,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
void update({
String? name,
int? id,
bool? isDefault,
String? showTitleFormat,
String? videoTitleFormat,
String? audioTitleFormat,
Expand All @@ -308,6 +319,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
}) {
this.name = name ?? this.name;
this.id = id ?? this.id;
this.isDefault = isDefault ?? this.isDefault;
this.showTitleFormat = showTitleFormat ?? this.showTitleFormat;
this.videoTitleFormat = videoTitleFormat ?? this.videoTitleFormat;
this.audioTitleFormat = audioTitleFormat ?? this.audioTitleFormat;
Expand Down Expand Up @@ -425,6 +437,7 @@ class UserProfile extends ChangeNotifier with EquatableMixin {
List<Object> get props => [
id,
name,
isDefault,
showTitleFormat,
videoTitleFormat,
audioTitleFormat,
Expand Down
4 changes: 2 additions & 2 deletions lib/screens/main_screen.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:flutter/foundation.dart' as foundation;
import 'package:flutter/foundation.dart';
import 'package:fluent_ui/fluent_ui.dart';

import 'package:provider/provider.dart';
Expand Down Expand Up @@ -70,7 +70,7 @@ class MainScreen extends StatelessWidget {
title: Text(l10n.settings),
body: const SettingsScreen(),
),
if (foundation.kDebugMode) ...[
if (kDebugMode) ...[
PaneItem(
key: const Key('/testing'),
icon: const Icon(FluentIcons.test_impact_solid),
Expand Down
Loading

0 comments on commit 0af50ad

Please sign in to comment.