From 90ff41d40d1566484e03cd5310b04264d14b1ba3 Mon Sep 17 00:00:00 2001 From: gopi2401 Date: Tue, 7 Nov 2023 20:53:31 +0530 Subject: [PATCH] Add: stories --- lib/Functions/insta_download.dart | 41 +++++++++++++++++++++++++++++++ lib/Functions/story | 6 ++++- lib/main.dart | 23 +++++++++++++++-- 3 files changed, 67 insertions(+), 3 deletions(-) diff --git a/lib/Functions/insta_download.dart b/lib/Functions/insta_download.dart index d52493e..abe8a2c 100644 --- a/lib/Functions/insta_download.dart +++ b/lib/Functions/insta_download.dart @@ -41,6 +41,47 @@ class InstaDownloadController extends GetxController { } } + stories(String uName, String? sId) async { + try { + var url = 'https://igs.sf-converter.com/api/userInfoByUsername/$uName'; + final http.Response user = await http.get(Uri.parse(url)); + var userData = jsonDecode(user.body); + var userId = userData['result']['user']['pk']; + var url1 = 'https://igs.sf-converter.com/api/stories/$userId'; + final http.Response stories = await http.get(Uri.parse(url1)); + var storiesData = jsonDecode(stories.body); + var arr = storiesData['result']; + for (var storie in arr) { + if (storie['pk'] == sId) { + if (storie['image_versions2'] != null) { + var image = storie['image_versions2']['candidates'][0]['url']; + if (storie['video_versions'] != null) { + var video = storie['video_versions'][0]['url']; + downloadFile(image, video, 'storie_video_$sId'); + } else { + downloadFile(image, image, 'storie_image_$sId'); + } + } + } + } + // arr.forEach((storie) { + // if (storie['pk'] == sId) { + // if (storie['image_versions2'] != null) { + // var image = storie['image_versions2']['candidates'][0]['url']; + // if (storie['video_versions'] != null) { + // var video = storie['video_versions'][0]['url']; + // downloadFile(image, video, 'storie_video_$sId'); + // } else { + // downloadFile(image, image, 'storie_image_$sId'); + // } + // } + // } + // }); + } catch (e) { + print(e); + } + } + postReel(data) { if (data['require_login'] != null && data['require_login']) { navigatorKey.currentState?.pushNamed('login'); diff --git a/lib/Functions/story b/lib/Functions/story index 8f5fdfc..022ed4c 100644 --- a/lib/Functions/story +++ b/lib/Functions/story @@ -55,4 +55,8 @@ static Future storyFromUrl(String userUrl) async { } return _profileParsed; } -} \ No newline at end of file +} + + // https://igs.sf-converter.com/api/userInfoByUsername/phoenix_queen_25 + // https://igs.sf-converter.com/api/stories/50839057408 + // https://igs.sf-converter.com/api/highlights/50839057408 \ No newline at end of file diff --git a/lib/main.dart b/lib/main.dart index 9599991..9708467 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -245,8 +245,27 @@ class _MyHomePageState extends State { setState(() { downloading = true; }); - if (reelController.text.trim().isNotEmpty) { - downloadController.downloadReal(reelController.text); + var url = reelController.text.trim(); + if (url.isNotEmpty) { + final Uri uri = Uri.parse(url); + if (uri.hasAbsolutePath) { + RegExp ins = RegExp(r'instagram.com'); + bool test = ins.hasMatch(url); + if (test) { + var optIon = url.split("/")[3]; + if (optIon == 'p' || optIon == 'reel') { + downloadController.downloadReal(url); + } else if (optIon == 'stories') { + var data = url.split('/'); + RegExp regExp = RegExp(r'^(\d+)'); + var match = regExp.firstMatch(data[5]); + if (match == null) return; + downloadController.stories(data[4], match.group(0)); + } + } + } else { + print('else'); + } } else { showToast(); }