mirror of
https://github.com/madari-media/madari-oss.git
synced 2026-05-10 03:00:49 +00:00
Formatting and comments removal
This commit is contained in:
parent
cce3c2b8e4
commit
15bf4205a3
3 changed files with 88 additions and 89 deletions
|
|
@ -56,10 +56,9 @@ class _StremioItemSeasonSelectorState extends State<StremioItemSeasonSelector>
|
|||
int initialSeason = getSelectedSeason();
|
||||
|
||||
if (seasons.contains(initialSeason)) {
|
||||
// Check if initialSeason is in seasons
|
||||
selectedSeason = initialSeason;
|
||||
} else if (seasons.isNotEmpty) {
|
||||
selectedSeason = seasons.first; // Or any other default if not found
|
||||
selectedSeason = seasons.first;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -67,47 +66,48 @@ class _StremioItemSeasonSelectorState extends State<StremioItemSeasonSelector>
|
|||
getWatchedHistory();
|
||||
}
|
||||
|
||||
getWatchedHistory() async {
|
||||
final traktService = TraktService.instance;
|
||||
try {
|
||||
final result =
|
||||
await traktService!.getWatchedShowsWithEpisodes(widget.meta);
|
||||
watchedEpisodesBySeason.clear();
|
||||
for (final show in result) {
|
||||
if (show.episodes != null) {
|
||||
for (final episode in show.episodes!) {
|
||||
if (!watchedEpisodesBySeason.containsKey(episode.season)) {
|
||||
watchedEpisodesBySeason[episode.season] = {};
|
||||
getWatchedHistory() async {
|
||||
final traktService = TraktService.instance;
|
||||
try {
|
||||
final result =
|
||||
await traktService!.getWatchedShowsWithEpisodes(widget.meta);
|
||||
watchedEpisodesBySeason.clear();
|
||||
for (final show in result) {
|
||||
if (show.episodes != null) {
|
||||
for (final episode in show.episodes!) {
|
||||
if (!watchedEpisodesBySeason.containsKey(episode.season)) {
|
||||
watchedEpisodesBySeason[episode.season] = {};
|
||||
}
|
||||
watchedEpisodesBySeason[episode.season]!.add(episode.episode);
|
||||
}
|
||||
watchedEpisodesBySeason[episode.season]!.add(episode.episode);
|
||||
} else {
|
||||
_logger.info("No episodes found for ${show.title}");
|
||||
}
|
||||
} else {
|
||||
//print("No episodes found for ${show.title}");
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
return;
|
||||
} catch (e, stack) {
|
||||
print("Error fetching Trakt data: $e");
|
||||
print("Stack Trace: $stack");
|
||||
}
|
||||
}
|
||||
|
||||
setState(() {});
|
||||
return;
|
||||
} catch (e, stack) {
|
||||
print("Error fetching Trakt data: $e");
|
||||
print("Stack Trace: $stack");
|
||||
bool isEpisodeWatched(int season, int episode) {
|
||||
return watchedEpisodesBySeason.containsKey(season) &&
|
||||
watchedEpisodesBySeason[season]!.contains(episode);
|
||||
}
|
||||
}
|
||||
bool isEpisodeWatched(int season, int episode) {
|
||||
return watchedEpisodesBySeason.containsKey(season) &&
|
||||
watchedEpisodesBySeason[season]!.contains(episode);
|
||||
}
|
||||
|
||||
bool isSeasonWatched(int season) {
|
||||
if (!watchedEpisodesBySeason.containsKey(season)) {
|
||||
return false; // No episodes watched in this season
|
||||
bool isSeasonWatched(int season) {
|
||||
if (!watchedEpisodesBySeason.containsKey(season)) {
|
||||
return false;
|
||||
}
|
||||
if (seasonMap.containsKey(season)) {
|
||||
return watchedEpisodesBySeason[season]!.length ==
|
||||
seasonMap[season]!.length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (seasonMap.containsKey(season)) {
|
||||
return watchedEpisodesBySeason[season]!.length ==
|
||||
seasonMap[season]!.length;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
int getSelectedSeason() {
|
||||
return widget.meta.currentVideo?.season ??
|
||||
|
|
@ -120,19 +120,15 @@ bool isSeasonWatched(int season) {
|
|||
|
||||
getWatchHistory() async {
|
||||
final traktService = TraktService.instance;
|
||||
|
||||
try {
|
||||
if (TraktService.isEnabled()) {
|
||||
final result = await traktService!.getProgress(
|
||||
widget.meta,
|
||||
bypassCache: false,
|
||||
);
|
||||
|
||||
setState(() {
|
||||
meta = result;
|
||||
});
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
} catch (e, stack) {
|
||||
|
|
@ -140,7 +136,6 @@ bool isSeasonWatched(int season) {
|
|||
print(stack);
|
||||
print("Unable to get trakt progress");
|
||||
}
|
||||
|
||||
final docs = await zeeeWatchHistory!.getItemWatchHistory(
|
||||
ids: widget.meta.videos!.map((item) {
|
||||
return WatchHistoryGetRequest(
|
||||
|
|
@ -154,7 +149,6 @@ bool isSeasonWatched(int season) {
|
|||
for (var item in docs) {
|
||||
_progress[item.id] = item.progress.toDouble();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
@ -270,11 +264,14 @@ bool isSeasonWatched(int season) {
|
|||
child: DropdownButtonFormField<int>(
|
||||
isExpanded: true,
|
||||
decoration: InputDecoration(
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 2, vertical: 8),
|
||||
contentPadding: const EdgeInsets.symmetric(
|
||||
horizontal: 2, vertical: 8),
|
||||
filled: true,
|
||||
fillColor: Theme.of(context).colorScheme.surface.withOpacity(0.3),
|
||||
fillColor: Theme.of(context)
|
||||
.colorScheme
|
||||
.surface
|
||||
.withOpacity(0.3),
|
||||
),
|
||||
|
||||
value: selectedSeason,
|
||||
onChanged: (newValue) {
|
||||
setState(() {
|
||||
|
|
@ -295,7 +292,6 @@ bool isSeasonWatched(int season) {
|
|||
Icons.check_circle,
|
||||
color: Theme.of(context).colorScheme.primary,
|
||||
size: 16,
|
||||
|
||||
)
|
||||
]
|
||||
],
|
||||
|
|
@ -316,7 +312,7 @@ bool isSeasonWatched(int season) {
|
|||
),
|
||||
sliver: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
(context, index) {
|
||||
final currentSeason = selectedSeason;
|
||||
if (currentSeason == null ||
|
||||
!seasonMap.containsKey(currentSeason)) {
|
||||
|
|
@ -328,11 +324,11 @@ bool isSeasonWatched(int season) {
|
|||
final videoIndex = meta.videos?.indexOf(episode);
|
||||
|
||||
final progress = ((!TraktService.isEnabled()
|
||||
? (_progress[episode.id] ?? 0) / 100
|
||||
: videoIndex != -1
|
||||
? (meta.videos![videoIndex!].progress)
|
||||
: 0.toDouble()) ??
|
||||
0) /
|
||||
? (_progress[episode.id] ?? 0) / 100
|
||||
: videoIndex != -1
|
||||
? (meta.videos![videoIndex!].progress)
|
||||
: 0.toDouble()) ??
|
||||
0) /
|
||||
100;
|
||||
|
||||
return InkWell(
|
||||
|
|
@ -359,37 +355,37 @@ bool isSeasonWatched(int season) {
|
|||
children: [
|
||||
Container(
|
||||
child: episode.thumbnail != null &&
|
||||
episode.thumbnail!.isNotEmpty
|
||||
episode.thumbnail!.isNotEmpty
|
||||
? Image.network(
|
||||
episode.thumbnail!,
|
||||
width: 140,
|
||||
height: 90,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) {
|
||||
return Container(
|
||||
width: 140,
|
||||
height: 90,
|
||||
color: colorScheme
|
||||
.surfaceContainerHighest,
|
||||
child: Icon(
|
||||
Icons.movie,
|
||||
color:
|
||||
colorScheme.onSurfaceVariant,
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
episode.thumbnail!,
|
||||
width: 140,
|
||||
height: 90,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder:
|
||||
(context, error, stackTrace) {
|
||||
return Container(
|
||||
width: 140,
|
||||
height: 90,
|
||||
color: colorScheme
|
||||
.surfaceContainerHighest,
|
||||
child: Icon(
|
||||
Icons.movie,
|
||||
color:
|
||||
colorScheme.onSurfaceVariant,
|
||||
),
|
||||
);
|
||||
},
|
||||
)
|
||||
: Container(
|
||||
width: 140,
|
||||
height: 90,
|
||||
color:
|
||||
colorScheme.surfaceContainerHighest,
|
||||
child: Icon(
|
||||
Icons.movie,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
width: 140,
|
||||
height: 90,
|
||||
color:
|
||||
colorScheme.surfaceContainerHighest,
|
||||
child: Icon(
|
||||
Icons.movie,
|
||||
color: colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
Positioned(
|
||||
top: 0,
|
||||
|
|
@ -439,7 +435,7 @@ bool isSeasonWatched(int season) {
|
|||
.fontSize,
|
||||
color: Theme.of(context)
|
||||
.colorScheme
|
||||
.primary, // Use primary color from theme
|
||||
.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
|
@ -503,7 +499,7 @@ bool isSeasonWatched(int season) {
|
|||
);
|
||||
},
|
||||
childCount: selectedSeason != null &&
|
||||
seasonMap.containsKey(selectedSeason!)
|
||||
seasonMap.containsKey(selectedSeason!)
|
||||
? seasonMap[selectedSeason!]!.length
|
||||
: 0,
|
||||
),
|
||||
|
|
|
|||
|
|
@ -1079,16 +1079,16 @@ class TraktService {
|
|||
|
||||
return meta;
|
||||
}
|
||||
|
||||
Future<List<TraktShowWatched>> getWatchedShowsWithEpisodes(Meta meta) async {
|
||||
if (!isEnabled()) {
|
||||
_logger.info('Trakt integration is not enabled');
|
||||
return [];
|
||||
}
|
||||
if (meta.type == "series" ) {
|
||||
if (meta.type == "series") {
|
||||
final watchedShows = await getWatchedShows();
|
||||
for (final show in watchedShows) {
|
||||
if(show.ids.imdb==meta.imdbId) {
|
||||
// await Future.delayed(const Duration(seconds: 5));
|
||||
if (show.ids.imdb == meta.imdbId) {
|
||||
show.episodes = await _getWatchedEpisodes(show.ids.trakt);
|
||||
}
|
||||
}
|
||||
|
|
@ -1096,6 +1096,7 @@ class TraktService {
|
|||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
Future<List<TraktShowWatched>> getWatchedShows() async {
|
||||
if (!isEnabled()) {
|
||||
_logger.info('Trakt integration is not enabled');
|
||||
|
|
@ -1114,11 +1115,12 @@ class TraktService {
|
|||
title: item["show"]["title"],
|
||||
seasons: item["seasons"],
|
||||
ids: TraktIds.fromJson(item["show"]["ids"]),
|
||||
lastWatchedAt: item["last_watched_at"] != null ? DateTime.parse(item["last_watched_at"]) : null,
|
||||
lastWatchedAt: item["last_watched_at"] != null
|
||||
? DateTime.parse(item["last_watched_at"])
|
||||
: null,
|
||||
plays: item["plays"],
|
||||
),
|
||||
);
|
||||
|
||||
} catch (e, stack) {
|
||||
_logger.warning('Error parsing watched show: $e\n$stack item: $item');
|
||||
}
|
||||
|
|
@ -1129,6 +1131,7 @@ class TraktService {
|
|||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
Future<List<TraktEpisodeWatched>> _getWatchedEpisodes(int? traktId) async {
|
||||
if (traktId == null) return [];
|
||||
int page = 1;
|
||||
|
|
@ -1140,7 +1143,7 @@ class TraktService {
|
|||
);
|
||||
final List<TraktEpisodeWatched> episodes = [];
|
||||
for (final item in body) {
|
||||
if (item['episode'] != null ) {
|
||||
if (item['episode'] != null) {
|
||||
episodes.add(
|
||||
TraktEpisodeWatched(
|
||||
season: item['episode']['season'],
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class TraktShowWatched {
|
|||
final TraktIds ids;
|
||||
final DateTime? lastWatchedAt;
|
||||
final int plays;
|
||||
List<TraktEpisodeWatched>? episodes; // Add episodes list
|
||||
List<TraktEpisodeWatched>? episodes;
|
||||
|
||||
TraktShowWatched({
|
||||
required this.title,
|
||||
|
|
|
|||
Loading…
Reference in a new issue