Hello Friends Today, through this tutorial, I will tell you How to Get Facebook Video id From url Using Perl Script Code?
To extract the video ID from a Facebook video URL in Perl, you can use regular expressions. Here’s an example:
use strict; use warnings; sub get_facebook_video_id { my ($url) = @_; # Define the regular expression pattern to match Facebook video URLs my $pattern = qr/(?:https?:\/\/)?(?:www\.)?(?:facebook\.com\/.*\/videos\/|facebook\.com\/video\.php\?v=)(\d+)(?:\S+)?/; # Use the pattern in a match operation if ($url =~ $pattern) { # If a match is found, return the video ID return $1; } else { # If no match is found, return undef return undef; } } # Example usage my $facebook_video_url = "https://www.facebook.com/facebook/videos/123456789/"; my $video_id = get_facebook_video_id($facebook_video_url); if (defined $video_id) { print "Facebook Video ID: $video_id\n"; } else { print "Invalid Facebook Video URL\n"; }
In this Perl script, the `get_facebook_video_id` subroutine takes a Facebook video URL as input and returns the video ID using a regular expression. The example usage demonstrates how to call this subroutine with a Facebook video URL.
Make sure to test the code with different Facebook video URLs to ensure it covers various formats. Note that relying on web scraping methods like this might be subject to changes in the structure of Facebook URLs, so it’s a good idea to monitor and adapt if needed. If Facebook provides an API for retrieving video information, using that API would be a more reliable solution.