Skip to content

Commit

Permalink
feat: expose innertube client as a flag in yt settings
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 22, 2024
1 parent 402d358 commit eb651ef
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 8 deletions.
14 changes: 10 additions & 4 deletions lib/controller/settings.youtube.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,18 @@ class _YoutubeSettings with SettingsFileWriter {
final ytVisibleShorts = <YTVisibleShortPlaces, bool>{}.obs;
final ytVisibleMixes = <YTVisibleMixesPlaces, bool>{}.obs;

bool markVideoWatched = true;
int addToPlaylistsTabIndex = 0;
bool markVideoWatched = true;
InnertubeClients? innertubeClient;

void save({
int? addToPlaylistsTabIndex,
bool? markVideoWatched,
InnertubeClients? innertubeClient,
}) {
if (addToPlaylistsTabIndex != null) this.addToPlaylistsTabIndex = addToPlaylistsTabIndex;
if (markVideoWatched != null) this.markVideoWatched = markVideoWatched;
if (innertubeClient != null) this.innertubeClient = innertubeClient;
_writeToStorage();
}

Expand All @@ -32,10 +35,12 @@ class _YoutubeSettings with SettingsFileWriter {
final json = await prepareSettingsFile_();
if (json == null) return;
try {
json as Map;
ytVisibleShorts.value = (json['ytVisibleShorts'] as Map?)?.map((key, value) => MapEntry(YTVisibleShortPlaces.values.getEnum(key)!, value)) ?? ytVisibleShorts.value;
ytVisibleMixes.value = (json['ytVisibleMixes'] as Map?)?.map((key, value) => MapEntry(YTVisibleMixesPlaces.values.getEnum(key)!, value)) ?? ytVisibleMixes.value;
addToPlaylistsTabIndex = json['addToPlaylistsTabIndex'] ?? addToPlaylistsTabIndex;
markVideoWatched = json['markVideoWatched'] ?? markVideoWatched;
innertubeClient = InnertubeClients.values.getEnum(json['innertubeClient']);
} catch (e) {
printy(e, isError: true);
}
Expand All @@ -45,11 +50,12 @@ class _YoutubeSettings with SettingsFileWriter {
Object get jsonToWrite => <String, dynamic>{
'ytVisibleShorts': ytVisibleShorts.map((key, value) => MapEntry(key.convertToString, value)),
'ytVisibleMixes': ytVisibleMixes.map((key, value) => MapEntry(key.convertToString, value)),
'addToPlaylistsTabIndex ': addToPlaylistsTabIndex,
'markVideoWatched ': markVideoWatched,
'addToPlaylistsTabIndex': addToPlaylistsTabIndex,
'markVideoWatched': markVideoWatched,
'innertubeClient': innertubeClient?.convertToString,
};

Future<void> _writeToStorage() async => await writeToStorage();
Future<void> _writeToStorage() => writeToStorage();

@override
String get filePath => AppPaths.SETTINGS_YOUTUBE;
Expand Down
1 change: 1 addition & 0 deletions lib/controller/settings_controller.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';

import 'package:history_manager/history_manager.dart';
import 'package:youtipie/core/http.dart';

import 'package:namida/base/settings_file_writer.dart';
import 'package:namida/class/lang.dart';
Expand Down
33 changes: 32 additions & 1 deletion lib/ui/widgets/settings/youtube_settings.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import 'package:flutter/material.dart';

import 'package:youtipie/core/http.dart';

import 'package:namida/base/setting_subpage_provider.dart';
import 'package:namida/class/route.dart';
import 'package:namida/controller/file_browser.dart';
Expand Down Expand Up @@ -535,9 +537,38 @@ class __YTFlagsOptionsState extends State<_YTFlagsOptions> {
children: [
CustomSwitchListTile(
value: settings.youtube.markVideoWatched,
onChanged: (isTrue) => settings.youtube.save(markVideoWatched: !isTrue),
onChanged: (isTrue) => setState(() => settings.youtube.save(markVideoWatched: !isTrue)),
title: 'mark_video_watched'.toUpperCase(),
),
CustomListTile(
title: 'innertube_client'.toUpperCase(),
trailing: NamidaPopupWrapper(
childrenDefault: () => [
InnertubeClients.tvEmbedded,
InnertubeClients.web,
InnertubeClients.ios,
InnertubeClients.android,
InnertubeClients.mweb,
InnertubeClients.webEmbedded,
InnertubeClients.iosEmbedded,
InnertubeClients.androidEmbedded,
InnertubeClients.webCreator,
InnertubeClients.iosCreator,
InnertubeClients.androidCreator,
]
.map(
(e) => NamidaPopupItem(
icon: Broken.video_octagon,
title: e.name,
onTap: () {
setState(() => settings.youtube.save(innertubeClient: e));
},
),
)
.toList(),
child: Text(settings.youtube.innertubeClient?.name ?? lang.DEFAULT)),
onTap: () {},
),
],
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,15 @@ class _VideoInfoController {
const _VideoInfoController();

/// tvEmbedded can bypass age restricted and obtain higher quality streams.
static const _usedClient = InnertubeClients.tvEmbedded;
static const _requiresJSPlayer = true;
static const _defaultClient = InnertubeClients.tvEmbedded;
static const _defaultRequiresJSPlayer = true;

InnertubeClients get _usedClient => settings.youtube.innertubeClient ?? _defaultClient;
bool get _requiresJSPlayer {
final userSpecified = settings.youtube.innertubeClient;
if (userSpecified == null) return _defaultRequiresJSPlayer;
return userSpecified.configuration.requireJSPlayer == true;
}

bool get jsPreparedIfRequired => _requiresJSPlayer ? YoutiPie.cipher.isPrepared : true;

Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: namida
description: A Beautiful and Feature-rich Music Player, With YouTube & Video Support Built in Flutter
publish_to: "none"
version: 3.5.6-beta+240722220
version: 3.5.7-beta+240722227

environment:
sdk: ">=3.4.0 <4.0.0"
Expand Down

0 comments on commit eb651ef

Please sign in to comment.