Skip to content

Commit

Permalink
chore: freaky adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 25, 2024
1 parent 16cdb22 commit 9f48569
Show file tree
Hide file tree
Showing 15 changed files with 67 additions and 73 deletions.
2 changes: 1 addition & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.SEND" />
<data
android:host="com.msob7y.namida.patreonauth"
android:host="patreonauth.msob7y.namida"
android:scheme="app" />
</intent-filter>
<intent-filter>
Expand Down
19 changes: 2 additions & 17 deletions lib/controller/logs_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class _Log {
methodCount: 48,
errorMethodCount: 48,
),
output: _FileOutput(file: File(AppPaths.LOGS), fileClean: File(AppPaths.LOGS_CLEAN)),
output: _FileOutput(file: File(AppPaths.LOGS)),
);
}

Expand All @@ -41,14 +41,11 @@ class _Log {
}

class _FileOutput extends LogOutput {
_FileOutput({required this.file, required this.fileClean});
_FileOutput({required this.file});
final File file;
final File fileClean;

late final IOSink _sink;

// final _cleanLogsMap = <String?, Map<String, int>>{}; // <stackTrace, <error, count>{}>{}

@override
Future<void> init() async {
try {
Expand All @@ -60,9 +57,6 @@ class _FileOutput extends LogOutput {
await _sink.flush();
}
} catch (_) {}
// try {
// await fileClean.create();
// } catch (_) {}
return await super.init();
}

Expand All @@ -77,18 +71,9 @@ class _FileOutput extends LogOutput {
} catch (_) {}
}

// void _writeCleanFile(OutputEvent event) {
// // -- clean logs
// final stackString = event.origin.stackTrace.toString();
// _cleanLogsMap[stackString] ??= <String, int>{};
// _cleanLogsMap[stackString]!.update("${event.origin.error} => ${event.origin.message}", (value) => value + 1, ifAbsent: () => 1);
// fileClean.writeAsJson(_cleanLogsMap);
// }

@override
void output(OutputEvent event) async {
_writeMainFile(event);
// _writeCleanFile(event);
}

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/controller/lyrics_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class _LRCSearchManager with PortsProvider<SendPort> {
_completer?.completeIfWasnt([]);
_completer = Completer<List<LyricsModel>>();

await initialize();
if (!isInitialized) await initialize();
final p = customQuery != null && customQuery.isNotEmpty ? customQuery : queries;
await sendPort(p);
final res = await _completer?.future ?? [];
Expand Down
3 changes: 2 additions & 1 deletion lib/controller/settings.youtube.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ class _YoutubeSettings with SettingsFileWriter {
int? addToPlaylistsTabIndex,
bool? markVideoWatched,
InnertubeClients? innertubeClient,
bool setDefaultInnertubeClient = false,
bool? whiteVideoBGInLightMode,
bool? enableDimInLightMode,
}) {
if (addToPlaylistsTabIndex != null) this.addToPlaylistsTabIndex = addToPlaylistsTabIndex;
if (markVideoWatched != null) this.markVideoWatched = markVideoWatched;
if (innertubeClient != null) this.innertubeClient = innertubeClient;
if (innertubeClient != null || setDefaultInnertubeClient) this.innertubeClient = innertubeClient;
if (whiteVideoBGInLightMode != null) this.whiteVideoBGInLightMode = whiteVideoBGInLightMode;
if (enableDimInLightMode != null) this.enableDimInLightMode = enableDimInLightMode;
_writeToStorage();
Expand Down
7 changes: 3 additions & 4 deletions lib/controller/thumbnail_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ class ThumbnailManager {
String? symlinkId,
bool isTemp = false,
}) {
final dirPrefix = isTemp ? 'temp/' : '';

final goodId = id != null && id.isNotEmpty;
if (goodId || type == ThumbnailType.video) {
String? filename;
if (symlinkId != null) {
filename = symlinkId;
} else if (goodId) {
filename = '$id.png';
} else if (url != null) {
} else if (url != null && isTemp) {
try {
int? indexStart;
final index1try = url.indexOf('/vi/shorts/');
Expand All @@ -74,11 +76,9 @@ class ThumbnailManager {
},
);
}
isTemp = true;
} catch (_) {}
}
if (filename == null || filename.isEmpty) return null;
final dirPrefix = isTemp ? 'temp/' : '';
return File("${AppDirs.YT_THUMBNAILS}$dirPrefix$filename");
}
String? finalUrl = url;
Expand All @@ -90,7 +90,6 @@ class ThumbnailManager {
}

if (finalUrl != null) {
final dirPrefix = isTemp ? 'temp/' : '';
return File("${AppDirs.YT_THUMBNAILS_CHANNELS}$dirPrefix${symlinkId ?? finalUrl}");
}

