david-dick / firefox-marionette

This is a client module to automate the Mozilla Firefox browser via the Marionette protocol
https://metacpan.org/dist/Firefox-Marionette
Other
12 stars 3 forks source link

Extract video / audio content from html5 tag #46

Closed japharl closed 2 months ago

japharl commented 3 months ago

I'm not sure how to download am embeded video from a webpage. Specifically, given this code:

<HTML>
<BODY>
<VIDEO height=240 width=240>
  <source src="video.mp4">
  no video tag support.
</VIDEO>
</BODY>
</HTML>

The selfie function is close, but not quite. Also interested in the audio tag which has a similar format.

david-dick commented 2 months ago

I would suggest something like this?

#! /usr/bin/perl

use strict;
use warnings;
use Firefox::Marionette();

my $firefox = Firefox::Marionette->new();
$firefox->go('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video');
foreach my $iframe ($firefox->find_tag('iframe')) {
        $firefox->switch_to_frame($iframe);
        foreach my $video ($firefox->find_tag('video')) {
                foreach my $source ($video->find_tag('source')) {
                        if ($source->property('type') eq 'video/mp4') {
                                my $url = $source->property('src');
                                my $handle = $firefox->download($url);
                                my $count = 0;
                                while(my $line = <$handle>) {
                                        $count += length $line;
                                }
                                print "Video at $url is $count bytes long\n";
                        }
                }
        }
        $firefox->switch_to_parent_frame();
}
$firefox->quit();

Does that meet your requirement?

japharl commented 2 months ago

Ooh, that's great. Thank you. Please close ticket. 😀

On Fri, Jun 14, 2024, 9:21 PM david-dick @.***> wrote:

I would suggest something like this?

! /usr/bin/perl

use strict; use warnings; use Firefox::Marionette();

my $firefox = Firefox::Marionette->new(); $firefox->go('https://www.w3schools.com/tags/tryit.asp?filename=tryhtml5_video'); foreach my $iframe ($firefox->find_tag('iframe')) { $firefox->switch_to_frame($iframe); foreach my $video ($firefox->find_tag('video')) { foreach my $source ($video->find_tag('source')) { if ($source->property('type') eq 'video/mp4') { my $url = $source->property('src'); my $handle = $firefox->download($url); my $count = 0; while(my $line = <$handle>) { $count += length $line; } print "Video at $url is $count bytes long\n"; } } } $firefox->switch_to_parent_frame(); } $firefox->quit();

Does that meet your requirement?

— Reply to this email directly, view it on GitHub https://github.com/david-dick/firefox-marionette/issues/46#issuecomment-2169021614, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJR56UDC3Q5PPQ4MFXNDWLZHOJIDAVCNFSM6AAAAABJKQTROGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNRZGAZDCNRRGQ . You are receiving this because you authored the thread.Message ID: @.***>