Download Instagram Vids Via Linux Bash Script Example
Page 1 of 1
Download Instagram Vids Via Linux Bash Script Example
Script
- Code:
#!/bin/bash
# (c) J~Net 2018
# jnet.forumotion.com/t1655-download-instagram-vids-via-linux-bash-script-example#2553
#
# Example:
#
# ./run.sh "https://www.instagram.com/p/BqFMLEig93K/?utm_source=ig_share_sheet&igshid=1bxa7vyyr78c9"
#
#
cd /home/jay/Documents/Scripts/Instagram_Download
#
wget $1 -O out.html
#
cat out.html | grep "<meta property=\"og:video\" content=\"" > out.txt
#
clear
cat out.txt | grep "content=\"https://" > new.txt
grep -o ' <meta property.*/>' new.txt | sed 's/\(<meta property\|<\/>\)//g' > final.txt
str=`cat final.txt`
echo "$str" | cut -c 23- > final.txt
str=`cat final.txt`
# Remove last 4 chars
echo ${str::-4} > final.txt
#
str=`cat final.txt`
#readarray a < out.txt
#
wget $str
#
rm *.html
rm out.txt
rm out2.txt
rm new.txt
rm final.txt
Make executable and run
Soon I will put a php script for this so you can use it via a web page.
Vid Coming Soon!
Script
PHP Front End
For a PHP based front end to do the same thing using above bash script you can do this too
Before you start make sure any folders you want files to download to via a php script, you will need to allow www-data access to execute bash scripts and have correct folder permissions!
Run.sh script
Index.php
Process.php
Before you start make sure any folders you want files to download to via a php script, you will need to allow www-data access to execute bash scripts and have correct folder permissions!
Run.sh script
- Code:
#!/bin/bash
#
#export TERM=xterm
export TERM=linux
# ./run.sh https://www.instagram.com/p/BqA5E3QhRTB/?utm_source=ig_share_sheet&igshid=w4vbfaltu7c4
#
url="$1"
if [ -z "$url" ]
then
echo "\url is empty"
else
cd "/var/www/html/apps/Downloader/ig/"
wget $url -O out.html
#
cat out.html | grep "<meta property=\"og:video\" content=\"" > out.txt
#
cat out.txt | grep "content=\"https://" > new.txt
grep -o ' <meta property.*/>' new.txt | sed 's/\(<meta property\|<\/>\)//g' > final.txt
str=`cat final.txt`
echo "$str" | cut -c 23- > final.txt
str=`cat final.txt`
# Remove last 4 chars
echo ${str::-4} > final.txt
#
str=`cat final.txt`
#readarray a < out.txt
#
wget "$str"
#
rm *.html
rm out.txt
#rm out2.txt
rm new.txt
rm final.txt
#echo "\url is set to $url"
mv *.mp4 output.mp4
fi
#cd $url
#
Index.php
- Code:
<!DOCTYPE HTML>
<meta http-equiv="Pragma" content="no-cache">
<title>J~Net Instagram Video Downloader</title>
<html>
<body>
<?php
session_start();
if(!$_SESSION['userid']){
header("Location: /index.php");
exit;
} ?>
<?php
include_once("../../../php_includes/check_login_status.php");
include("../../../headerd.php");
$id=$_SESSION['userid'];
$username=$_SESSION['username'];
?>
<center>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/button3.css">
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
}
</style>
<header id="header"><h1 class="logo"><a href="/">J~Net Instagram Video Downloader</a></h1><p class="subtitle">Instagram Photo, Video, and IGTV Downloader</p><form id="main_form" action="process.php" method="post" onsubmit="return false;>
<div class="main_input_wrapper"><input autofocus="" placeholder="https://instagram.com/p/41SW_pmmq4/" name="url" value="" style="color:#000;"></div><div class="actions"><input value="Download" class="button" type="submit"></div>
</form><div id="results" style="opacity: 1;"><div class="success"></div>
</div><div id="waiting" style="transform-origin: 0px 0px 0px; opacity: 1; transform: scale(1, 1); display: none;"><div class="loading"><span></span> <span></span> <span></span></div></div><div id="waitingdls">Your download will start in a few seconds.</div><section class="zen"><div id="zen"> </div></section></header>
</body>
</html>
Process.php
- Code:
<!DOCTYPE HTML>
<meta http-equiv="Pragma" content="no-cache">
<title>J~Net Instagram Video Downloader</title>
<html>
<body>
<?php
session_start();
if(!$_SESSION['userid']){
header("Location: /index.php");
exit;
} ?>
<?php
include_once("../../../php_includes/check_login_status.php");
include("../../../headerd.php");
$id=$_SESSION['userid'];
$username=$_SESSION['username'];
//
//$url=$_POST['url'];
$url=filter_var($_POST['url'], FILTER_SANITIZE_STRING);
?>
<center>
<link rel="stylesheet" href="css/style.css">
<style>
.button {
background-color: #4CAF50; /* Green */
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
cursor: pointer;
}
</style>
<h2>J~Net Instagram Video Downloader</h2>
<p><br>
<?php
echo "<center>Downloading Video From Link $url<p><br>";
function Build(){
sleep(1);
//$name="output.mp4";
$message=shell_exec("/var/www/html/apps/Downloader/ig/run.sh \"$url\" 2>&1");
//print_r($message);
echo '<p><br>';
echo "<img src=\"$url\">";
}
if (isset($_POST['url']))
//$name="output.mp4";
//echo "$name";
$message=shell_exec("/var/www/html/apps/Downloader/ig/run.sh \"$url\" 2>&1");
//print_r($message);
echo '<p><br>';
$link='<div id="results" style="opacity: 1;"><div class="success"><a href="output.mp4?dl=1" class="button button_green" target="_blank">Download video</a></div>';
//Build($name);
?>
<p><br>
<?php echo $link;?>
<p><br>
<link rel="stylesheet" type="text/css" href="css/button3.css">
<div id="breadcrumbsc" onclick="location.href='index.php';" style="cursor: pointer;">
<center>
<h2>Back</h2>
</center>
</div>
<script>
function Build(){
alert("<?php Build(); ?>");
}
</script>
</body>
</html>
Similar topics
» Linux BASH Script Running Commands and Functions From Bash Script and saving to varables
» Convert MP4 To MP3 Linux Bash Script
» Linux Bash Dog Age Calculator Script
» BASH Linux Talking IP Script
» Linux Random Name Picker Bash Script Example
» Convert MP4 To MP3 Linux Bash Script
» Linux Bash Dog Age Calculator Script
» BASH Linux Talking IP Script
» Linux Random Name Picker Bash Script Example
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum