Removing any videos from a HTML fragment - html

I have a (possibly not conforming to any standards) HTML fragment with embedded video. The problem is to remove the subfragment(s) with the video.
It is expected that the video follows this format:
<div data-oembed-url="https://www.youtube.com/watch?v=XXX&feature=youtu.be"><iframe allowfullscreen="allowfullscreen" frameborder="0" height="270" src="https://www.youtube.com/embed/XXX?feature=oembed" tabindex="-1" width=" 480"></iframe></div>
I am entirely unsure whether all data follows this scheme.
I think any div or p containing only the video should be removed, too.
Please help to write Perl code to remove video. Which Perl module do you recommend to use for parsing?

sub RemoveVideo {
my ($str) = #_;
my $attrRe = qr/\s*(?<name>\b\S+\b)\s*=\s*(?<value>"[^"]*"|'[^']*'|[^"'<>\s]+)\s*/;
my $iframeRe = qr{<iframe\b($attrRe)*>\s*</iframe\s*>|<iframe\b($attrRe)*\s*/>}i;
my $divRe = qr{<div\b($attrRe)*>\s*$iframeRe\s*</div\s*>\s*}i;
my $pRe = qr{<p\b($attrRe)*>\s*$iframeRe\s*</p\s*>\s*}i;
$str =~ s/$divRe//gms;
$str =~ s/$pRe//gms;
$str =~ s/$iframeRe//gms; # "голый" iframe (не внутри дива)
return $str;
}
my $Test = <<EOF;
XXX
<IFRAME allowfullscreen="allowfullscreen" frameborder="0" height="270" src="https://www.youtube.com/embed/XXX?feature=oembed" tabindex="-1" width=" 480"></iframe>
<div data-oembed-url="https://www.youtube.com/watch?v=XXX&feature=youtu.be"><iframe allowfullscreen="allowfullscreen" frameborder="0" height="270" src="https://www.youtube.com/embed/XXX?feature=oembed" tabindex="-1" width=" 480"></iframe></div>
<p data-oembed-url="https://www.youtube.com/watch?v=XXX&feature=youtu.be"><iframe allowfullscreen="allowfullscreen" frameborder="0" height="270" src="https://www.youtube.com/embed/XXX?feature=oembed" tabindex="-1" width=" 480"></iframe></p>
YYY
EOF
print RemoveVideo($Test);

Related

How to define a specific location in each item from loop ANGULAR

