feat: Implement streaming handlers for live MPEG-TS proxy and VOD HLS transcoding via FFmpeg, and add a release build script.

This commit is contained in:
Michael committed 2025-12-16 07:39:33 +01:00
1 parent c7ba52b88d
commit 8128174ac3
26 files changed
+1529 -927

No files matched your search

+158 -104
View File
@@ -27,9 +27,8 @@ class LiveTVTab extends ConsumerStatefulWidget {
class _LiveTVTabState extends ConsumerState<LiveTVTab>
with AutomaticKeepAliveClientMixin {
String? _selectedCategory;
bool _isGridView = true;
final bool _isGridView = true;
final TextEditingController _searchController = TextEditingController();
bool _showFavoritesOnly = false;
String _searchQuery = '';
@@ -57,7 +56,8 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
Widget build(BuildContext context) {
super.build(context);
final channelsAsync = ref.watch(liveChannelsByPlaylistProvider(widget.playlist));
final channelsAsync =
ref.watch(liveChannelsByPlaylistProvider(widget.playlist));
final favorites = ref.watch(favoritesProvider);
final settings = ref.watch(iptvSettingsProvider);
@@ -65,30 +65,36 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
backgroundColor: Colors.transparent,
body: channelsAsync.when(
loading: () => const ThemedLoading(),
error: (e, s) => Center(child: Text('Error: $e', style: const TextStyle(color: Colors.white))),
error: (e, s) => Center(
child:
Text('Error: $e', style: const TextStyle(color: Colors.white))),
data: (groupedChannels) {
var categories = groupedChannels.keys.toList();
if (settings.liveTvKeywords.isNotEmpty) {
categories = categories.where((cat) => settings.matchesLiveTvFilter(cat)).toList();
}
categories.sort();
List<Channel> displayedChannels = [];
bool showingCategoryGrid = false;
if (_searchQuery.isNotEmpty) {
displayedChannels = groupedChannels.values.expand((l) => l)
.where((c) => c.name.toLowerCase().contains(_searchQuery))
.toList();
} else if (_showFavoritesOnly) {
displayedChannels = groupedChannels.values.expand((l) => l)
.where((c) => favorites.contains(c.streamId))
.toList();
} else if (_selectedCategory != null) {
displayedChannels = groupedChannels[_selectedCategory] ?? [];
} else {
showingCategoryGrid = true;
}
var categories = groupedChannels.keys.toList();
if (settings.liveTvKeywords.isNotEmpty) {
categories = categories
.where((cat) => settings.matchesLiveTvFilter(cat))
.toList();
}
categories.sort();
List<Channel> displayedChannels = [];
bool showingCategoryGrid = false;
if (_searchQuery.isNotEmpty) {
displayedChannels = groupedChannels.values
.expand((l) => l)
.where((c) => c.name.toLowerCase().contains(_searchQuery))
.toList();
} else if (_showFavoritesOnly) {
displayedChannels = groupedChannels.values
.expand((l) => l)
.where((c) => favorites.contains(c.streamId))
.toList();
} else if (_selectedCategory != null) {
displayedChannels = groupedChannels[_selectedCategory] ?? [];
} else {
showingCategoryGrid = true;
}
return Column(
children: [
@@ -98,16 +104,19 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
child: GlassContainer(
borderRadius: 16,
opacity: 0.6,
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
padding:
const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
child: Row(
children: [
if (_selectedCategory != null && _searchQuery.isEmpty && !_showFavoritesOnly) ...[
if (_selectedCategory != null &&
_searchQuery.isEmpty &&
!_showFavoritesOnly) ...[
TvFocusableCard(
onTap: () {
setState(() {
_selectedCategory = null;
_mainScrollController.jumpTo(0);
});
setState(() {
_selectedCategory = null;
_mainScrollController.jumpTo(0);
});
},
borderRadius: 50,
child: Container(
@@ -116,7 +125,8 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
color: Colors.white.withOpacity(0.1),
shape: BoxShape.circle,
),
child: const Icon(Icons.arrow_back, color: Colors.white),
child: const Icon(Icons.arrow_back,
color: Colors.white),
),
),
const SizedBox(width: 16),
@@ -124,9 +134,11 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
Expanded(
child: Text(
_searchQuery.isNotEmpty ? 'Search Results' :
_showFavoritesOnly ? 'Favorites' :
_selectedCategory ?? 'Live TV',
_searchQuery.isNotEmpty
? 'Search Results'
: _showFavoritesOnly
? 'Favorites'
: _selectedCategory ?? 'Live TV',
style: GoogleFonts.inter(
fontSize: 24,
fontWeight: FontWeight.w700,
@@ -136,7 +148,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
overflow: TextOverflow.ellipsis,
),
),
// Search Bar
Container(
width: 250,
@@ -151,37 +163,50 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
decoration: InputDecoration(
hintText: 'Search channels...',
hintStyle: GoogleFonts.inter(color: Colors.white54),
prefixIcon: const Icon(Icons.search, color: Colors.white54),
prefixIcon:
const Icon(Icons.search, color: Colors.white54),
border: InputBorder.none,
contentPadding: const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
suffixIcon: _searchQuery.isNotEmpty
? IconButton(icon: const Icon(Icons.clear, color: Colors.white), onPressed: _searchController.clear)
: null,
contentPadding: const EdgeInsets.symmetric(
horizontal: 16, vertical: 10),
suffixIcon: _searchQuery.isNotEmpty
? IconButton(
icon: const Icon(Icons.clear,
color: Colors.white),
onPressed: _searchController.clear)
: null,
),
),
),
const SizedBox(width: 12),
// Favorites Toggle
TvFocusableCard(
onTap: () {
setState(() {
_showFavoritesOnly = !_showFavoritesOnly;
if (_showFavoritesOnly) _searchController.clear();
_selectedCategory = null;
});
setState(() {
_showFavoritesOnly = !_showFavoritesOnly;
if (_showFavoritesOnly) _searchController.clear();
_selectedCategory = null;
});
},
borderRadius: 12,
child: Container(
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
color: _showFavoritesOnly ? AppColors.live.withOpacity(0.2) : Colors.white.withOpacity(0.1),
color: _showFavoritesOnly
? AppColors.live.withOpacity(0.2)
: Colors.white.withOpacity(0.1),
borderRadius: BorderRadius.circular(12),
border: _showFavoritesOnly ? Border.all(color: AppColors.live) : null,
border: _showFavoritesOnly
? Border.all(color: AppColors.live)
: null,
),
child: Icon(
_showFavoritesOnly ? Icons.favorite : Icons.favorite_border,
color: _showFavoritesOnly ? AppColors.live : Colors.white,
_showFavoritesOnly
? Icons.favorite
: Icons.favorite_border,
color: _showFavoritesOnly
? AppColors.live
: Colors.white,
),
),
),
@@ -199,11 +224,14 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.tv_off, size: 64, color: Colors.white.withOpacity(0.3)),
Icon(Icons.tv_off,
size: 64,
color: Colors.white.withOpacity(0.3)),
const SizedBox(height: 16),
Text(
'No channels found',
style: GoogleFonts.inter(color: Colors.white54, fontSize: 18),
style: GoogleFonts.inter(
color: Colors.white54, fontSize: 18),
),
],
),
@@ -218,7 +246,8 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
);
}
Widget _buildCategoryGrid(List<String> categories, Map<String, List<Channel>> groupedChannels) {
Widget _buildCategoryGrid(
List<String> categories, Map<String, List<Channel>> groupedChannels) {
final columns = ResponsiveLayout.value(
context,
mobile: 2,
@@ -239,7 +268,7 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
itemBuilder: (context, index) {
final category = categories[index];
final count = groupedChannels[category]?.length ?? 0;
return TvFocusableCard(
onTap: () {
setState(() {
@@ -271,7 +300,8 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.folder_copy_outlined, color: Colors.white.withOpacity(0.9), size: 32),
Icon(Icons.folder_copy_outlined,
color: Colors.white.withOpacity(0.9), size: 32),
const SizedBox(height: 12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
@@ -290,7 +320,8 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
const SizedBox(height: 4),
Text(
'$count Channels',
style: GoogleFonts.inter(fontSize: 13, color: Colors.white54),
style: GoogleFonts.inter(
fontSize: 13, color: Colors.white54),
),
],
),
@@ -337,74 +368,97 @@ class _LiveTVTabState extends ConsumerState<LiveTVTab>
// Icon Area
Expanded(
child: Container(
decoration: BoxDecoration(
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: const BorderRadius.vertical(top: Radius.circular(12)),
borderRadius:
BorderRadius.vertical(top: Radius.circular(12)),
),
padding: const EdgeInsets.all(16),
child: Center(
child: channel.streamIcon.isNotEmpty
? Image.network(
_getProxiedIconUrl(channel.streamIcon)!,
errorBuilder: (_,__,___) => const Icon(Icons.tv, color: Colors.grey, size: 40),
)
: Text(
channel.name.characters.first.toUpperCase(),
style: GoogleFonts.inter(fontSize: 40, fontWeight: FontWeight.bold, color: Colors.black12),
),
child: channel.streamIcon.isNotEmpty
? Image.network(
_getProxiedIconUrl(channel.streamIcon)!,
errorBuilder: (_, __, ___) => const Icon(Icons.tv,
color: Colors.grey, size: 40),
)
: Text(
channel.name.characters.first.toUpperCase(),
style: GoogleFonts.inter(
fontSize: 40,
fontWeight: FontWeight.bold,
color: Colors.black12),
),
),
),
),
// Footer
Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
padding:
const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
color: Colors.black54,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
channel.name,
style: GoogleFonts.inter(color: Colors.white, fontSize: 13, fontWeight: FontWeight.w500),
style: GoogleFonts.inter(
color: Colors.white,
fontSize: 13,
fontWeight: FontWeight.w500),
maxLines: 1,
overflow: TextOverflow.ellipsis,
),
const SizedBox(height: 4),
Consumer(
builder: (context, ref, _) {
final epgAsync = ref.watch(epgByPlaylistProvider(
EpgRequestKey(playlist: widget.playlist, streamId: channel.streamId)
));
return epgAsync.when(
data: (epgList) {
if (epgList.isEmpty) {
return Text('No Info', style: GoogleFonts.inter(color: Colors.white54, fontSize: 10));
}
final now = DateTime.now();
final currentProgram = epgList.firstWhere(
(entry) {
try {
final start = DateTime.parse(entry.start);
final end = DateTime.parse(entry.end);
return now.isAfter(start) && now.isBefore(end);
} catch (e) {
return false;
}
},
orElse: () => epgList.first,
);
final epgAsync = ref.watch(
epgByPlaylistProvider(
EpgRequestKey(
playlist: widget.playlist,
streamId: channel.streamId),
),
);
return Text(
currentProgram.title,
style: GoogleFonts.inter(color: const Color(0xFFFFD700), fontSize: 10, fontWeight: FontWeight.w600),
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
},
loading: () => Text('...', style: GoogleFonts.inter(color: Colors.white24, fontSize: 10)),
error: (_,__) => Text('Err', style: GoogleFonts.inter(color: Colors.red, fontSize: 10)),
);
}
return epgAsync.when(
data: (epgList) {
if (epgList.isEmpty) {
return Text('No Info',
style: GoogleFonts.inter(
color: Colors.white54, fontSize: 10));
}
final now = DateTime.now();
final currentProgram = epgList.firstWhere(
(entry) {
try {
final start = DateTime.parse(entry.start);
final end = DateTime.parse(entry.end);
return now.isAfter(start) &&
now.isBefore(end);
} catch (e) {
return false;
}
},
orElse: () => epgList.first,
);
return Text(
currentProgram.title,
style: GoogleFonts.inter(
color: const Color(0xFFFFD700),
fontSize: 10,
fontWeight: FontWeight.w600),
maxLines: 1,
overflow: TextOverflow.ellipsis,
);
},
loading: () => Text('...',
style: GoogleFonts.inter(
color: Colors.white24, fontSize: 10)),
error: (_, __) => Text('Err',
style: GoogleFonts.inter(
color: Colors.red, fontSize: 10)),
);
},
),
],
),