Skip to content

Instantly share code, notes, and snippets.

@elyeandre
Forked from obadajasm/getSub
Created December 18, 2023 06:49
Show Gist options
  • Save elyeandre/71ca46600c3940024a0b3a9225ff595f to your computer and use it in GitHub Desktop.
Save elyeandre/71ca46600c3940024a0b3a9225ff595f to your computer and use it in GitHub Desktop.
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