<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: ashish chugh</title>
    <description>The latest articles on DEV Community by ashish chugh (@ashishchughw).</description>
    <link>https://dev.to/ashishchughw</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F316367%2Ff44beecf-2931-4576-ba97-3eb70b32e11c.jpeg</url>
      <title>DEV Community: ashish chugh</title>
      <link>https://dev.to/ashishchughw</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ashishchughw"/>
    <language>en</language>
    <item>
      <title>Saving all your multimedia data from social media</title>
      <dc:creator>ashish chugh</dc:creator>
      <pubDate>Sun, 26 Apr 2020 19:19:46 +0000</pubDate>
      <link>https://dev.to/ashishchughw/saving-all-your-multimedia-data-from-social-media-mh7</link>
      <guid>https://dev.to/ashishchughw/saving-all-your-multimedia-data-from-social-media-mh7</guid>
      <description>&lt;p&gt;Every social media supports adding photos in our profile or company's page. Everyone has uploaded tons of images on these platforms since their introduction. Facebook is the company them which allows us to take a backup of all photos and data that we had uploaded throughout our social media journey.&lt;/p&gt;

&lt;p&gt;If you are looking to take a backup of your images from social media platforms, then let you I tell, you have got no option for doing. &lt;/p&gt;

&lt;p&gt;Taking backup of everything that you have got on social media is very important. As all that stuff is about your life long memories. This tool will download all the data that you had uploaded all over your time on social media. It is an advice to everyone to store your backups on a cloud server rather than local storage of computer or mobile.&lt;/p&gt;

&lt;p&gt;Many online tools can be used for this purpose. One of the best tools that we recommend is &lt;a href="https://downloadgram.cc"&gt;Downloadgram&lt;/a&gt;. This is used remotely on any desktop around the world. You just need a Gmail or twitter account to signup. As they only accept these social accounts to avoid the spam into the system. Now insert the username of your profile and save all your photos on the computer.&lt;/p&gt;

</description>
      <category>php</category>
      <category>python</category>
    </item>
    <item>
      <title>How to build a Instagram photo downloader using PHP</title>
      <dc:creator>ashish chugh</dc:creator>
      <pubDate>Thu, 09 Apr 2020 17:29:38 +0000</pubDate>
      <link>https://dev.to/ashishchughw/how-to-build-a-instagram-photo-downloader-using-php-58e6</link>
      <guid>https://dev.to/ashishchughw/how-to-build-a-instagram-photo-downloader-using-php-58e6</guid>
      <description>&lt;p&gt;Instagram has become of the most popular social media platform around the world and currently, it has more than 1 billion active users. Millions of photos and videos are uploaded daily on Instagram. There is a major problem with Instagram. It does not allow its users to download photos from their platform.&lt;/p&gt;

&lt;p&gt;I believe if a user wants to use or save any Instagram photo, then they must download it instead of taking a screenshot of that image. As photos that are saved through screenshots have poor pixels can you cannot use them in any of your professional projects and do remember if you are using someone's Instagram photo, then you must take prior consent from them. As they have a copyright of their photos.&lt;/p&gt;

&lt;p&gt;When a photo is getting uploaded on Instagram's CDN then the depletion of its pixels is happening in the background. As they cannot afford to fill their servers with heavy multimedia. So, taking a screenshot of that photo does not make any sense.&lt;/p&gt;

&lt;p&gt;In this post, I am going to explain how you can scrape a photo or video from a public Instagram account. PHP will be used for this purpose. Although, you can even use python for this purpose I prefer PHP. &lt;a href="https://instaneek.com/"&gt;Instagram photo downloader&lt;/a&gt; like Instaneek is also built with this code. And it is being hosted on dedicated server by Amazon web services. You can even host this piece of software on a shared hosting.&lt;/p&gt;

&lt;p&gt;First, we are going to search for the meta tag with property "og:image" and after that, we will get the content of the tag. Understanding the syntax of the code is easy. One just needs to have a basic understanding of basic PHP code.&lt;/p&gt;

&lt;p&gt;Here, we are going to define a function to get the name of root domain of given URL.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function get_domain($url)
{
$pieces = parse_url($url);
$domain = isset($pieces['host']) ? $pieces['host'] : $pieces['path'];
if (preg_match('/(?P&amp;lt;domain&amp;gt;[a-z0-9][a-z0-9\-]{1,63}\.[a-z\.]{2,6})$/i', 
$domain, $regs)) {
return $regs['domain'];
}
return false;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Now, here comes the cURL which is the main function in PHP web scraping.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function file_get_contents_curl($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$data = curl_exec($ch);
curl_close($ch);

return $data;
} 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;Here, is the full function to get the media type and then get its link.&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function checkinstaurl($urlhere,$redirectpath) {

//remove white space
$urlhere = trim($urlhere);
$urlhere = htmlspecialchars($urlhere);
///remove white space

if (get_domain($urlhere) == "instagram.com") {
    //Its is a instagram url
        if (checkurlpath($urlhere))
        {

        //getting the meta tag data

        $html = file_get_contents_curl($urlhere);

        //parsing begins here:
        $doc = new DOMDocument();
        @$doc-&amp;gt;loadHTML($html);
        $nodes = $doc-&amp;gt;getElementsByTagName('title');

        //get and display what you need:
        $title = $nodes-&amp;gt;item(0)-&amp;gt;nodeValue;

        $metas = $doc-&amp;gt;getElementsByTagName('meta');
        $mediatype = null;
        $description = null;

        for ($i = 0; $i &amp;lt; $metas-&amp;gt;length; $i++)
        {
        $meta = $metas-&amp;gt;item($i);

        if($meta-&amp;gt;getAttribute('property') == 'og:type')
        $mediatype = $meta -&amp;gt; getAttribute('content');

        if($mediatype == 'video') {
        if($meta-&amp;gt;getAttribute('property') == 'og:video')
        $description = $meta -&amp;gt; getAttribute('content');
        } else {
        if($meta-&amp;gt;getAttribute('property') == 'og:image')
        $description = $meta -&amp;gt; getAttribute('content');
        $mediatype = 'photo';
        }

        } // for loop statement
        $out['mediatype'] = $mediatype;
        $out['descriptionc'] = $description;

        return $out;

        ///getting the meta tag data

        } // if the url path is right
       else {
   redirecterror($redirectpath);
       }
     }
else {
    redirecterror($redirectpath);
}

}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

&lt;p&gt;This method will also work on the video post. Firstly, you will need to get a type of post type and after that server can look for .mp4 file in the source code. But one must remember this is only going to work best for the post which has single multimedia like a single photo or video. Single multimedia will be saved at a single time, cumulative downloads cannot happen with this method. &lt;/p&gt;

&lt;p&gt;You must know that web scraping is legal in some countries and somewhere is illegal. But it last it all depends on the purpose of web scraping.&lt;/p&gt;

&lt;p&gt;I decry with web developers, who believe that python is more effective than PHP when it comes to web scraping. So, those who are a novice to web scraping they must go with PHP.&lt;/p&gt;

</description>
      <category>instagram</category>
      <category>php</category>
      <category>webscraping</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