I created activity.json and I want to call data from json file. So, I made a ngFor loop in another file for getting the each item/data from json.
I thought it could get the location url-link from json file and put it to "<iframe src=" line of html file as a src link.
Following code, that mention about above issue.
[this is html file][1]
<div *ngFor="let seminer of activities">
<!-- <p>dive giriyor 6/6</p> -->
<h6>{{seminer.name}}</h6>
<iframe src="{{seminer.location}}" width="95%" height="225" style="border:0;" allowfullscreen="" loading="lazy"></iframe>
</div>
The spesific definition, this expression "{{seminer.location}}" couldn't accept as src link. How can I fix this issue. I mean I want to call each different location from json file.
[this is json file][2]
{
"activities":
[
{
"id":1,
"name":"Akınsoft Robotik Yarışması",
"location":"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d97887.93596631498!2d32.725496907783025!3d39.9414344280414!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xbda608ad56f1f424!2zQWvEsW5zb2Z0IEFua2FyYSBCw7ZsZ2UgTcO8ZMO8cmzDvMSfw7wtIEJpcmV5c2VsIEJpbGnFn2lt!5e0!3m2!1str!2str!4v1623673068413!5m2!1str!2str"
},
{
"id":2,
"name":"Parantez Teknoloji Arge Çalışması",
"location":"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3059.4160712434614!2d32.829206315242146!3d39.932081979424524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14d34ec5db5faa51%3A0xc30ca1837518daa4!2sParantez%20Teknoloji!5e0!3m2!1str!2str!4v1623673296169!5m2!1str!2str"
},
{
"id":3,
"name":"Tusaş Ionic Mobil Tasarımlama",
"location":"https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3049.556596789323!2d32.651176815249194!3d40.15215957939679!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x408276c02c887105%3A0x1c5ec14c2922033f!2zR0FaxLAgw5xOxLBWRVJTxLBURVPEsCBUVVNBxZ4gS0FaQU4gTUVTTEVLIFnDnEtTRUtPS1VMVQ!5e0!3m2!1str!2str!4v1623673780177!5m2!1str!2str"
}
]
}
I guess the html tool don't let to use us a specific variable for routing a URL-link in other file. It has to used link in that place from direct, like this;
src="https://..."
I tried to different way for solving this issue. I tried to reach with different id's of each item. My solution is;
<iframe *ngIf="seminer.id==1" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d97887.93596631498!2d32.725496907783025!3d39.9414344280414!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x0%3A0xbda608ad56f1f424!2zQWvEsW5zb2Z0IEFua2FyYSBCw7ZsZ2UgTcO8ZMO8cmzDvMSfw7wtIEJpcmV5c2VsIEJpbGnFn2lt!5e0!3m2!1str!2str!4v1623673068413!5m2!1str!2str" style="border:0;" allowfullscreen="" loading="lazy" class="center"></iframe>
<iframe *ngIf="seminer.id==2" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3059.4160712434614!2d32.829206315242146!3d39.932081979424524!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x14d34ec5db5faa51%3A0xc30ca1837518daa4!2sParantez%20Teknoloji!5e0!3m2!1str!2str!4v1623673296169!5m2!1str!2str" style="border:0;" allowfullscreen="" loading="lazy" class="center"></iframe>
<iframe *ngIf="seminer.id==3" src="https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d3049.556596789323!2d32.651176815249194!3d40.15215957939679!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x408276c02c887105%3A0x1c5ec14c2922033f!2zR0FaxLAgw5xOxLBWRVJTxLBURVPEsCBUVVNBxZ4gS0FaQU4gTUVTTEVLIFnDnEtTRUtPS1VMVQ!5e0!3m2!1str!2str!4v1623673780177!5m2!1str!2str" style="border:0;" allowfullscreen="" loading="lazy" class="center"></iframe>

Replace iframe video player with link to target page

I would like to modify my current code so that instead of the whole player, display only link to it. Does anyone have an idea how to do it? I have something like this:
<iframe src="http://www.youtube.com/embed/<?php echo $_GET['id']; ?>" style="border: 0; width: 100%; height: 360px;" frameborder="0" scrolling="no"></iframe>
And I want something like this:
"U can watch this here: http://www.youtube.com/watch?v=<?php echo $_GET['id']; ?>"
You can make a "link" with an "anchor" (<a>) tag. Something like this:
U can watch this here: http://www.youtube.com/watch?v=<?php echo $_GET['id']; ?>
Or simply:
U can watch this here: Click here!
Use an a tag:
"U can watch this here: <a href='http://www.youtube.com/watch?v=<?php echo $_GET['id']; ?>'>Video</a>"

Making a clean looking Doxygen ALIAS with HTML

