Add select server on streaming but still buggy (WIP)

This commit is contained in:
Moe Poi ~ 2020-09-08 01:15:07 +07:00
parent d70ef47a41
commit 04732cc962
2 changed files with 49 additions and 1 deletions

View file

@ -58,6 +58,8 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
return Text(error.toString());
},
renderSuccess: ({data}) {
var currentServer = data['stream_url'][0];
var currentServerName = data['stream_name'][0];
return Center(
child: ListView(
children: [
@ -65,7 +67,7 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
height: 200,
child: Center(
child: InAppWebView(
initialUrl: data['stream_url'][0],
initialUrl: currentServer,
onWebViewCreated:
(InAppWebViewController controller) {
webView = controller;
@ -76,6 +78,44 @@ class _EpisodeDetailState extends State<EpisodeDetail> {
),
),
),
Card(
child: Row(
children: [
Flexible(
flex: 3,
child: Container(
alignment: Alignment.centerRight,
margin: EdgeInsets.all(10),
child: Text('Select Server', style: TextStyle(fontSize: 20),),
),
),
Flexible(
flex: 3,
child: Container(
alignment: Alignment.centerLeft,
margin: EdgeInsets.all(10),
child: DropdownButton(
value: currentServerName,
onChanged: (newValue){
setState(() {
int index = data['stream_name'].indexOf(newValue);
currentServer = data['stream_url'][index];
currentServerName = data['stream_name'][index];
});
},
items: data['stream_name'].map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
child: Text(value),
value: value,
);
}).toList(),
),
// child: Text('test'),
),
)
],
),
),
Card(
child: Container(
margin: EdgeInsets.all(10),

View file

@ -44,12 +44,16 @@ Future<dynamic> getNewRelease(String page) async {
Future<dynamic> getEpisodeDetail(String url) async {
try {
List<String> streamUrls = <String>[];
List<String> streamNames = <String>[];
List<String> downloadUrls = <String>[];
List<String> description = <String>[];
final response = await http.get(url);
var document = parse(response.body);
document.getElementsByTagName('iframe').forEach((x) {
streamUrls.add(x.attributes['data-src']);
});
document.getElementsByClassName('change-player').forEach((x) {
streamNames.add(x.text);
});
var downloadBox = document.getElementsByClassName('linkstv')[0];
downloadBox.getElementsByTagName('a').forEach((x) {
@ -63,6 +67,9 @@ Future<dynamic> getEpisodeDetail(String url) async {
contentBox.getElementsByTagName('p').forEach((x) {
description.add(x.text);
});
if (streamUrls.length != streamNames.length) {
streamNames = streamNames.sublist(0, streamUrls.length);
}
var rmv = title.split(' Episode ');
title = rmv[0].replaceAll('Sinopsis dari anime ', '');
final data = {
@ -70,6 +77,7 @@ Future<dynamic> getEpisodeDetail(String url) async {
'description': description.join('\n\n'),
'image': image.replaceAll(new RegExp(r'\/w(\d\d\d)\/'), '/original/'),
'detail_url': detailUrl,
'stream_name': streamNames,
'stream_url': streamUrls,
'download_url': downloadUrls
};