Skip to content

Commit

Permalink
chore: various tweaks n fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MSOB7YY committed Jul 13, 2024
1 parent 5b2d098 commit 6ac49c7
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 45 deletions.
11 changes: 7 additions & 4 deletions lib/base/audio_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
if (newStreams != null) YoutubeInfoController.current.currentYTStreams.value = newStreams;
VideoStream? sameStream = newStreams?.videoStreams.firstWhereEff((e) => e.itag == stream.itag);
if (sameStream == null && newStreams != null) {
YoutubeController.inst.getPreferredStreamQuality(newStreams.videoStreams, preferIncludeWebm: false);
sameStream = YoutubeController.inst.getPreferredStreamQuality(newStreams.videoStreams, preferIncludeWebm: false);
}
final sameStreamUrl = sameStream?.buildUrl();

Expand Down Expand Up @@ -884,7 +884,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {

Duration? duration = streamsResult?.audioStreams.firstOrNull?.duration;
_ytNotificationVideoInfo = streamsResult?.info;
_ytNotificationVideoThumbnail = item.getThumbnailSync();
_ytNotificationVideoThumbnail = item.getThumbnailSync(temp: false);

bool checkInterrupted({bool refreshNoti = true}) {
final curr = currentItem.value;
Expand Down Expand Up @@ -922,7 +922,10 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
onInfoOrThumbObtained(info: _ytNotificationVideoInfo, thumbnail: _ytNotificationVideoThumbnail);

if (_ytNotificationVideoThumbnail == null) {
ThumbnailManager.inst.getYoutubeThumbnailAndCache(id: item.id).then((thumbFile) => onInfoOrThumbObtained(thumbnail: thumbFile));
ThumbnailManager.inst.getYoutubeThumbnailAndCache(id: item.id).then((thumbFile) {
thumbFile ??= item.getThumbnailSync(temp: true);
if (thumbFile != null) onInfoOrThumbObtained(thumbnail: thumbFile);
});
}

Future<void> plsplsplsPlay(bool wasPlayingFromCache, bool sourceChanged) async {
Expand Down Expand Up @@ -1050,7 +1053,7 @@ class NamidaAudioVideoHandler<Q extends Playable> extends BasicAudioHandler<Q> {
final videoStreams = streamsResult?.videoStreams ?? [];

if (audiostreams.isEmpty) {
snackyy(message: 'Error playing video, empty audio streams', top: false, isError: true);
if (!okaySetFromCache()) snackyy(message: 'Error playing video, empty audio streams', top: false, isError: true);
return;
}

Expand Down
5 changes: 3 additions & 2 deletions lib/controller/navigator_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ class NamidaNavigator {
}

/// Use [dialogBuilder] in case you want to acess the theme generated by [colorScheme].
Future<void> navigateDialog({
Future<T?> navigateDialog<T>({
final Widget? dialog,
final Widget Function(ThemeData theme)? dialogBuilder,
final int durationInMs = 300,
Expand Down Expand Up @@ -306,7 +306,7 @@ class NamidaNavigator {

final theme = AppThemes.inst.getAppTheme(colorScheme, null, lighterDialogColor);

await _rootNav.currentState?.pushPage(
final res = await _rootNav.currentState?.pushPage<T>(
WillPopScope(
onWillPop: onWillPop,
child: TapDetector(
Expand Down Expand Up @@ -337,6 +337,7 @@ class NamidaNavigator {
onDisposing.executeAfterDelay(durationMS: durationInMs * 2);
}
_printDialogs();
return res;
}

Future<void> closeDialog([int count = 1]) async {
Expand Down
7 changes: 2 additions & 5 deletions lib/controller/storage_cache_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -603,14 +603,11 @@ class _ImageTrimmer {
try {
element.deleteSync();
i++;
imagesLength--;
continue;
} catch (_) {}
}
// if not continued safely, i-- indicating that we still need to delete more
i--;
// i--; // this made things non-safe
imagesLength--;
if (imagesLength <= 0) break; // just to be safe that i-- doesnt mess things up
if (imagesLength <= 0) break; // to be safe that i++ wasnt called enough.
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/artwork.dart
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class _ArtworkWidgetState extends State<ArtworkWidget> with LoadingItemsDelayMix
}) {
final icon = Icon(
widget.displayIcon ? widget.icon : null,
size: widget.iconSize ?? widget.thumbnailSize / 2,
size: widget.iconSize ?? widget.thumbnailSize * 0.5,
);
return Container(
key: key,
Expand Down
4 changes: 2 additions & 2 deletions lib/youtube/class/youtube_id.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ class YoutubeID implements Playable, ItemWithDate {
}

extension YoutubeIDUtils on YoutubeID {
File? getThumbnailSync() {
return ThumbnailManager.inst.getYoutubeThumbnailFromCacheSync(id: id);
File? getThumbnailSync({required bool temp}) {
return ThumbnailManager.inst.getYoutubeThumbnailFromCacheSync(id: id, isTemp: temp);
}
}

Expand Down
3 changes: 2 additions & 1 deletion lib/youtube/controller/youtube_controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ class YoutubeController {
await _writeTaskGroupToStorage(groupName: groupName);
}

VideoStream getPreferredStreamQuality(List<VideoStream> streams, {List<String> qualities = const [], bool preferIncludeWebm = false}) {
VideoStream? getPreferredStreamQuality(List<VideoStream> streams, {List<String> qualities = const [], bool preferIncludeWebm = false}) {
if (streams.isEmpty) return null;
final preferredQualities = (qualities.isNotEmpty ? qualities : settings.youtubeVideoQualities.value).map((element) => element.settingLabeltoVideoLabel());
VideoStream? plsLoop(bool webm) {
for (int i = 0; i < streams.length; i++) {
Expand Down
29 changes: 26 additions & 3 deletions lib/youtube/pages/yt_channels_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'package:youtipie/youtipie.dart';
import 'package:namida/base/pull_to_refresh.dart';
import 'package:namida/base/youtube_channel_controller.dart';
import 'package:namida/class/route.dart';
import 'package:namida/controller/connectivity.dart';
import 'package:namida/controller/file_browser.dart';
import 'package:namida/controller/navigator_controller.dart';
import 'package:namida/core/dimensions.dart';
Expand Down Expand Up @@ -96,8 +97,22 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
}
}

bool get _hasConnection => ConnectivityController.inst.hasConnection;
void _showNetworkError() {
snackyy(
title: lang.ERROR,
message: lang.NO_NETWORK_AVAILABLE_TO_FETCH_DATA,
isError: true,
top: false,
);
}

/// TODO(youtipie): might be faster using rss feed, but limited to 15 vid.
Future<void> _fetchAllChannelsStreams({required bool forceRequest}) async {
if (!_hasConnection) {
_showNetworkError();
return;
}
setState(() {
isLoadingInitialStreams = true;
_allStreamsList = [];
Expand Down Expand Up @@ -132,7 +147,16 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
_allChannelsStreamsProgress.value = i / idsLength;
final channelPage = await YoutubeInfoController.channel.fetchChannelInfo(channelId: channelID, details: null);
if (channelPage == null) {
if (!_hasConnection) {
await Future.delayed(const Duration(seconds: 7));
if (!_hasConnection) {
_showNetworkError();
break;
}
}

if (pageFetchErrors < 3) {
pageFetchErrors++;
reportError('failed to fetch channel page for $channelID');
continue;
} else {
Expand All @@ -158,13 +182,12 @@ class _YoutubeChannelsPageState extends YoutubeChannelController<YoutubeChannels
}
printy('p: $i / $idsLength = ${_allChannelsStreamsProgress.value} =>> ${videosPage.length} videos');
if (channel != null) {
_allChannelsStreamsProgress.value = 0.0;
_allChannelsStreamsLoading.value = false;
return;
break;
}
YoutubeSubscriptionsController.inst.refreshLastFetchedTime(channelID, saveToStorage: false);
streams.addAll(videosPage.items);
}

YoutubeSubscriptionsController.inst.sortByLastFetched();
_allChannelsStreamsProgress.value = 0.0;
_allChannelsStreamsLoading.value = false;
Expand Down
1 change: 1 addition & 0 deletions lib/youtube/pages/yt_search_results_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ class YoutubeSearchResultsPageState extends State<YoutubeSearchResultsPage> with
thumbnailHeight: thumbnailHeightLocal,
thumbnailWidth: thumbnailWidthLocal,
showThirdLine: false,
dateInsteadOfChannel: true,
isImageImportantInCache: false,
video: item,
playlistID: null,
Expand Down
6 changes: 4 additions & 2 deletions lib/youtube/widgets/yt_description_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,13 @@ class YoutubeDescriptionWidgetManager {
if (surroundWithBG) {
Widget child = Text(sw.text);

double hmargin = 0.0;
double vpadding = 2.0;
double hpadding = 4.0;
double br = 4.0;

if (_latestAttachment != null) {
hmargin += 4.0;
vpadding += 2.0;
hpadding += 2.0;
br += 4.0;
Expand Down Expand Up @@ -182,9 +184,9 @@ class YoutubeDescriptionWidgetManager {
);
}

if (addVMargin) {
if (addVMargin || hmargin > 0) {
child = Padding(
padding: const EdgeInsets.symmetric(vertical: 2.0),
padding: EdgeInsets.symmetric(vertical: addVMargin ? 2.0 : 0, horizontal: hmargin),
child: child,
);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/youtube/widgets/yt_thumbnail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class _YoutubeThumbnailState extends State<YoutubeThumbnail> with LoadingItemsDe
thumbnailSize: widget.width,
boxShadow: widget.boxShadow,
icon: _typeToIcon[widget.type] ?? Broken.musicnote,
iconSize: widget.iconSize ?? (widget.customUrl != null ? null : widget.width * 0.3),
iconSize: widget.iconSize ?? widget.width * 0.3,
forceSquared: widget.forceSquared,
// cacheHeight: (widget.height?.round() ?? widget.width.round()) ~/ 1.2,
onTopWidgets: [
Expand Down
62 changes: 43 additions & 19 deletions lib/youtube/widgets/yt_video_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -264,25 +264,49 @@ class YoutubeShortVideoTallCard extends StatelessWidget {
bottom: 0,
left: 0,
child: Padding(
padding: const EdgeInsets.all(2.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: context.textTheme.displayMedium?.copyWith(fontSize: 12.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
viewsCountText,
style: context.textTheme.displaySmall?.copyWith(fontSize: 11.0),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
padding: const EdgeInsets.symmetric(horizontal: 4.0, vertical: 4.0),
child: SizedBox(
width: thumbnailWidth,
height: thumbnailHeight,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
mainAxisSize: MainAxisSize.min,
children: [
Text(
title,
style: context.textTheme.displayMedium?.copyWith(
fontSize: 12.0,
color: Colors.white70,
shadows: [
const BoxShadow(
spreadRadius: 1.0,
blurRadius: 12.0,
color: Colors.black38,
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
Text(
viewsCountText,
style: context.textTheme.displaySmall?.copyWith(
fontSize: 11.0,
color: Colors.white60,
shadows: [
const BoxShadow(
spreadRadius: 1.0,
blurRadius: 12.0,
color: Colors.black38,
),
],
),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
],
),
),
),
),
Expand Down
18 changes: 14 additions & 4 deletions lib/youtube/youtube_miniplayer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -310,10 +310,14 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
String? uploadDate;
String? uploadDateAgo;

final parsedDate = videoInfoStream?.publishedAt.date ?? videoInfoStream?.publishDate.date; // videoInfo?.publishedAt.date aint no way near accurate

DateTime? parsedDate = videoInfoStream?.publishedAt.date ?? videoInfoStream?.publishDate.date; // videoInfo?.publishedAt.date aint no way near accurate
bool accurateDate = true;
if (parsedDate == null) {
parsedDate = videoInfo?.publishedAt.date;
accurateDate = false;
}
if (parsedDate != null) {
uploadDate = parsedDate.millisecondsSinceEpoch.dateFormattedOriginal;
if (accurateDate) uploadDate = parsedDate.millisecondsSinceEpoch.dateFormattedOriginal;
uploadDateAgo = Jiffy.parseFromDateTime(parsedDate).fromNow();
} else {
// uploadDateAgo = videoInfo?.publishedFromText; // warcrime
Expand Down Expand Up @@ -832,7 +836,13 @@ class YoutubeMiniPlayerState extends State<YoutubeMiniPlayer> {
),
),
const SizedBox(width: 12.0),
YTSubscribeButton(channelID: channelID),
YTSubscribeButton(
channelID: channelID,
listenable: YoutubeInfoController.current.currentVideoPage,
retrieveInfo: () => YoutubeInfoController.current.currentVideoPage.value?.channelInfo,
mainPage: () => YoutubeInfoController.current.currentVideoPage.value,
mainChannelInfo: null,
),
const SizedBox(width: 20.0),
],
),
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.2.2-beta+240713184
version: 3.2.3-beta+240713186

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

0 comments on commit 6ac49c7

Please sign in to comment.