I have a working Doxygen ALIAS code using HTML (via #htmlonly), that in order to display a youtube video, allows me to simply write in the (".markdown")-file:
Youtube Link:
https://www.youtube.com/watch?v=**CODE**
With ALIAS:
#youtube{**CODE**}
Without ALIAS:
#htmlonly
<div align="center">
<iframe
title="my title" width="560" height="349"
src="http://www.youtube.com/embed/**CODE**?rel=0&loop=1"
frameborder="0" allowfullscreen align="middle">
</iframe>
</div>
#endhtmlonly
By adding the following ALIAS to the Doxyfile:
ALIASES += youtube{1}="#htmlonly<div align='center'><iframe title='my title' width='560' height='349' src='http://www.youtube.com/embed/\1?rel=0&loop=1' frameborder='0' allowfullscreen align='middle'></iframe></div>#endhtmlonly"
My problem is that the macro as you can see from above is HUGE and looks really CONFUSING!
Questions:
Is there a way to make it look clean?
What should I do with bigger HTML raw codes?
Should I be using any other Doxygen alternative to the ALIAS?
I managed to figure it out.
Instead of:
ALIASES += youtube{1}="#htmlonly<div align='center'><iframe title='my title' width='560' height='349' src='http://www.youtube.com/embed/\1?rel=0&loop=1' frameborder='0' allowfullscreen align='middle'></iframe></div>#endhtmlonly"
I can use:
#youtube{link}, with:
ALIASES+=addyoutube{1}="#htmlonly</p><div class='addYoutube'>\1</div>#endhtmlonly"
ALIASES+=youtube{1}="#addyoutube{\1} #htmlinclude add_youtube.html"
EXAMPLE_PATH += #CMAKE_CURRENT_SOURCE_DIR#/add_youtube.html
And add the following javascript code in a file in the current directory, add_youtube.html:
<script type="text/javascript">
var $getDiv = $('div.addYoutube').last();
var filmId = $getDiv.html()
filmId = filmId.replace("https://","")
filmId = filmId.replace("www.","")
filmId = filmId.replace("youtube.com/watch?v=","")
document.write("<div align='center'><iframe title='my title' width='560' height='349' src='http://www.youtube.com/embed/"+filmId+"?rel=0&loop=1' frameborder='0' allowfullscreen align='middle'> </iframe> </div>");
$getDiv.remove()
</script>
A bit to late for a party, but in Doxygen 1.8.12 it is possible to create some combination of doxygen tags #brief and HTML elements.
When you defining attributes for HTML elements it is possible to use apostrophes class='someClass' or you can also use quote sign with a backslash class=\"someClass\".
To indent the html use the string concantenation with a backslash sign \.
ALIASES += "briefWithImage{3} = #brief \
#htmlonly \
<span><img class='imgBriefImage' src='\1' alt='\1'></span> \
</span><span class='spanBriefText'>\2(<b>\3</b>)</span> \
#endhtmlonly"
I'm not sure about alternatives to aliases. One way is to define your custom HTML header for each page and when page is loaded - replace your own placeholders using custom JS functions.

HTML5 using <video> tag to insert every .mp4 from a directory

I'm trying to make a very basic image/video sharing website. To make things easier on myself, I was wondering if it was possible to mass-include ALL .mp4's from a directory instead of individually adding them. Here is my current doc:
<html>
<body>Under construction.<br>
<video autoplay>
<source src="away.mp4" type="video/mp4">
</video>
</body>
</html>
I don't want to have to manually add a <video> tag for every file, is there a way to add them all at once? Or something like YouTube does, where it shows a thumbnail but opens another page to play it. If there is a way to add the video sources en masse, does it include newly added files?
Maybe something like that
<?php
$dir = './videos';
$video_files = [];
foreach(glob($dir.'/*.*') as $file) {
$file_parts = pathinfo($file);
if ($file_parts['extension'] == "mp4"){
$video_files[] = $file;
}
}
foreach($video_files as $video_file) {
echo "<video autoplay>";
echo "<source src=". $video_file ." type='video/mp4'>";
echo "</video><br/>";
}
?>
or in one loop
<?php
$dir = './videos';
$video_files = [];
foreach(glob($dir.'/*.*') as $file) {
$file_parts = pathinfo($file);
if ($file_parts['extension'] == "mp4"){
echo "<video autoplay>";
echo "<source src=". $file ." type='video/mp4'>";
echo "</video><br/>";
}
}
?>

How to return text from nokogiri without parsing it

I have html that looks like this:
<textarea id='embed'>
<iframe frameborder='0' width='728' height='450' src='http://somelink'>
</iframe> some more text
</textarea>
My code is:
doc.at('textarea[#id="embed"]').content
however this returns some more text
I want to fetch the entire text area (including the iframe link as it is). So finally I want this :
<iframe frameborder='0' width='728' height='450' src='http://somelink'>
</iframe> some more text
Use .inner_html.
[1] pry(main)> require 'nokogiri'
=> true
[2] pry(main)> noko = Nokogiri::HTML("<textarea id='embed'>
[2] pry(main)* <iframe frameborder='0' width='728' height='450' src='http://www.dailymotion.com/embed/video/xvnu79'>
[2] pry(main)* </iframe> some more text
[2] pry(main)* </textarea>");
[3] pry(main)> noko.css("#embed").inner_html
=> "<iframe frameborder=\"0\" width=\"728\" height=\"450\" src=\"http://www.dailymotion.com/embed/video/xvnu79\">\n </iframe> some more text\n"
Edit: you can use .inner_html with the XPath selector you have above too.