Skip to content

Commit

Permalink
feat: "go to channel" icon in track dialog
Browse files Browse the repository at this point in the history
when track has youtube id and channel id
  • Loading branch information
MSOB7YY committed Jul 5, 2024
1 parent f0cd073 commit dda4ca6
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
18 changes: 17 additions & 1 deletion lib/ui/dialogs/general_popup_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ import 'package:namida/ui/widgets/custom_widgets.dart';
import 'package:namida/ui/widgets/library/multi_artwork_container.dart';
import 'package:namida/ui/widgets/settings/extra_settings.dart';
import 'package:namida/youtube/class/youtube_id.dart';
import 'package:namida/youtube/controller/youtube_info_controller.dart';
import 'package:namida/youtube/pages/yt_channel_subpage.dart';

Future<void> showGeneralPopupDialog(
List<Track> tracks,
Expand Down Expand Up @@ -104,7 +106,9 @@ Future<void> showGeneralPopupDialog(
final List<String> availableArtists = tracks.mappedUniquedList((e) => e.toTrackExt().artistsList);
final List<Folder> availableFolders = tracks.mappedUniqued((e) => e.folder);

final Iterable<YoutubeID> availableYoutubeIDs = tracks.map((e) => YoutubeID(id: e.youtubeID, playlistID: null)).where((element) => element.id != '');
final Iterable<YoutubeID> availableYoutubeIDs = tracks.map((e) => YoutubeID(id: e.youtubeID, playlistID: null)).where((element) => element.id.isNotEmpty);
final String? firstVideolId = availableYoutubeIDs.firstOrNull?.id;
final String? firstVideoChannelId = firstVideolId == null ? null : YoutubeInfoController.utils.getVideoChannelID(firstVideolId);

final numberOfRepeats = 1.obso;
final isLoadingFilesToShare = false.obso;
Expand Down Expand Up @@ -1114,6 +1118,18 @@ Future<void> showGeneralPopupDialog(
NamidaNavigator.inst.closeDialog();
Player.inst.playOrPause(0, availableYoutubeIDs, QueueSource.others);
},
trailing: isSingle && firstVideoChannelId != null
? IconButton(
tooltip: lang.GO_TO_CHANNEL,
icon: Icon(
Broken.user,
size: 20.0,
color: iconColor,
),
iconSize: 20.0,
onPressed: () => NamidaNavigator.inst.navigateTo(YTChannelSubpage(channelID: firstVideoChannelId)),
)
: null,
),

if (removeQueueTile != null) removeQueueTile,
Expand Down
31 changes: 19 additions & 12 deletions lib/youtube/controller/info_controllers/yt_various_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ class _YoutubeInfoUtils {
}

String? getVideoName(String videoId, {bool checkFromStorage = true /* am sorry every follow me */}) {
String? name = tempVideoInfosFromStreams[videoId]?.title ?? tempBackupVideoInfo[videoId]?.title;
String? name = tempVideoInfosFromStreams[videoId]?.title.nullifyEmpty() ?? tempBackupVideoInfo[videoId]?.title.nullifyEmpty();
if (name != null || checkFromStorage == false) return name;
return getStreamInfoSync(videoId)?.title ??
_getVideoStreamResultSync(videoId)?.info?.title ?? //
_getVideoPageResultSync(videoId)?.videoInfo?.title;
return getStreamInfoSync(videoId)?.title.nullifyEmpty() ??
_getVideoStreamResultSync(videoId)?.info?.title.nullifyEmpty() ?? //
_getVideoPageResultSync(videoId)?.videoInfo?.title.nullifyEmpty();
}

String? getVideoChannelName(String videoId, {bool checkFromStorage = true}) {
String? name = tempVideoInfosFromStreams[videoId]?.channelName ?? tempBackupVideoInfo[videoId]?.channel;
String? name = tempVideoInfosFromStreams[videoId]?.channelName?.nullifyEmpty() ?? tempBackupVideoInfo[videoId]?.channel.nullifyEmpty();
if (name != null || checkFromStorage == false) return name;
return getStreamInfoSync(videoId)?.channelName ??
_getVideoStreamResultSync(videoId)?.info?.channelName ?? //
_getVideoPageResultSync(videoId)?.channelInfo?.title;
return getStreamInfoSync(videoId)?.channelName?.nullifyEmpty() ??
_getVideoStreamResultSync(videoId)?.info?.channelName?.nullifyEmpty() ?? //
_getVideoPageResultSync(videoId)?.channelInfo?.title.nullifyEmpty();
}

String? getVideoChannelID(String videoId) {
return tempVideoInfosFromStreams[videoId]?.channelId ??
getStreamInfoSync(videoId)?.channelId ??
_getVideoStreamResultSync(videoId)?.info?.channelId ?? //
_getVideoPageResultSync(videoId)?.channelInfo?.id;
return tempVideoInfosFromStreams[videoId]?.channelId?.nullifyEmpty() ??
getStreamInfoSync(videoId)?.channelId?.nullifyEmpty() ??
_getVideoStreamResultSync(videoId)?.info?.channelId?.nullifyEmpty() ?? //
_getVideoPageResultSync(videoId)?.channelInfo?.id.nullifyEmpty();
}

DateTime? getVideoReleaseDate(String videoId) {
Expand All @@ -84,3 +84,10 @@ class _YoutubeInfoUtils {
_getVideoStreamResultSync(videoId)?.info?.durSeconds;
}
}

extension _StringChecker on String {
String? nullifyEmpty() {
if (isEmpty) return null;
return this;
}
}
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: 2.9.65-beta+240705126
version: 2.9.7-beta+240705185

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

0 comments on commit dda4ca6

Please sign in to comment.