Expand Down
2 changes: 1 addition & 1 deletion lib/core/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ class AppPaths {

static String get LOGS => _getLogsFile('');
static String get LOGS_TAGGER => _getLogsFile('_tagger');
static String get LOGS_CLEAN => _getLogsFile('_clean');

static String _getLogsFile(String identifier) {
final suffix = getLogsSuffix() ?? '_unknown';
Expand Down Expand Up @@ -480,6 +479,7 @@ const kDummyExtendedTrack = TrackExtended(
discNo: 0,
language: "",
lyrics: "",
label: "",
);

/// Unknown Tag Fields
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/dialogs/track_advanced_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,7 @@ class _TracksSearchTemp with PortsProvider<Map> {
_TracksSearchTemp(this._onResult);

void search(String text) async {
await initialize();
if (!isInitialized) await initialize();
final p = {'text': text, 'temp': true};
await sendPort(p);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/pages/about_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -419,12 +419,12 @@ class _AboutPageState extends State<AboutPage> {
body: 'pls look at this report im beggin u pls solve my issue pls i wa-',
subject: 'Namida Logs Report',
recipients: [AppSocial.EMAIL],
attachments: [AppPaths.LOGS, AppPaths.LOGS_TAGGER, AppPaths.LOGS_CLEAN],
attachments: [AppPaths.LOGS, AppPaths.LOGS_TAGGER],
);
await FlutterMailer.send(mailOptions);
},
),
onTap: () => Share.shareXFiles([XFile(AppPaths.LOGS), XFile(AppPaths.LOGS_TAGGER), XFile(AppPaths.LOGS_CLEAN)]),
onTap: () => Share.shareXFiles([XFile(AppPaths.LOGS), XFile(AppPaths.LOGS_TAGGER)]),
)
],
),
Expand Down
51 changes: 29 additions & 22 deletions lib/ui/widgets/settings/youtube_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -544,28 +544,35 @@ class __YTFlagsOptionsState extends State<_YTFlagsOptions> {
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(),
NamidaPopupItem(
icon: Broken.video_horizontal,
title: lang.DEFAULT,
onTap: () {
setState(() => settings.youtube.save(setDefaultInnertubeClient: true));
},
),
...[
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));
},
),
),
],
child: Text(settings.youtube.innertubeClient?.name ?? lang.DEFAULT)),
onTap: () {},
),
Expand Down
13 changes: 5 additions & 8 deletions lib/ui/widgets/video_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
title: audioTrack?.displayName ?? '?',
subtitle: " • ${audioTrack?.langCode ?? 0}",
onPlay: (isSelected) {
if (!isSelected) {
if (!isSelected || Player.inst.videoPlayerInfo.value?.isInitialized == true) {
Player.inst.onItemPlayYoutubeIDSetAudio(
stream: element,
mainStreams: streams,
Expand Down Expand Up @@ -1113,10 +1113,7 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
} else {
final id = Player.inst.currentVideoR?.id;
final cachedFile = id == null ? null : element.getCachedFile(id);
bool isSelected = settings.ytIsAudioOnlyMode.valueR
? false
: (element.itag == Player.inst.currentVideoStream.valueR?.itag ||
(Player.inst.currentCachedVideo.valueR != null && cachedFile?.path == Player.inst.currentCachedVideo.valueR?.path));
bool isSelected = false;
if (settings.ytIsAudioOnlyMode.valueR) {
isSelected = false;
} else {
Expand All @@ -1125,8 +1122,8 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
isSelected = element.itag == currentVS.itag;
} else {
final currentCachedV = Player.inst.currentCachedVideo.valueR;
if (currentCachedV != null) {
isSelected = cachedFile?.path == currentCachedV.path;
if (currentCachedV != null && cachedFile != null) {
isSelected = cachedFile.path == currentCachedV.path;
}
}
}
Expand All @@ -1136,7 +1133,7 @@ class NamidaVideoControlsState extends State<NamidaVideoControls> with TickerPro
subtitle: " • ${element.sizeInBytes.fileSizeFormatted}",
thirdLine: element.bitrateText(),
onPlay: (isSelected) {
if (!isSelected) {
if (!isSelected || Player.inst.videoPlayerInfo.value?.isInitialized != true) {
Player.inst.onItemPlayYoutubeIDSetQuality(
mainStreams: streams,
stream: element,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ part of namidayoutubeinfo;
class _VideoInfoController {
const _VideoInfoController();

/// tvEmbedded can bypass age restricted and obtain higher quality streams.
static const _defaultClient = InnertubeClients.tvEmbedded;
/// tvEmbedded can bypass age restricted and obtain higher quality streams,
/// but doesnt work with many vids, web is more stable and can also obtain higher quality streams.
/// On a better implementation, we would tv first and check result before using web, etc.
static const _defaultClient = InnertubeClients.web;
static const _defaultRequiresJSPlayer = true;

InnertubeClients get _usedClient => settings.youtube.innertubeClient ?? _defaultClient;
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/controller/youtube_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1193,7 +1193,7 @@ class _YTDownloadManager with PortsProvider<SendPort> {
'downloadStartRange': downloadStartRange,
'progressPort': progressPort.sendPort,
};
await initialize();
if (!isInitialized) await initialize();
await sendPort(p);
final res = await _downloadCompleters[filePath]?.future ?? false;
_onFileFinish(filePath, null);
Expand Down
17 changes: 10 additions & 7 deletions lib/youtube/pages/yt_playlist_subpage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,6 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
return await _playlist.basicInfo.fetchAllPlaylistAsYTIDs(showProgressSheet: true, playlistToFetch: _playlist);
}

PlaylistID get _getPlaylistID {
final plId = _playlist.basicInfo.id;
return PlaylistID(id: plId);
}

Future<bool> _fetch100Video({bool forceRequest = false}) async {
if (_isLoadingMoreItems.value) return false;
_isLoadingMoreItems.value = true;
Expand All @@ -460,8 +455,11 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
details: ExecuteDetails.forceRequest(),
);
} else {
String? plId;
if (currentPlaylist is YoutiPiePlaylistResult) plId = currentPlaylist.playlistId;
plId ??= currentPlaylist.basicInfo.id;
newPlaylist = await YoutubeInfoController.playlist.fetchPlaylist(
playlistId: currentPlaylist.basicInfo.id,
playlistId: plId,
details: ExecuteDetails.forceRequest(),
);
}
Expand Down Expand Up @@ -495,6 +493,8 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
String? description;
String uploaderTitleAndViews = '';
String? thumbnailUrl;
String? plId;

if (playlist is YoutiPiePlaylistResult) {
description = playlist.info.description;
final uploaderTitle = playlist.info.uploader?.title;
Expand All @@ -505,7 +505,10 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
if (viewsCountText != null) viewsCountText,
].join(' - ');
thumbnailUrl = playlist.info.thumbnails.pick()?.url;
plId = playlist.playlistId;
}
plId ??= playlist.basicInfo.id;
final plIdWrapper = PlaylistID(id: plId);
final firstID = playlist.items.firstOrNull?.id;
final hasMoreStreamsLeft = playlist.canFetchNext;
return AnimatedTheme(
Expand Down Expand Up @@ -713,7 +716,7 @@ class _YTHostedPlaylistSubpageState extends State<YTHostedPlaylistSubpage> with
thumbnailWidth: itemsThumbnailWidth,
isImageImportantInCache: false,
video: item,
playlistID: _getPlaylistID,
playlistID: plIdWrapper,
playlist: playlist,
index: index,
);
Expand Down
8 changes: 4 additions & 4 deletions lib/youtube/widgets/yt_playlist_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ class _YoutubePlaylistCardState extends State<YoutubePlaylistCard> {
super.dispose();
}

List<NamidaPopupItem> getMenuItems(PlaylistBasicInfo playlist) {
List<NamidaPopupItem> getMenuItems() {
if (_fetchTimer?.isActive == true || this.playlistToFetch == null) _forceFetch();

final playlistToFetch = this.playlistToFetch;
if (playlistToFetch == null) return [];
return playlist.getPopupMenuItems(
return widget.playlist.getPopupMenuItems(
playlistToFetch: playlistToFetch,
showProgressSheet: true,
displayPlay: !widget.playOnTap,
Expand All @@ -133,7 +133,7 @@ class _YoutubePlaylistCardState extends State<YoutubePlaylistCard> {
return NamidaPopupWrapper(
openOnTap: false,
openOnLongPress: true,
childrenDefault: () => getMenuItems(playlist),
childrenDefault: getMenuItems,
child: YoutubeCard(
thumbnailHeight: widget.thumbnailHeight,
thumbnailWidth: widget.thumbnailWidth,
Expand Down Expand Up @@ -178,7 +178,7 @@ class _YoutubePlaylistCardState extends State<YoutubePlaylistCard> {
},
),
],
menuChildrenDefault: () => getMenuItems(playlist),
menuChildrenDefault: getMenuItems,
),
);
}
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.6.1-beta+240725224
version: 3.6.3-beta+240725225

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

0 comments on commit 9f48569

Please sign in to comment.