-
-
Save elyeandre/71ca46600c3940024a0b3a9225ff595f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MyProvider with ChangeNotifier { | |
List<dynamic> responseBody; | |
String errMsg = ""; | |
//for movies | |
Future<void> getSub(id) async { | |
try { | |
HttpClient client = new HttpClient(); | |
client.userAgent = 'TemporaryUserAgent'; | |
HttpClientRequest request = await client.getUrl(Uri.parse( | |
"http://rest.opensubtitles.org/search/imdbid-$id/sublanguageid-$lang")); | |
HttpClientResponse response = await request.close(); | |
var result = new StringBuffer(); | |
await for (var contents in response.transform(Utf8Decoder())) { | |
result.write(contents); | |
} | |
responseBody = jsonDecode(result.toString()); | |
} on DioError catch (e) { | |
errMsg = e.toString(); | |
} | |
} | |
// for tv shows | |
Future<void> getTvSub(id, ep, se) async { | |
HttpClient client = new HttpClient(); | |
client.userAgent = 'obadasub'; | |
HttpClientRequest request = await client.getUrl(Uri.parse( | |
"https://rest.opensubtitles.org/search/episode-$ep/imdbid-$id/season-$se/sublanguageid-$lang")); | |
HttpClientResponse response = await request.close(); | |
var result = new StringBuffer(); | |
await for (var contents in response.transform(Utf8Decoder())) { | |
result.write(contents); | |
} | |
responseBody = jsonDecode(result.toString()); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment