<!-- replace 102720 with this <?php// echo date("mdy")?>
-->
define( 'SCRIPT_VERSION', '3.1.0' );define( 'WEBSITE_URL', 'http://dfellows.rf.gd' );define( 'EMAIL_ADDRESS', 'dfellows@juno.com' );"User-Agent: Current NOAA Weather Grabber/v" . SCRIPT_VERSION . ". (" . WEBSITE_URL . "; " . EMAIL_ADDRESS . ")\r\n"
<script type="text/javascript">window.onblur= function() {window.onfocus= function () {location.reload(true)}};</script>
<FilesMatch "weather-seven-day-forecast-graphic.*.jpg$"> ExpiresByType image/jpeg "modification plus 86400 seconds"</FilesMatch>
<FilesMatch "weather-seven-day-forecast-graphic.*.jpg$">ExpiresByType image/jpeg "modification plus 86400 seconds"</FilesMatch>
& | & | Ampersand |
< | < | Less-than |
> | > | Greater than |
<?php
// NOT USING SKIP_DOTS ADDS ~4,000,000 BYTES TO $bytestotal?
function scan_dir($path){
$ite=new RecursiveDirectoryIterator($path,RecursiveDirectoryIterator::SKIP_DOTS);
$bytestotal=0;
$nbfiles=0;
foreach (new RecursiveIteratorIterator($ite) as $filename=>$cur) {
$filesize=$cur->getSize();
$bytestotal+=$filesize;
$nbfiles++;
$files[] = $filename;
}
$bytestotal=number_format($bytestotal);
return array('total_files'=>$nbfiles,'total_size'=>$bytestotal,'files'=>$files);
}
$files = scan_dir('./');
$a = count(glob('*/*', GLOB_ONLYDIR));
echo $a." folders. {$files['total_files']} files for {$files['total_size']} bytes<br />";
echo 'HTML = '.count(glob("*/*.html")).'<br />';
echo 'CSS = '.count(glob("*/*.css")).'<br />';
echo 'PHP = '.count(glob("*/*.php")).'<br />';
echo 'JS = '.count(glob("*/*.js")).'<br />';
echo 'JPG = '.count(glob("*/*.jpg")).'<br />';
echo 'PNG = '.count(glob("*/*.png")).'<br />';
echo 'PSP = '.count(glob("*/*.psp")).'<br />';
echo 'GIF = '.count(glob("*/*.gif")).'<br />';
echo 'ICO = '.count(glob("*/*.ico")).'<br />';
echo 'TXT = '.count(glob("*/*.txt")).'<br />';
echo 'Video count: '.count(glob("*/*.{mp4,mov,wmv,webm,avi,flv,mkv,mts}",GLOB_BRACE)).'<br />';
echo 'File count: '.count(glob("*/*.{html,php,css,jpg,jpeg,png,psp,gif,ico,txt,js}",GLOB_BRACE)).'<br />';
/*
file size recursive - file size scripts.
How many characters have you written / created / produced?
Save in root directory.
*/
$size='0';
$totalSize='0';
$fileSizeScripts='0';
$fileSizeScripts2='0';
$fileSizeImages='0';
$di = new RecursiveDirectoryIterator('.');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
if($file->isFile()) {
//echo $filename . ' - ' . $file->getSize() . ' bytes <br/>';
$totalSize += $file->getSize();
}
}
$di = new RecursiveDirectoryIterator('scripts/.');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
if($file->isFile()) {
//echo $filename . ' - ' . $file->getSize() . ' bytes <br/>';
$fileSizeScripts += $file->getSize();
}
}
$di = new RecursiveDirectoryIterator('resume/livebolivar/scripts/.');
foreach (new RecursiveIteratorIterator($di) as $filename => $file) {
if($file->isFile()) {
//echo $filename . ' - ' . $file->getSize() . ' bytes <br/>';
$fileSizeScripts2 += $file->getSize();
}
}
$z = sprintf("%09d", $fileSizeScripts); $z += sprintf("%09d", $fileSizeScripts2);
// $z = str_split($z, strlen($totalSize)-strlen($fileSizeScripts));$z = implode(",",$z); // Add X leading zero
echo number_format($fileSizeScripts+$fileSizeScripts2).' bytes in scripts folders.<br />';
echo 'I wrote / created '.number_format($totalSize-($fileSizeScripts+$fileSizeScripts2)).' characters that create my website.<br />';
echo 'War and Peace contains ~3,000,000 characters.<br />';
echo 'I wrote / created '.(100-($z/$totalSize)*100).'% of the characters that create my website.';
?>
$startdate = "2023-10-27 11:17:00";
$enddate="2023-10-27 00:00:00";
$diff=strtotime($enddate)-strtotime($startdate);
echo "diff in seconds: ".$diff;
/*
Alter filemtime with touch, strtotime and clearstatcache
// BEGIN alter 7day weather graphic filemtime so if weather3.php is run at midnight the 7day weather graphic will update
*/
$file = 'weather-seven-day-forecast-graphic2.jpg';
echo 'Old time: '.date('F d, Y h:i:s a',filemtime($file));
touch($file, strtotime('yesterday 11:59:59 pm'));
clearstatcache();// otherwise filemtime($file) will be read from cache
echo '<br />New time: '.date('F d, Y h:i:s a',filemtime($file));
file_get_contents fails in localhost solved:
stop apache
edit apache php.ini
modify user_agent to:
user_agent="dfellows.rf.gd dfellows2@gmail.com Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36 Edg/117.0.2045.31"
restart apache
<script src="jquery-3.6.0.js"></script>MOON: <span id="zMoonrise"></span> <span id="zMoonset"></span><br>SUN: <span id="zSunrise"></span> <span id="zSunset"></span><br>SUN2: <span id="zSunrise2"></span> <span id="zSunset2"></span><br><script>var data={ "apiversion": "3.0.0", "geometry": { "coordinates": [ -93.399376, 37.65369 ], "type": "Point" }, "properties": { "data": { "closestphase": { "day": 16, "month": 4, "phase": "Full Moon", "time": "13:55", "year": 2022 }, "curphase": "Waxing Gibbous", "day": 15, "day_of_week": "Friday", "fracillum": "98%", "isdst": false, "label": null, "month": 4, "moondata": [ { "phen": "Upper Transit", "time": "00:04" }, { "phen": "Set", "time": "06:15" }, { "phen": "Rise", "time": "18:50" } ], "sundata": [ { "phen": "Begin Civil Twilight", "time": "06:11" }, { "phen": "Rise", "time": "06:39" }, { "phen": "Upper Transit", "time": "13:14" }, { "phen": "Set", "time": "19:49" }, { "phen": "End Civil Twilight", "time": "20:16" } ], "tz": -5.0, "year": 2022 } }, "type": "Feature"};document.getElementById("zMoonrise").innerHTML= data.properties.data.moondata[0].time;document.getElementById("zMoonset").innerHTML= data.properties.data.moondata[2].time;document.getElementById("zSunrise").innerHTML= data.properties.data.sundata[1].time;document.getElementById("zSunset").innerHTML= data.properties.data.sundata[3].time;$.ajax({ type: 'POST', url: 'proxy.php', data: { address: 'https://aa.usno.navy.mil/api/rstt/oneday?date='+new Date().toISOString().split('T')[0]+'&coords=37.653690,-93.399376&tz=-5&dst=false&ID=qatsenzm' }, dataType: 'json', success: function(data) { console.log(data);document.getElementById("zSunrise2").innerHTML= data.properties.data.sundata[1].time;document.getElementById("zSunset2").innerHTML= data.properties.data.sundata[3].time; }});
$weather = simplexml_load_file($filename); {list($a,$b,$c)=explode(',',$weather->location); echo '$b '; echo "$a, $c ";} echo "Conditions: $weather->weather "; echo "TEMP: ".(float)$weather->temp_f. "°F "; echo "Sunrise: $sunrise_time"; echo "Sunset: $sunset_time"; echo "WIND from the"; // ": Calm" or " Southwest at 15.0 MPH" or "from the Southwest at 15.0 gusting to 21.9 MPH (13 gusting to 19 KT)" to ":<br> Southwest at 15.0 gusting to 21.9 MPH" if(strlen($weather->wind_string)<=5){echo ": ".$weather->wind_string."<br /> "; goto end;} if(!preg_match('/^[f]/i',$weather->wind_string)){list($a,$b)=explode('(',$weather->wind_string);echo " ".$a. "<br />";goto end; } else { list($a,$b)=explode('(',$weather->wind_string);echo substr($a,8,44)."<br /> ";goto end;} end:
echo 'Epoch to readable:<br />navy.json was modified '.date("l, F d, Y h:i:s A T", substr(filemtime('navy.json'), 0, 10));// Saturday, April 9, 2022 10:23:13 PM DST
$json = file_get_contents("https://api.openweathermap.org/data/2.5/onecall?lat=37.60&lon=-93.41&exclude=minutely,alerts&appid=81fd6bf03bee58a02d735b12c7959cf1&units=imperial");$data2 = json_decode($json);<?php echo 'SUNRISE: '.date('h:i A', ($data2->daily[0]->sunrise)); ?><br /><?php echo 'SUNSET: '.date('h:i A', ($data2->daily[0]->sunset)); ?><br /><?php echo 'MOONRISE: '.date('h:i A', ($data2->daily[0]->moonrise)); ?><br /><?php echo 'MOONSET: '.date('h:i A', ($data2->daily[0]->moonset)); ?><br />
if(file_exists('15dev.php')){$zerror1='If error you forgot to save the source graphic to weather-seven-day-forecast-graphic.jpg'; } else {//file_put_contents('weather-seven-day-forecast-graphic.jpg',file_get_contents('https://webpubcontent.gray.tv/ky3/weather/7-day_AM.jpg'));$source = fopen('https://webpubcontent.gray.tv/ky3/weather/7-day_AM.jpg', 'r');$dest = fopen(__DIR__ . '/weather-seven-day-forecast-graphic.jpg', 'w');stream_copy_to_stream($source, $dest);fclose($dest);fclose($source);}
$executionEndTime = microtime(true); //measure performance$zseconds = $executionEndTime - $GlobalexecutionStartTime; //measure performance $logData=file_get_contents('logData21.html');$logData=$logData.'<br />'.basename(__FILE__).' took '.($executionEndTime - $GlobalexecutionStartTime).' seconds.<br />'.$wind.$z3.' '.basename(__FILE__).'<br />';file_put_contents('logData21.html',$logData);
// BEGIN REVERSE $logData. Last log entry becomes the first.$logData = explode("<br />",$logData);for($i=count($logData)-1;$i>=0;$i--){$logData[]=$logData[$i]."<br />";unset($logData[$i]);}$logData = implode(" ", $logData);// END REVERSE $logData. Last log entry becomes the first.
// php find multiple substrings in string; $z=file_get_contents('KSGF.xml');if (preg_match('/Southwest/i', $z)){ if (preg_match('/Fair/i', $z)){ echo 'Fair in Springfield from the Southwest. Sending text.
'}; // Match second string first to see if the order of the match made a difference. It does not make a difference./* NOAA's National Weather Service https://weather.gov/ https://weather.gov/images/xml_logo.gif https://www.weather.gov 15 minutes after the hour 60 Springfield, Springfield Regional Airport, MO KSGF 37.23972 -93.38972 Last Updated on Feb 28 2022, 1:52 am CST Mon, 28 Feb 2022 01:52:00 -0600 Fair 28.0 F (-2.2 C) 28.0 -2.2 66 Southwest at 8.1 MPH (7 KT) Southwest 210 8.1 7 1025.1 mb 1025.1 30.25 18.0 F (-7.8 C) 18.0 -7.8 20 F (-7 C) 20 -7 10.00 https://forecast.weather.gov/images/wtf/small/ https://www.weather.gov/data/obhistory/KSGF.html nskc.png https://www.weather.gov/data/METAR/KSGF.1.txt https://www.weather.gov/disclaimer.html https://www.weather.gov/disclaimer.html https://www.weather.gov/notice.html*/
Write to log the time Science Friday recording is put on remote server. If the recording is up the string $z3 (small f so use stripos) will be in the source code. This script runs as a cron job every thirty minutes. If not between $z8 Friday $z4 and $z9 Saturday $z7 exit.
ScienceFriday.log2.html raw data
date_default_timezone_set('America/New_York');$z1=date('h:i:sa'); // 02:50:26am$z8='4pm';$z10='160000'; // START TIME 4pm$z9='7am';$z11='065959'; // END TIME 7AM$z2 = new DateTime();// if not friday {next friday date}else{date}if((date('w')) != 5){$z2->modify('next friday'); // Modify the date it contains$z3=$z2->format('F-j-Y'); // February-18-2022$z4=$z2->format('F j, Y'); // February 18, 2022$z5=$z2->format("Ymj $z10"); // START TIME i.e. 20220218 160000$z2->modify('next saturday');// Modify the date it contains$z6=$z2->format("Ymj $z11"); // END TIME i.e. 20220219 065959$z7=$z2->format('F j, Y'); // February 19 2022}else{ $z3=$z2->format('F-j-Y'); // February-18-2022$z4=$z2->format('F j, Y'); // February 18, 2022$z5=$z2->format("Ymj $z10"); // START TIME i.e. 20220218 160000$z2->modify('next saturday');// Modify the date it contains$z6=$z2->format("Ymj $z11"); // END TIME i.e. 20220219 065959$z7=$z2->format('F j, Y'); // February 19 2022 }echo "Script written to log what time Science Friday recording is put on remote server I have no control of in East Time zone. If the recording is up $z3 (small f so use stripos) will be in the source code. This script runs as a cron job every thirty minutes. If not between $z8 Friday $z4 and $z9 Saturday $z7 exit.
";// BEGIN https://stackoverflow.com/a/19070232/8826818 $Date = new DateTime();echo $Date->format('m/d/Y H:i:s'); // mm/dd/yyyy hhmmss $DateTimeBegin = new DateTime($z5); // format must be yyyymmdd. punctuation optional: i.e. yyyymmdd yyyy-mm-dd or yyyy/mm/dd ...$DateTimeEnd = new DateTime($z6); if ($Date->getTimestamp() > $DateTimeBegin->getTimestamp() && $Date->getTimestamp() < $DateTimeEnd->getTimestamp()){ echo " is between"; $result = file_get_contents('https://www.sciencefriday.com/radio/'); $test = stripos($result, date('F-j-Y')); // case insensitive February-18-2022 if ($test==false) { echo "no. $z3 (small f) does not exist on ScienceFriday."; $fileContent = file_get_contents('ScienceFriday.log2.html'); file_put_contents('ScienceFriday.log2.html', date('h:i:sa').' no. $z3 (small f) does not exist on ScienceFriday ' . $fileContent); } else { echo "yes. $z3 (small f) does exist on ScienceFriday."; $fileContent = file_get_contents('ScienceFriday.log2.html'); file_put_contents('ScienceFriday.log2.html', date('h:i:sa').' yes. $z3 (small f) does exist on ScienceFriday ' . $fileContent); } }else{ echo " is not between. Logging and exiting."; }// END https://stackoverflow.com/a/19070232/8826818 $fileContent1 = file_get_contents('ScienceFriday.log1.html');$fileContent2 = file_get_contents('ScienceFriday.log2.html');file_put_contents('ScienceFriday.log2.html', $z1.' Log of when cron job fires.<br />'. $fileContent2); file_put_contents('ScienceFriday.log.html', $fileContent1. $fileContent2.'</div></body></html>'); exit ;
CST
Most of us are familiar with how a web application works. We know that when we enter an URL in our browser, it’ll contact a web server who’ll returnsome HTML. The browser will then make follow-up requests and then render the web page. (This is a simplification! But that’s the main idea.)
Butwhat’s happening on the web server returning HTML? How is the web server getting the HTML that it returns to our browser? And, to be even more specific, how does this happen in PHP?
Thisisn’t something that most of us know how to answer. We know (or at least should know!) how to build a PHP website. But what happens betweenour PHP code and the browser is a bit of a mystery.
There’sa good chance that you’re thinking, “Well, my site loads. Why should I think twice about this?” And that’s true! But the truth is that knowing how a PHP application works can be useful.
Itcan affect how you design your PHP application. But it’s also importantif you’re looking to improve its performance. For example, it’s hard tounderstand PHP application caching if you don’t understand how a PHP application works.
If you come from a compiled language (like Java or C#), the biggest thing to understand is that PHP isn’t one. It’s an interpreted language. This means that PHP will need to interpret and compile the code of your application for each request made to it.
Now,you can use caching and other optimizations to speed this process up. But the nature of how requests to your PHP application work won’t change. They’ll always look like this:
Asyou can see in the diagram above, we always start with a browser makinga request for a web page. This request is going to hit the web server. The web server will then analyze it and determine what to do with it.
If the web server determines that the request
is for a PHP file (often index.php
),it’ll pass that
file to the PHP interpreter. The PHP interpreter will read the
PHP file, parse it (and other included files) and then execute
it. Once the PHP interpreter finishes executing the PHP file,
it’ll return an output. The web server will take that output and
send it back as a response to the browser.
Thiswas the goal of explaining the life cycle of a PHP request was to get to this statement. This is the truth behind any PHP application whether it’s a Laravel or Symfony application. (Or even a CMS like Drupal or WordPress.) They’re all nothing more than scripts much like a shell script.
Inthis scenario, the web server is nothing more than an intermediary. Each time that someone makes a request for a PHP page, it’s just asking the web server to run a specific PHP script. If the PHP script returns any output, the web server sends it back.
Thisis different to what you’ll see in with other web programming languages. These web programming languages create what we’ll call more traditional web applications. These traditional web applications often work using an application server. Some well-known application servers are Tomcat for Java, IIS for .NET, Gunicorn for Python, Unicorn for Ruby.
Workingwith an application server is different in some fundamental ways. The most important one is that a traditional web application resides within the application server. It’s not a script that your web server can call.In fact, these application servers also act as web servers. The diagrambelow should help you visualize this.
Asyou can see, the web application is inside of the application server. (There can even be more than one web application per application server!) This application server is also your web server. Any request that you make to it is the same as a request to the web application. It’s not an intermediary like it is with PHP.
Thisfundamental difference between a PHP application and more traditional web application is important. It changes a lot of the dynamics around them. For example, this is why you can edit any PHP file on a server andsee the changes right away. (Well, that’s unless you have some caching solution in place!)
Butyou can’t say the same about traditional web applications. These applications often only let you edit template files on the fly. Any other changes will require that you restart the application server at a minimum. (Things get more complicated if you use a compiled language.)
Thatsaid, this isn’t the only difference between a PHP application and a traditional one. There are other differences that are important to know.So let’s look at some of them.
Let’s start with memory management.How do we manage memory when we’re working with a PHP application? The answer is that most of us don’t manage memory when we’re working on a PHP application.
We only do something if PHP gives us an out of memory error. And often we’ll just increase the PHP’s memory limit when we encounter that error. We’ll then move on and continue working on whatever we were working on before we saw the error.
Ifyou’re more performance focused, you’ll try to reduce the memory usage of your code. For example, let’s say that you’re running out of memory storing a big XML file in memory using SimpleXML. You can switch to XMLReader to traverse the XML file instead.
Have you ever encountered a memory leakwith PHP? Memory leaks are the result of improper memory management like our out of memory errors. They happen you persist data in memory and that memory never gets cleared once you’re done with the data.
Thatsaid, memory leaks are quite rare with PHP applications. That’s becausePHP is a script that runs and then terminates. Once terminated, PHP will clear all the memory used by the script. Resetting memory that way prevents most PHP applications from having memory leaks.
Butthis isn’t the case with a more traditional web application. Since the application is part of the web server, it only terminates when you restart the web server itself. This doesn’t (or shouldn’t!) happen very often. This means that memory leaks are a common reality with those types of applications.
Memoryleaks have real consequences with a more traditional web application. If you don’t restart your application server, your server will run out of memory at some point. When that happens, the application server will crash taking your web application with it.
Sowe’re pretty clear on how what memory leaks are and why PHP doesn’t suffer from that problem much. But this isn’t the only unique aspect of memory management in PHP either. PHP also doesn’t have any built-in way to persist data in memory.
Infact, part of the reason why there are few memory leaks in PHP is because of this aspect of memory management in PHP. Let’s imagine that we have two identical requests for our PHP application. The first one runs through our PHP script and stores data in memory in the process. None of that data will be available to the second request.
Thisties to what we explained about PHP scripts earlier. Once the PHP finishes executing a script, the operating system clears the memory thatit used. This means that PHP can’t share data between requests by usingmemory like a traditional web application would.
Instead, PHP depends on other systems to share data between requests. You can use sessions which themselves use a storage method. A storage method could be a file, a data store or even a database.
APHP application tends to make use of one or more of these storage methods. Which ones you use depends on what your application supports and your needs. But, if you have to pick one, using a data store like Redis or Memcached tends to be the most popular option.
Concurrencyis another concept that’s important to understand with PHP applications. What is concurrency? It’s the idea that you can break downsoftware into smaller parts. You can then execute these smaller parts at the same time or in a different order without anything breaking.
Now,explained like this, concurrency doesn’t really make sense with PHP applications. PHP doesn’t break down our application into smaller parts and run them at the same time. That said, concurrency still applies because of how PHP handles multiple requests to an application.
Aswe’ve seen so far, each request made to a PHP application is independent of the other. The web server will pass the request to the PHP interpreter who’ll run the script of our PHP application. This meansthat it’s very common for the PHP interpreter to be processing more than one script at the same time.
Thetimeline above attempts to highlight this using a timeline. We have three concurrent processes of a PHP script. They start and finish at different times, but some of their execution overlaps.
Thisis why you should keep concurrency in mind when working with a PHP application. And concurrency like memory management has more than one implication with PHP. That said, they’re not things that you have to think about all the time. (But it’s still good to know about them!)
Let’s start with multitasking. Multitasking is the idea that you can perform a set of computer tasks faster if you do them at the same time. PHP applications rely on this concept a lot to do computing intensive tasks.
That’sbecause it’s quite easy to implement multitasking in PHP. As we’ve seenalready, it’s possible for the PHP interpreter to process more than onescript at a time. So multitasking comes down to creating requests for these extra tasks that we need to do.
Howdoes this work? Well, as you can see in the above diagram, you have an initial request to your PHP application. This initial request will causethe PHP application to generate other subrequests to itself. These other subrequests are our new application tasks. They run at the same time as our initial request.
It’s worth pointing out that these requests are often sent asynchronously.They don’t have a large impact on the execution time of a PHP script. This means that they don’t slow down the execution of the PHP application during the initial request.
A good example of multitasking in PHP applications is how popular PHP CMSs handle cron jobs.In a CMS, a cron job is a task that you scheduled (like publishing a future post) in the future that you need your CMS to handle. A CMS handles these cron jobs by creating a request for a specific URL whenever you make a request to the CMS.
But concurrency isn’t without issues either. The most common one is resource starvationwhich means exactly what the name suggests. It refers to your concurrent PHP processes not having the resources they need to run well (or at all).
It’sworth pointing out that memory leaks which we saw earlier are a form ofresource starvation. The growing memory leak starves the server’s memory until the application stops working. But, since PHP applications don’t suffer from memory leaks, it’s not the cause of the problem here.
Let’simagine that your server has 300megs of free memory. And your PHP application takes on average 50megs of memory during its execution. Thismeans that, in theory, your server can only handle six concurrent executions.
Sowhat happens if your server needs to process more than six scripts at atime? Well, at this point, it depends on how your host configured your server. It could just slow down or it could outright die. (That’s the idea behind most denial-of-service attacks.)
Thisis why resource starvation isn’t so much of an issue with your PHP application. Yes, you could its reduce memory usage. And, as a result, you’d be able to have more concurrent executions of your PHP application.
Butit would be better to configure your server so that it doesn’t ever tryto do too many concurrent executions. That’s why it’s an important configuration setting for a PHP application server. Resource starvation is more of a server configuration issue than an application issue.
Another issue to be aware of with concurrency is race conditions.A race condition is a bit of a complicated problem that’s easier to explain with an example. A common example of a race condition is tracking page views. That said, most types of tracking are susceptible to race conditions.
Aboveis a timeline of our PHP code that’s tracking the page views. The page view tracking code is in pink. In it, we fetch the current number of page views, increment the number by one and then save the value again. This is all pretty straightforward so far.
Now,let’s add concurrency to the mix! What happens if there are multiple executions of our page view tracking PHP code at the same time? Well, let’s update our timeline and find out.
Everythinglooks ok in this timeline. We have multiple executions of our PHP code,but none of the pink bars overlap. Each execution is able to fetch the current number of page views, increment it by one and then save it again.
Butwhat happens if multiple executions of our PHP code overlap? After all,it’s not realistic to expect our executions to be nice and spread out like that all the time. Well, this is where things start to break down.
Here’sa timeline where our three executions are closer in time to one another. As you can see, the execution of our page view tracking PHP code overlaps now. This code overlap is our race condition.
Becauseof it, the page view increment from the second process is incorrect. That’s because it fetches the page view count before the first process saved it back. So it counts the same number of page views as the first process.
Butthat’s not the end of it either! Because of the race condition, the third process also overwrites the number of page views recorded by the second process. If we had more concurrent processes, this would compoundthe problems caused by the race condition.
Theresult is an inaccurate tracking of the number of page views. Our page view tracking code ended up counting only two page views when it should’ve counted three. That’s a serious problem if you bothered to design such a system.
Sohow do we fix the race condition in our page view tracking PHP code? The obvious solution is to not do it and use an external service like Google Analytics. But that’s not an especially useful solution if you want to learn to fix race conditions!
Well,the problem with race conditions is that there are countless ways to fix them. We can’t cover them all in this article. But let’s not let this prevent us from talking about it a bit!
The key to fixing a race condition is the concept of mutual exclusion. Mutual exclusion is itself a property of larger topic called concurrency control.And the point of concurrency control is to ensure that concurrent operations (like our tracking of page views) generate the correct results.
Now,let’s go back to mutual exclusion. Mutual exclusion is the idea that only one execution can enter a critical piece of code at a time. This prevents race conditions because you can’t have more than one execution of this piece of code at a time.
And how can we implement mutual exclusion with PHP? One of the common ways to implement it is with a lock.You use a lock to limit the access to a resource. In this scenario, this would be the number of page views that we only want one process to access at a time.
Thistimeline shows what happens to our page view tracking code when we use alock. The yellow bar in our timeline represents the time spent waiting for the other execution to release the lock. Our page view tracking codecan only begin when that happens.
But even then, there’s more than one way of implementing a lock! For example, you could use a semaphore. This is a special variable or data type that you can use to determine if a resource is in use or not. There are semaphores in PHP so it’s one option that you have available.
Another option besides using a lock is to use message passing.Message passing revolves around isolating a critical piece of code inside your web application. Once isolated, your code should never make acall to this piece of code ever again. Instead, it should send a message to the web application to run it for you.
So,in the case of our page view tracking code, we would isolate that code inside our application. We would then replace that code with code that sends a message to our application. This message would tell our application to run this code for us.
Buthow is that different from making a call to our page view tracking code? The critical element to message passing is that you send the message outside the current process. Your current process won’t run the critical piece of code that causes the race condition.
Instead,it’s another process that runs it. And that process can enforce mutual exclusion for that critical piece of code. This ends up preventing the race condition.
A lot of PHP applications use a message queueto implement their messaging system. The PHP application will send a message to the message queue. The message queue will then process each message one at a time in the order that it received them.
There are a lot of choices from message queue systems. Some frameworks (such as Laravel)also have their own message queue system. Either way, it’s a great way to implement mutual exclusion inside your PHP application.
Asyou can see, PHP applications are in a category of their own. They don’t quite behave in ways that a lot of web developers are familiar with. This is especially true if they come from other programming languages. (But even PHP developers don’t always know how they work!)
Thatsaid, there are also some common elements with other programming languages. But it’s knowing what’s the same and what’s different that’s important in the end. It’ll help you do a better job architecting your solutions using PHP.
exec("cp -f $HOME/private/2BACKUP\ DOUG/*.* $HOME2/$today/php/2backup\ doug",$out,$err);
ECHO "backup $56/*.* to $HOME2/$today/php/$56/ ";
ECHO "RESULTS IS : ".$err."";
// Clear localhost log every day$headers=get_headers("http://localhost/dfellows.rf.gd/htdocs/site_html/weather-seven-day-forecast-graphicLOG.html", 1);$str=($headers["Last-Modified"]); // Tue, 11 Feb 2020 10:39:44 GMTif ((date('d')) - (substr($str, 5, 2)) >= 2){file_put_contents('weather-seven-day-forecast-graphicLOG.html', '');}
// BEGIN EDIT LOG IF THERE ARE MORE THAN 45 ENTRIESecho '<br />';$z=file_get_contents('weather-seven-day-forecast-graphicLOG.html'); // string // echo gettype($z); if (substr_count($z,'<br />') > 99) { $z = explode('<br />', $z);array_pop($z); // remove last element in array.$z = implode('<br />', $z); // stringfile_put_contents('weather-seven-day-forecast-graphicLOG.html', $z);}echo $z; // display contents of weather-seven-day-forecast-graphicLOG.html// END EDIT LOG IF THERE ARE MORE THAN 45 ENTRIES
$now = time();while ($now + 2 > time()) {echo " ";}
// Add 1 to x five times.$x=0;start:$x++;echo "x=$x\n";if ($x<5) goto start;Output:x=1x=2x=3x=4x=5
$images = ["weather-seven-day-forecast-graphic.png", "weather-seven-day-forecast-graphic.jpg"];foreach ($images as $image) {echo $image ."<br />";}
$content = file_get_contents("weather-seven-day-forecast-graphicURLd.txt");$lines = explode(PHP_EOL, $content);$remaining = array_filter($lines, function($line) {$zm="/".date('m')."/"; // remove lines that do not contain string i.e. /10/return strpos($line, $zm) !== false;});file_put_contents("weather-seven-day-forecast-graphicURLd.txt", implode("\r\n", $remaining), FILE_APPEND);
// Read text file, add one to the value in text file, write text file.$z="\r\nWhat week of the NFL season is it? October 4, 2020 is the beginning of Week 4 of the NFL 2020 season ";$content = file('week.txt'); // read file$zweek = intval($content[0]) + 1; // add 1 to the value on line 1file_put_contents('week.txt', $zweek.$z); // update file
// yesterdayvar date = new Date();date ; //# => Fri Apr 01 2011 11:14:50 GMT+0200 (CEST)date.setDate(date.getDate() - 1); // yesterdaydate ;
new Date().toISOString(
YYYY-MM-DDTHH:mm:ss.sssZ)
If you want to create dates, use arguments.
You can pass in up to seven arguments to create a date/time.
new Date().toLocaleDateString('en-GB').split('/').reverse().join('-'); // = 2022-02-04 yyyymmdd javascript ; new Date().toISOString().split('T')[0]; // = 2022-02-04 yyyymmdd javascript ;
<span id='ct'></span>function display_c() {var refresh = 1000; // Refresh rate in milli secondsmytime = setTimeout('display_ct()', refresh)}function display_ct() {var strcountvar x = new Date()document.getElementById('ct').innerHTML = x.toString().replace(/GMT(.*)/g,"");tt = display_c();}display_ct() ;
<script> /*https://stackoverflow.com/questions/4522213*/ function startTime(){
var today=new Date();var hr=today.getHours();var min=today.getMinutes();
var sec=today.getSeconds();ap=(hr<12)?"<span>am</span>":"<span>pm</span>";
hr=(hr==0)?12:hr;hr=(hr>12)?hr-12:hr;hr=checkTime(hr);min=checkTime(min);
sec=checkTime(sec);document.getElementById("clock").innerHTML=hr+":"+min+":"+sec+""+ap;
var time=setTimeout(function(){startTime()},500);}function checkTime(i){if(i<10){i="0"+i;}return i;}
</script> </head><body onload="startTime()"><span id=clock></span>
rem Count filesFOR /F %%g IN ('DIR /B /A:-D %zfolder%\*.mp4 ^| FIND /V /C "::"') DO set zcount=%%gFOR /F %g IN ('DIR /B /A:-D %zfolder%\*.mp4 ^| FIND /V /C "::"') DO set zcount=%g
rem Concatenate .mp4 with Windows 10 64-bit, cmd and ffmpeg using intermediate .ts filerem get sample .mp4 https://www.vjloops.com/stock-video/circle-flow-offsets-01-138855.htmlrem BEGIN PREPrem make directory mmddyy-hhmmss i.e. 081721-085851FOR /f "TOKENS=1-4" %%g in ('time/T') do set zhhmmss=%%g%%i%TIME:~10,2%FOR /f "TOKENS=1-4" %g in ('time/T') do set zhhmmss=%g%i%TIME:~10,2%set zfolder=%DATE:~-10,2%%DATE:~-7,2%%DATE:~-2,2%-%zhhmmss%md "%zfolder%"for /l %g in (2,1,4) do copy /y "1.mp4" "%zfolder%\%g.mp4"for /l %%g in (2,1,4) do copy /y "1.mp4" "%zfolder%\%%g.mp4"rem END PREPrem BEGIN CONCATENATE for %g in (%zfolder%\*.mp4) do (echo ffmpeg -y -i "%g" -c copy -bsf:v h264_mp4toannexb "%zfolder%\%~ng.ts")for %g in ("%zfolder%\*.ts") do (echo file '%g')>>list.txtrem -crf quality 23 = default, 51 = worst, 0 = best ffmpeg -f concat -safe 0 -i "list.txt" -crf 40 output.mp4rem copy .mp4 to .tsfor %%g in (%zfolder%\*.mp4) do (ffmpeg -y -i "%%g" -c copy -bsf:v h264_mp4toannexb "%zfolder%\%%~ng.ts")rem Make ASCII list of filesfor %%g in ("%zfolder%\*.ts") do (echo file '%%g')>>list.txtffmpeg -f concat -safe 0 -i "list.txt" -c copy output.mp4rem -crf quality 23 = default, 51 = worst, 0 = best ffmpeg -f concat -safe 0 -i "list.txt" -crf 40 output.mp4pause rem END CONCATENATErem CLEAN UPrd /q /s %zfolder%
Here is a brief overview of phases in the batch file line parser:
Phase 0) Read Line:
Phase 1) Percent Expansion:
Phase 2) Process special characters, tokenize, and build a cached command block: This is a complex process that is affected by things such as quotes, special characters, token delimiters, and caret escapes.
Phase 3) Echo the parsed command(s) Only if the command block did not begin with @, and ECHO was ON at the start of the preceding step.
Phase 4) FOR %X variable expansion: Only if a FOR command is active and the commands after DO are being processed.
Phase 5) Delayed Expansion: Only if delayed expansion is enabled
Phase 5.3) Pipe processing: Only if commands are on either side of a pipe
Phase 5.5) Execute Redirection:
Phase 6) CALL processing/Caret doubling: Only if the command token is CALL
Phase 7) Execute: The command is executed
Here are details for each phase:
Note that the phases described below are only a model of how the batch parser works. The actual cmd.exe internals may not reflect these phases. But this model is effective at predicting behavior of batch scripts.
Phase 0) Read Line: Read line of input through first <LF>.
Phase 1) Percent Expansion:
Phase 2) Process special characters, tokenize, and build a cached command block: This is a complex process that is affected by things such as quotes, special characters, token delimiters, and caret escapes. What follows is an approximation of this process.
There are concepts that are important throughout this phase.
The following characters may have special meaning in this phase, depending on context: <CR> ^ ( @ & | < > <LF> <space> <tab> ; , = <0x0B> <0x0C> <0xFF>
Look at each character from left to right:
Phase 3) Echo the parsed command(s) Only if the command block did not begin with @, and ECHO was ON at the start of the preceding step.
Phase 4) FOR %X variable expansion: Only if a FOR command is active and the commands after DO are being processed.
---- From this point onward, each command identified
in phase 2 is processed separately.
---- Phases 5 through 7 are completed for one command before moving
on to the next.
Phase 5) Delayed Expansion: Only if delayed expansion is on, the command is not in a parenthesized block on either side of a pipe, and the command is not a "naked" batch script (script name without parentheses, CALL, command concatenation, or pipe).
Phase 5.3) Pipe processing: Only if commands
are on either side of a pipe
Each side of the pipe is processed independently and asynchronously.
Phase 5.5) Execute Redirection: Any redirection that was discovered in phase 2 is now executed.
Phase 6) CALL processing/Caret doubling: Only if the command token is CALL, or if the text before the first occurring standard token delimiter is CALL. If CALL is parsed from a larger command token, then the unused portion is prepended to the arguments token before proceeding.
Phase 7) Execute: The command is executed
Works like the BatchLine-Parser, except:
Phase 1) Percent Expansion:
Phase 3) Echo the parsed command(s)
Phase 5) Delayed Expansion: only if DelayedExpansion is enabled
Phase 7) Execute Command
There are many different contexts where cmd.exe parses integer values from strings, and the rules are inconsistent:
Details for these rules may be found at Rules for how CMD.EXE parses numbers
For anyone wishing to improve the cmd.exe parsing rules, there is a discussion topic on the DosTips forum where issues can be reported and suggestions made.
Hope it helps
Jan Erik (jeb) - Original author and discoverer of phases
Dave Benham (dbenham) - Much additional content and editing
for %%g in (D E F G H I J K L M N O P Q R S T U V W X Y Z) DO IF EXIST "%%g:\DoNotDeleteFlash4291phIr_Wn.txt" SET zdrive=%%g:
C:\Windows\System32\cmd.exe /k C:\Windows\System32\netsh.exe wlan show interfaces
rename "*" "///*"
jsort file.txt /u >file.txt.new
# BEGIN CMD MAKE FILES FOR TESTING.for %g in (FileGroup000000159.txt,FileGroup000000160.txt,FileGroup000000161.txt,FileGroup000000162.txt,FileGroup000000163.txt,FileGroup000000164.txt,FileGroup000000165.txt) do echo > %g # END CMD MAKE FILES FOR TESTING.
# BEGIN CMD MAKE FILES FOR TESTING.for /f "tokens=*" %g in (file.txt) do echo > %g file.txt = FileGroup000000159.txtFileGroup000000160.txtFileGroup000000161.txtFileGroup000000162.txtFileGroup000000163.txtFileGroup000000164.txtFileGroup000000165.txt# END CMD MAKE FILES FOR TESTING.
For /F %%# In ('PowerShell -NoP "(Get-Date).AddDays(-1).ToString('MM/dd/yy')"') Do Set "zYesterDay=%%#"
Echo(%zYesterDay%
C:\Windows\devcon64.exe disable "USB\VID_148F&PID_3072&REV_0101"
C:\Windows\devcon64.exe enable "USB\VID_148F&PID_3072&REV_0101"
for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do echo "%%~b"
for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do rundll32 printui.dll,PrintUIEntry /e /n %%~b
for /f "tokens=1*" %%a in ('wmic printer get name^, default ^| find /i "TRUE"') do (
set printer=%%brundll32 printui.dll,PrintUIEntry /e /n "%printer: =%"
)
@echo off dir /b /a-d | findstr /n "lnk" >listREM get the total number of filesfor /f %%n in ('type list ^| find /c /v ""') do set total=%%nREM Begin debugREM set totalREM pause REM End debugREM pick random filessetlocal EnableDelayedExpansionfor /l %%n in (1 1 20) do (set /a number=!random!*total/32768+1REM Begin debugREM set numberREM pause REM End debugfor /f "tokens=1* delims=:" %%a in ('findstr "!number!:" "list"') do echo %%b)del listREM
aaa.binaaa.cuebbb.binbbb.cueccc.binccc.cue
for /f %%a in (file.txt) do cd.>%%a
for /f %a in (file.txt) do cd.>%a
Combo: testing123mail@gmail.com:passwordAs Combo: abcdefghijklmnopqrstuvwxyz@gmail.com:ajfbdfsome text heresome more text hereAs Combo: hadvsfhia@ahfjbadj.com:password@1some random text hereiloveu@gmail.com:passypassyword123goldenmammy@hotmail.com:youtube123
@echo offsetlocal enabledelayedexpansionset "_log=.\mail.txt"cmd /v /c cd.>!_log!for /f "tokens=* delims=" %%i in ('type .\file.txt')do echo/%%~i|find "@" >nul && (for /f "tokens=1-3 delims=:" %%I in ('echo/%%~i')do echo/%%~I|find "@" >nul && (set "_m_p=%%~I:%%~J")||set "_m_p=%%~J:%%~K")&& for %%E in ("%%~J")do >>!_log! (echo/!_m_p: =!|find "@")
testing123mail@gmail.com:passwordabcdefghijklmnopqrstuvwxyz@gmail.com:ajfbdfhadvsfhia@ahfjbadj.com:password@1iloveu@gmail.com:passypassyword123goldenmammy@hotmail.com:youtube123
$z2=(get-content $env:userprofile\downloads\$zname`lasttime.txt) -notmatch '(?<!\d)0(?!\d)' ; # gc of all lines that does not have only 0 i.e. Get 160 but not 0.$z=[math]::Ceiling(($z2 | measure -sum | % sum) / [int]$z2.count) ; write-output "`n Average seconds needed: $z"
$z = gc 2.html$z -replace ' data-pf(.+?)>', '>' | sc 2.html
$z = gc 2.html$z -replace ' data-pf(.+?)>', '>' -replace '<em(.+?)>', <em> | sc 2.html
gci *.txt,* -name
(gci *.pdf).name(gci *.pdf).extensiongci *.pdf | % Name #name.extgci *.pdf | % extension #extgci *.pdf | % basename #namegci *.pdf | % fullname #fqpn
foreach($file in gci *){ foreach ($line in $file){ $file.Name $file.baseName $file.fullName }}
Function DisplayInBytes($num) {$suffix = "B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"; $index = 0 ;while ($num -gt 1kb){$num = $num / 1kb;$index++};"{0:N1} {1}" -f $num, $suffix[$index]};foreach ($file in gci *){ foreach ($line in $file){ write-output " Name = $($file.Name) Size = $(DisplayInBytes $file.length)" }}
Function z{Param([string[]]$path,[int]$numberDays)$cutOffDate = (Get-Date).AddDays(-$numberDays)Get-ChildItem -Path $path |Where-Object {$_.LastAccessTime -le $cutOffDate}}z -path F:\xampp\htdocs\dfellows.rf.gd\htdocs\site_html -numberDays 10 | select name, lastaccesstime | sort LastAccessTime
gci *.lnk | Sort lastwritetime | Select-Object lastwritetime,baseName | Format-Table -Wrap
gci *.lnk | Sort lastwritetime -descending | Select-Object lastwritetime,baseName | Format-Table -Wrap
"{0} MB" -f ((Get-ChildItem | Measure-Object -Property Length -Sum -ErrorAction Stop).Sum / 1MB)
files:(gci -file).countfile and folders - recurse(gci -recurse).count
Get-ChildItem *.mp4,ytsearch | Where-Object { ( $_.creationtime -ge $zstart ) }
[System.IO.File]::ReadAllLines
for large
files. # $zStartNFL = ([System.IO.File]::ReadAllLines( "$zdrive\downloads\DoNotDelete\$zScriptName$($z5)start.txt" ))[0]; # $zStartNFL = (gc "j:\downloads\DoNotDelete\103.txtNFLstart.txt")[0];
# https://jordantheitguy.com/2019/06/24/how-to-powershell-progress-bars/$Contents = gci -Path "$zdrive\downloads\downloads" -file;$Destination = "$env:userprofile\downloads";foreach($Item in $Contents){Move-Item -path $Item.FullName -Destination $Destination[int]$currentItem = [array]::indexof($Contents,$Item)Write-Progress -Activity "Moving files" -Status "Moving - $($Item.Name) - File $($currentItem) of $($Contents.Count - 1) $([math]::round((($currentItem + 1)/$Contents.Count),2) * 100)% " -PercentComplete $([float](($currentItem + 1)/$Contents.Count) * 100)Start-Sleep -Seconds 1 }
$z='.mp4'gci * -file -exclude *.* | Rename-Item -NewName { $_.BaseName + $z } -WhatIf
gci $zdrive\downloads\downloads -file | Rename-Item -NewName {$_.name -replace "'",""} ; # Remove apostrophegci $zdrive\downloads\downloads -file | Rename-Item -NewName {$_.name -replace "\[",""};gci $zdrive\downloads\downloads -file | Rename-Item -NewName {$_.name -replace "\]",""};gci $zdrive\downloads\downloads\* -File -Include *.*.* | Rename-Item -NewName { ($_.BaseName -replace '\.') + $_.Extension }; # Remove period from basename
# Move files from flash drive to Downloads.# Find flash drive by searching DriveType 2 for text file.# Strip file name of characters that cause CMD to choke.(Get-WmiObject Win32_Volume -f {Label='Verbatim' and DriveType='2'}).name|foreach-object{if(test-path $_'\DoNotDeleteFlash4291phIr_Wn.txt'){$zdrive="$_"}} ; # Removing illegal / problematic characters from file name;
# "All of these characters should be escaped with a backslash when using a regex in PowerShell: \\ \^ \$ \* \+ \? \period \( \) \| \{ \} \[ \] "
gci $zdrive\downloads\downloads -file | Rename-Item -NewName {$_.name -replace "'",""} ; # Remove apostrophe
# sleep -m 500 ;
gci $zdrive\downloads\downloads -file | Rename-Item -NewName {$_.name -replace "\[",""};
# sleep -m 500 ;
gci $zdrive\downloads\downloads -file | Rename-Item -NewName {$_.name -replace "\]",""};
# sleep -m 500 ;
gci * -File -Include *.*.* | Rename-Item -NewName { ($_.BaseName -replace '\.') + $_.Extension }; # Remove period from basename# Create shortcut to this script # Windows 10 does not know PowerShell variables; it knows CMD variables. Shortcuts containing variables must use CMD variables.# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit %zmyapps1%\WINDOWS\107.ps1# How to move files with CMD # C:\Windows\System32\cmd.exe /k FOR /f "tokens=*" %g in ('dir /b "j:\downloads\downloads\*.*" ') do move /y "J:\downloads\downloads\%g" %userprofile%\downloads\
# BEGIN Find flash drive( Get-WmiObject Win32_Volume -Filter {DriveType='2'} ).name | % { if ( test-path $_'\DoNotDeleteFlash4291phIr_Wn.txt' ) { $zdrive="$_"} } ; # Set flashdrive drive letter by looking for text file on removable drives ; Trim backslash:$zdrive=$zdrive.Trim("\") ;# $z = @('D:','E:','F:','G:','H:','I:','J:','K:','L:','M:','Z:') $z|foreach-object{if(test-path $_'\DoNotDeleteFlash4291phIr_Wn.txt'){$zdrive="$_"}} ; Trim colon:$zdrive.Trim(":") ;CMD: for %%g in (D E F G H I J K L M) DO IF EXIST "%%g:\DoNotDeleteFlash4291phIr_Wn.txt" SET zdrive=%%g:# END Find flash drive
"$zStartNFL`n$zFinishNFL`n$zStartNHL`n$zFinishNHL`n$zStartMLB`n$zFinishMLB`n#NFL, NHL and MLB start / end date." | out-file "$zdrive\Downloads\DoNotDelete\$zscriptname$($z5)start.txt" ;
gv -Exclude pwd,*preference | rv -ea 0
ls env:
gci Env:* | Sort-Object Name | ft -h (format-table hide headers)
gv
See get-help gv
Sunday, ?August ?29, ?2021, ??9 : 12 : 11 AM
get-date "Sunday, August 29, 2021, 9 : 12 : 11 AM"Cannot convert value "Sunday, August 29, 2021, 9 : 12 : 11 AM" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
get-date "Sunday, August 29, 2021, 9 : 12 : 11 AM"Cannot convert value "Sunday, ‎August ‎29, ‎2021, â€â€Ž9 : 12 : 11 AM" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime."
$zstart=$(Get-Date "8/29/2021 9 : 12 : 10 AM")$zequal=$(Get-Date "8/29/2021 9 : 12 : 11 AM")$zend=$(Get-Date "8/29/2021 9 : 12 : 12 AM")$arr = @(gci -file | Sort-Object creationtime | Where-Object {$_.creationtime -like $zequal})$arr = @(gci -file | Sort-Object creationtime | Where-Object {$_.creationtime -gt $zstart -and $_.CreationTime -lt $zend})
# BEGIN HOW TO MAKE FILES WHOSE BASENAME INCLUDES _24_ THE OLDEST.# AddHours(-8) = *_24_*# AddHours(-7) = *_25_*# AddHours(-6) = *_26_*$z=(Get-Date).AddHours(-8) ;$arr = @(gci * -Include '*_24_*')$arr | ForEach {$z = $z.addSeconds(-60) ; $_.LastWriteTime = $z ;}# END HOW TO MAKE FILES WHOSE BASENAME INCLUDES _24_ THE OLDEST.
(Get-Date).AddHours(-6).AddMinutes(-34).AddSeconds(-6)
(Get-Date).AddHours(6).AddMinutes(34).AddSeconds(6)
(get-date -f T) -replace " : ",":"
Format pattern Description d 12/7/2020 ShortDatePattern D Monday, December 7, 2020 LongDatePattern f Monday, December 7, 2020 5 : 49 PM Full date and time (long date and short time) F Monday, December 7, 2020 5 : 49 : 55 PM FullDateTimePattern (long date and long time) g 12/7/2020 5 : 50 PM General (short date and short time) G 12/7/2020 5 : 50 : 14 PM General (short date and long time) m, M December 7 MonthDayPattern o, O Round-trip date/time pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture r, R RFC1123Pattern; with this format pattern, the formatting or parsing operation always uses the invariant culture s SortableDateTimePattern (based on ISO 8601) using local time;
with this format pattern, the formatting or parsing operation always uses the invariant culturet ShortTimePattern T LongTimePattern u UniversalSortableDateTimePattern using the format for universal time display; with this format pattern, the formatting or parsing operation always uses the invariant culture U Full date and time (long date and long time) using universal time y, Y YearMonthPattern
$Files = @(gci *.mp3) if ($Files.length -ne 0) { write-host " .mp3 found."}else{ write-host " No .mp3 found."}
$scriptblock ={ $filename = 'D:\profile\test\summary.txt' $filename2 = 'e:\profile\test\summary.txt' $filename # this feeds $result[0] $filename2 # this feeds $result[1]}$result = Invoke-Command -ScriptBlock $scriptblock $result[0]$result[1]Results:D:\profile\test\summary.txte:\profile\test\summary.txt
$zstart=$(get-date) ;$zinput='public' ;$zdrive='J:' ;$zblock ={ param($zstart, $zinput, $zdrive) "arg1 is $zstart" "arg2 is $zinput" "arg3 is $zdrive"}&$zblock $zstart $zinput $zdrive
function zInput1 ($title,$z1, $z2, $z3,$z4) {# https://techwizard.cloud/2014/03/11/powershell-custom-gui-input-box-for-passing-values-to-variables/[void][System.Reflection.Assembly]::LoadWithPartialName( "System.Windows.Forms") ;[void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.VisualBasic") ;$form = New-Object "System.Windows.Forms.Form";$form.Width = 500;$form.Height = 200;$form.Text = $title;$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;$textLabel1 = New-Object "System.Windows.Forms.Label";$textLabel1.Left = 25;$textLabel1.Top = 15;$textLabel1.Text = $z1;$textLabel2 = New-Object "System.Windows.Forms.Label";$textLabel2.Left = 25;$textLabel2.Top = 50;$textLabel2.Text = $z2;$textLabel3 = New-Object "System.Windows.Forms.Label";$textLabel3.Left = 25;$textLabel3.Top = 85;$textLabel3.Text = $z3;$textLabel4 = New-Object "System.Windows.Forms.Label";$textLabel4.Left = 25;$textLabel4.Top = 120;$textLabel4.Text = $z4;$textBox1 = New-Object "System.Windows.Forms.TextBox";$textBox1.Left = 150;$textBox1.Top = 10;$textBox1.width = 200;$textBox2 = New-Object "System.Windows.Forms.TextBox";$textBox2.Left = 150;$textBox2.Top = 50;$textBox2.width = 200;$textBox3 = New-Object "System.Windows.Forms.TextBox";$textBox3.Left = 150;$textBox3.Top = 90;$textBox3.width = 200;$textBox4 = New-Object "System.Windows.Forms.TextBox";$textBox4.Left = 150;$textBox4.Top = 130;$textBox4.width = 200;$defaultValue = "" ;$textBox1.Text = $defaultValue;$textBox2.Text = $defaultValue;$textBox3.Text = $defaultValue;$textBox4.Text = $defaultValue;$zInput1 = New-Object "System.Windows.Forms.Button";$zInput1.Left = 360;$zInput1.Top = 85;$zInput1.Width = 100;$zInput1.Text = "Ok";$eventHandler = [System.EventHandler]{$textBox1.Text;$textBox2.Text;$textBox3.Text;$textBox4.Text;$form.Close();};$zInput1.Add_Click($eventHandler) ;$form.Controls.Add($zInput1);$form.Controls.Add($textLabel1);$form.Controls.Add($textLabel2);$form.Controls.Add($textLabel3);$form.Controls.Add($textLabel4);$form.Controls.Add($textBox1);$form.Controls.Add($textBox2);$form.Controls.Add($textBox3);$form.Controls.Add($textBox4);$ret = $form.ShowDialog();return $textBox1.Text, $textBox2.Text, $textBox3.Text, $textBox4.Text;} <# End of function #>$return= zInput1 "NFL and NHL start and end dates in mm/dd/yyyy format." "NFL start:" "NFL end:" "NHL start:" "NHL end:";$Script:zNflStart=$return[0];$Script:zNflEnd=$return[1];$Script:zNhlStart=$return[2];$Script:zNhlEnd=$return[3];write "NFL start is: $zNflStart" ;write "NFL end is: $zNflEnd" ;write "NHL start is: $zNhlStart" ;write "NHL end is: $zNhlEnd" ;"$zNflStart`n$zNflEnd`n$zNhlStart`n$zNhlEnd`n#NFL and NHL start / end date. Used by 103.txt and 103.psm1" | out-file "$zdrive\Downloads\DoNotDelete\$zscriptname$($z5)start.txt" ;
Add-Type -AssemblyName PresentationFramework ;# $zarr = @(gci $env:userprofile\downloads\_3videos\temp -file) ; # Create an array of files to download. See below.$zarr = @(gci $env:userprofile\downloads\_3videos\temp -file | Where-Object {($_.creationtime -ge $zstart)} | Sort-Object creationtime -descending) ; switch ( [System.Windows.MessageBox]::Show( 'Would you like to move files to flashdrive\downloads\downloads??', 'QUESTION', 'YesNo', 'QUESTION' )) { 'Yes' {# $zarr | % {$_}$zarr | % {move-item $env:userprofile\downloads\_3videos\temp\$_ $zdrive\downloads\downloads -force ;while (!(Test-Path "$zdrive\downloads\downloads\$_")) { Start-Sleep 1 }}&$zdrive\Downloads\DESKTOPREFRESH ;} ; # END Yes 'No' {$zarr | % {move-item $env:userprofile\downloads\_3videos\temp\$_ $env:userprofile\downloads\_3videos -force ;while (!(Test-Path "$env:userprofile\downloads\_3videos\$_")) { Start-Sleep 1 }&$zdrive\Downloads\DESKTOPREFRESH ; } } ; # END No} ; # END Switchexit ;
Function IsBetweenDates ([Datetime]$start,[Datetime]$end){ $d = get-date ; if (($d -ge $start) -and ($d -le $end)){return $true ;}else{return $false ;}} <# End of function #># if (IsBetweenDates "$zNflStart 12:00:00 AM" "$zNflEnd 12:00:00 PM"){}
gc K:\Downloads\DoNotDelete\archive.txt,C:\Users\_56\AppData\Local\Temp\DoNotDelete\archive.txt | out-file -encoding ascii combine.txt
(gc K:\Downloads\DoNotDelete\archive.txt,C:\Users\_56\AppData\Local\Temp\DoNotDelete\archive.txt) -replace '\t\t ','' | sort | get-unique | out-file -encoding ascii combine.txt
# youtube-dl archive lists: Find unique, output to file and copy# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -ExecutionPolicy Bypass gc "F:\MYAPPS\WINDOWS\102.ps1"|powershell(gc "F:\Users\_9doug\AppData\Local\Temp\DoNotDelete\archive.txt","J:\Downloads\DoNotDelete\archive.txt","Z:\DoNotDeleteArchive.txt") | sort | get-unique | out-file -encoding ascii "combine.txt"copy combine.txt "F:\Users\_9doug\AppData\Local\Temp\DoNotDelete\archive.txt"copy combine.txt "J:\Downloads\DoNotDelete\archive.txt"copy combine.txt "Z:\DoNotDeleteArchive.txt"
(gc K:\Downloads\DoNotDelete\archive.txt,C:\Users\_56\AppData\Local\Temp\DoNotDelete\archive.txt) -replace '\t\t ','' | sort | get-unique | out-file -encoding ascii combine.txt
function Get-StartMenuShortcuts{ $Shortcuts = Get-ChildItem $env:USERPROFILE\Desktop -Include *.lnk $Shell = New-Object -ComObject WScript.Shell foreach ($Shortcut in $Shortcuts) { $Properties = @{ ShortcutName = $Shortcut.Name; ShortcutFull = $Shortcut.FullName; ShortcutPath = $shortcut.DirectoryName Target = $Shell.CreateShortcut($Shortcut).targetpath } New-Object PSObject -Property $Properties }[Runtime.InteropServices.Marshal]::ReleaseComObject($Shell) | Out-Null}$Output = Get-StartMenuShortcuts$Output.Target$Output.shortcutname$Output.shortcutFull
# Concatenate .mp4 with Windows 10 64-bit, powershell 5 and ffmpeg using intermediate .ts file# get sample .mp4 https://www.vjloops.com/stock-video/circle-flow-offsets-01-138855.html# BEGIN PREP$ErrorActionPreference="SilentlyContinue" ; # $ErrorActionPreference = "Continue" ;$z=Get-Date -f 'MMddyy-hhmmss';ni -ItemType Directory "$z" > $null ;# make copies of .mp4 1..3 | foreach { copy-item 1.mp4 "$z\$_.mp4" > $null}# END PREP# BEGIN CONCATENATE # copy .mp4 to .tsforeach ($i in gci "$z\*.mp4" | % basename) {ffmpeg -y -i "$z\$i.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts "$z\$i.ts"}# http://trac.ffmpeg.org/wiki/Concatenate# Create ASCII list of files for ffmpeg -i input in format "file 'directory\name' = file '081721-015117\3.ts'remove-item "$z\list3.txt" # next line out-file must use -append AND must use -Encoding ASCIIforeach ($i in gci "$z\*.mp4" | % name) {echo "file '$z\$i'" | out-file "$z\list3.txt" -append -Force -Encoding ASCII}# http://trac.ffmpeg.org/wiki/Concatenate&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" "$env:userprofile\desktop\NotifyAnimation.mp4"# reduce quality from default of 23 to 30. 51= worst 0 = best.#&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" -crf 30 "$env:userprofile\desktop\NotifyAnimation.mp4"#&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" -crf 40 "$env:userprofile\desktop\NotifyAnimation.mp4"# END CONCATENATE#CLEAN UPri "$z" -Recurse -confirm
$zpass = ConvertTo-SecureString "PasswordGoesHere" -AsPlainText -Force$z = New-Object System.Management.Automation.PSCredential ("dfellows2@gmail.com", $zpass)Send-MailMessage -SmtpServer smtp.gmail.com -Credential $z -UseSsl -From 'dfellows2@gmail.com' -To '2125551212@vmobl.com' -Subject 'This is the subject' -body 'This is the body'
$zpass = ConvertTo-SecureString "PasswordGoesHere" -AsPlainText -Force$z = New-Object System.Management.Automation.PSCredential ("dfellows2@gmail.com", $zpass)Send-MailMessage -SmtpServer smtp.gmail.com -Credential $z -UseSsl -From 'dfellows2@gmail.com' -To '2125551212@txt.att.net' -Subject 'This is the subject' -body 'This is the body'
$zpass = ConvertTo-SecureString "PasswordGoesHere" -AsPlainText -Force$z = New-Object System.Management.Automation.PSCredential ("dfellows2@gmail.com", $zpass)Send-MailMessage -SmtpServer smtp.gmail.com -Credential $z -UseSsl -From 'dfellows2@gmail.com' -To @('dfellows2@gmail.com','2125551212@vmobl.com','2125551212@txt.att.net') -Subject 'This is the subject' -body 'This is the body'
$body = @'
Firstname | Lastname | Age |
---|---|---|
Jill | Smith | 50 |
Eve | Jackson | 94 |
'@# Separate -To addresses w/ apostropes and commas: -To
@('xyz2@gmail.com','xyz@juno.com','xyz8@juno.com')$zpass = ConvertTo-SecureString
"PasswordGoesHere" -AsPlainText -Force$z = New-Object System.Management.Automation.PSCredential
("dfellows2@gmail.com", $zpass)Send-MailMessage -SmtpServer
smtp.gmail.com -Credential $z -UseSsl -From 'dfellows2@gmail.com'
-To @('dfellows2@gmail.com') -Subject 'This is the subject'
-body $body -BodyAsHtml
Send-MailMessage -To 'dfellows2@gmail.com' -From 'dfellows2@gmail.com' -Subject 'test powershell' -Body 'test powershell' -Credential 'dfellows2@gmail.com' -SmtpServer 'smtp.gmail.com' -Port 587 -usessl
Send-MailMessage -To 'dfellows2@gmail.com' -From 'dfellows2@gmail.com' -Subject 'test powershell' -Body 'test powershell' -Attachments 'C:\file.doc','D:\report.xlsx' -Credential 'dfellows2@gmail.com' -SmtpServer 'smtp.gmail.com' -Port 587 -usessl
Get-ChildItem -Path 'C:\MyFiles' | Send-MailMessage -To 'dfellows2@gmail.com' -From 'dfellows2@gmail.com' -Subject 'test powershell' -Body 'test powershell' -Credential 'dfellows2@gmail.com' -SmtpServer 'smtp.gmail.com' -Port 587 -usessl
# Convert .mp4 that begins with character 'a' to .mp3 using PowerShell 5 and ffmpeg.gci a*.mp4 | % { & ffmpeg -y -i $_ -metadata title="$($_.basename).mp3" -metadata album="(1Radio)" -metadata artist="YouTube" -metadata publisher="Youtube" "$($_.basename).mp3"} ;gci a*.mp4 | % { "$($_.basename).mp3"$($_.basename)"2$($_.name)"} ;
# Replace - metadata title with file name or basename using PowerShell 5 and ffmpeg.# FFmpeg cannot edit existing files in-place.gci | % { & ffmpeg -y -i $_ -metadata title="$($_.name)" -metadata album="Mad Men" -c copy "2$($_.name)"ri $_ ;rename-item 2$_ $_ ;} ;# Another approach$ztimestamp1=Get-Date -f 'ddhhmmss' ;ni -ItemType Directory "$ztimestamp1" -force | OUT-NULL ; # See _57 or _54.txtgci | % { & ffmpeg -y -i $_ -metadata title=$($_.name) -metadata album="Mad Men5" -c copy "$ztimestamp1\$($_.name)"move-item "$ztimestamp1\$($_.name)" $_ -Force ;} ;ri $ztimestamp1 ;
# Replace - metadata title with file basename using PowerShell 5 and ffmpeg.# FFmpeg cannot edit existing files in-place.gci | foreach { $z2=$_.basename ;& ffmpeg -y -i $_ -metadata title="$z2" -metadata album="Introduction to the Old Testament (Hebrew Bible) (RLST 145) Yale University" -metadata artist="Christine Hayes. Professor of Religious Studies in Classical Judaica at Yale University" -metadata publisher="Youtube - Yale Courses" -c copy 2$_ri $_ ;rename-item 2$_ $_ ;} ;
powershell -command "get-childitem "PATH-TO-ROOT-FOLDER-HERE" |? {$_.psiscontainer -and $_.lastwritetime -lt (get-date).adddays(-14)} |% {remove-item $_ -recurse -force -whatif}"
# you are using "pushd" aren't you? popd before remove-item.popd ;ri -recurse -force $env:userprofile\Downloads\$ztimestamp1 ; # See flash\downloads\_29.ps1
# REMOVE EVERY LINE FROM TEXT FILE THAT DOES NOT CONTAIN TEXT1, TEXT2. OUTPUT W/ OR W/O NEWLINE.CLS$z=@('doug','$window','$23@','$20','$1+$0','$5.50','$2.19).','$USER:$GROUP','$a')$z|out-file doug.txt(Get-Content doug.txt) | Where-Object { $_ -notmatch 'doug|TEXT1|TEXT2' } | Set-Content doug2.txt;write-output "Contents of doug.txt:";gc doug.txt;write-output "Contents of doug.txt with doug removed:";gc doug2.txt;#
# REMOVE ELEMENT FROM ARRAY AND OUTPUT TO TEXT FILE W/ OR W/O NEWLINECLS$z=@('doug','$window','$23@','$20','$1+$0','$5.50','$2.19).','$USER:$GROUP','$a')write-output "Contents of array:";$z | foreach{Write-Host $_}; # with newline. w/o newline ,$z | foreach{Write-Host $_};write-output "Array with doug removed";$z=$z | foreach{$_ | Where-Object { $_ -notmatch 'doug|TEXT1|TEXT2' }};$z;$z | out-file doug2.txt;write-output "Contents of doug2.txt produced with array:";gc doug2.txt;write-output "";#
$z=@('doug','$window','$23@','$20','$1+$0','$5.50','$2.19).','$USER:$GROUP','$a')$z|out-file doug.txt(gc doug.txt).Split()| Where-Object {$_ -like "$*"}
ORparam(
[string]$file = "$env:userprofile\Desktop\2.txt",
[string]$pattern = "$*"
)
(Gc $file).Split()| Where-Object {$_ -like $pattern}
$z=@('doug','$window','$23@','$20','$1+$0','$5.50','$2.19).','$USER:$GROUP','$a')$z|out-file doug.txt(gc doug.txt) | select-string -SimpleMatch '$'
Do not use -raw:
$z=@('doug','$doug','do$ug','doug$','$USER:$GROUP','$a')$z|out-file doug.txt(gc doug.txt) | select-string -SimpleMatch '$'
file.log:
Opening track for playback: "D:\Music\musicfile1.m4a"
Opening track for playback: "D:\Music\musicfile2.mp3"
Opening track for playback: "D:\Music\musicfile3.wav"
Opening track for playback: "D:\Music\musicfile4.mid"
Opening track for playback: "D:\Music\musicfile5.MINIGSF"
Opening track for playback: "D:\Music\musicfile6.AIMPPL"
Opening track for playback: "D:\Music\musicfile7.L"
Opening track for playback: "D:\Music\musicfile8.ACD-ZIP"
Opening track for playback: "D:\Music\musicfile.m4a"
Path to file.log:
$HOME\Documents\file.log
What I want to extract from the last line:
musicfile
Long:
(Get-Content -Path $HOME\Documents\file.log | Select -Last 1) -match '.+\\([\w\s]+).+' $matches[1] | out-file $HOME\Documents\file2.log -append -encoding ascii
Short:
(gc "$HOME\Documents\file.log")[-1] -match '.+\\([\w\s]+).+' $matches[1] | out-file $HOME\Documents\file2.log -append -encoding ascii
(gc "$HOME\Documents\file.log")[-1].split('"')[1].split('\')[-1].split('.')[0]
$z=get-dategci *.lnk | ForEach-Object{$_.LastWriteTime = $z$z = $z.addSeconds(1)$_.LastWriteTime}
Get-ChildItem *.jpg | ForEach-Object{$_.CreationTime = $_.LastWriteTime} Get-ChildItem *.mkv | ForEach-Object{$_.CreationTime = $_.LastWriteTime}
# Windows 10 64-bit. Powershell 5.1 # New-item directory\directory name last ten days pushd $env: userprofile\Desktopforeach($i in -10..-1){$z=(Get-Date).AddDays($i).tostring("MMddyy")ni -itemtype directory "$z\livebolivar.com\New Folder" > $nullni -itemtype file "$z\livebolivar.com\New Folder\test.txt" > $null}popd exit #
ri -Recurse "$env:userprofile\Downloads\_4Documents2" -whatif
"F:\MYAPPS\USERS\_9doug\011220, 011920, 020520, 020620, 020720, 020820, 020920, 021020, 021120, 021220, 021320, 021420, 021520, 021620, 021720, 021820, 021920, 022020, 022120, 022220, 022320, 022420, 022520, 022720, 022820, 022920, 030120, 030220, 030320, 030420, 030520, 030620, 030720, 030820, 030920, 031020, 031120, 031220, 031320, 031420, 111718, 111818, 111918, 112018, 112118, 112218, 112318\livebolivar.com"
gci F:\MYAPPS\USERS\_9doug\*\livebolivar.com | % {ri $_.fullname -recurse -force -whatif}
Windows 10 64-bit. PowerShell 5.1
Parse basename to first dot. Update X archives with Y files using gci, regex, $Matches, foreach {$_, PadLeft}, Compress-Archive, and Remove-Item.
Update X archives with Y files using gci, regex, $Matches, foreach {$_ PadLeft}, Compress-Archive, and Remove-Item. Files and archives are in the same directory. Avg. 29ms to archive 9 text files (48KB) into 3 .zip files on 20 runs. Is there a faster way?
For testing clear your desktop. There should be no .txt or .zip files on your desktop. There are 3 Remove-Item without -whatif or -confirm. Makes 9 text files for testing. Credit to rokumaru
1.1.txt, 1.1.3.txt and 1.txt go in FileGroup0000000001.zip
11.txt and 11.1.txt goes in FileGroup0000000011.zip
2.1.3.6.txt, 2.1.3.6.7.txt, 2.1.txt, and 2.txt go in FileGroup0000000002.zip
Script:
pushd $env:USERPROFILE\Desktop
ni @("1.1.txt", "1.txt", "11.txt", "2.1.3.6.txt", "2.1.txt","2.txt") > $null
gci *.txt | where BaseName -match "^(\d+)(\.\d+)*$" | group { $Matches[1] } | foreach {
$dest = 'FileGroup' + $_.Name.PadLeft(10, "0") + ".zip"
Compress-Archive $_.Group $dest -ea Stop -update ri $_.Group}
ni @("1.1.3.txt", "11.1.txt", "2.1.3.6.7.txt") > $null
gci *.txt | where BaseName -match "^(\d+)(\.\d+)*$" | group { $Matches[1] } | foreach {
$dest = 'FileGroup' + $_.Name.PadLeft(10, "0") + ".zip"
Compress-Archive $_.Group $dest -ea Stop -update ri $_.Group}
Read-Host @"
Delete all FileGroup*.zip is next. There should be nine files in three archives.
Press enter key to delete all test files "@
ri FileGroup*.zip clear-variable -name ("Matches", "dest")
popd
#
Parse file path, name, basename with more than one dot with powershell.
1..5 | % { ni "$env:USERPROFILE\desktop\$_.mkv"} | out-null
# BEGIN POWERSHELL MAKE FILES FOR TESTING. Makes filegroup000000159.txt - 165.txt
159..165 | ForEach-Object {
$zippedFile = 'FileGroup{0:000000000}' -f $_
New-Item -itemtype file -path $env:USERPROFILE\Desktop\$zippedFile.txt
}
# END POWERSHELL MAKE FILES FOR TESTING. Makes filegroup000000159.ZIP - ZIP.txt# BEGIN MAKE ZIPFILE stackoverflow
159..165 | ForEach-Object {
$zippedFile = 'FileGroup{0:000000000}' -f $_
Compress-Archive "$env:USERPROFILE\Desktop\$zippedFile.txt" -DestinationPath "$env:USERPROFILE\Desktop\$zippedFile.zip" -forceRemove-item "$env:USERPROFILE\Desktop\$zippedFile.txt" -whatif
}
# END MAKE ZIPFILE https://stackoverflow.com/a/60586689/8826818
# gci "$zdrive\Downloads\DoNotDelete\$zScriptName$($z5)start.txt" | Where-Object { $_.creationTime -le (get-date).adddays(-180) } | Remove-Item ;# gci "$zdrive\Downloads\DoNotDelete\$zScriptName$($z5)start.txt" | Where-Object { $_.creationTime } | select creationtime ;
Add-Type -AssemblyName System.Drawing$imagesToDelete = Get-ChildItem . | Where-Object {try { $pic = [System.Drawing.Image]::FromFile($_.FullName)# We only want images that are _not_ 1920px wide$pic.Width -ne 1920}catch{# Ignore errors (== probably not an image)}finally {# Clean upif($pic -is [IDisposable]){$pic.Dispose()}}}#
Add-Type -AssemblyName System.Drawing$imagesToDelete = Get-ChildItem . |Where-Object {try {$pic = [System.Drawing.Image]::FromFile($_.FullName)# We only want images that are / are not 800x600$pic.Width -eq 800$pic.Height -eq 600 # $pic.Width -ne 800# $pic.Height -ne 600 }catch{# Ignore errors (== probably not an image)}finally {# Clean upif($pic -is [IDisposable]){$pic.Dispose()}}}$imagesToDelete | Remove-Item
$z = Invoke-WebRequest http://localhost/dfellows.rf.gd/htdocs/site_html/weather.html$z.Links$z.Links.Count$z.Links.outerhtml
Greedy and lazy quantifiers explained
regex101.com is your friend
Copy and paste into PowerShell 5.1. It will output everything between <body></body>. The results outputs twice. Once without the body tags and once with.
$testhtml = @'<!doctype html><html lang="en"><head><meta charset="utf-8"><title>AdminWeb</title><base href="/wwwroot/admin-web/"><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="icon" type="image/x-icon" href="favicon.ico"></head><body><app-root></app-root><script src="/wwwroot/admin-web/runtime.js"></script><script src="/wwwroot/admin-web/file1.js" nomodule></script><script src="/wwwroot/admin-web/file2.js"></script><script src="/wwwroot/admin-web/styles.js"></script><script src="/wwwroot/admin-web/vendor.js"></script><script src="/wwwroot/admin-web/main.js"></script></body></html>'@ $testhtml -match '(?s)(?<=<body>).+?(?=<\/body>)';$matches[0] $testhtml -match '(?s)(<body>).+?(<\/body>)';$matches[0]
[regex]::matches($testhtml,'(?s)(?<=<body>).+?(?=<\/body>)').Value [regex]::matches($testhtml,'(?s)(<body>).+?(<\/body>)').Value
(gc -Raw test.html) -match '(?s)(?<=<body>).+?(?=<\/body>)';$matches[0] [Regex]::Matches((gc -Raw test.html), '(?s)(?<=<body>).+?(?=<\/body>)').Value gc test.html -Raw | Select-String '(?s)(?<=<body>).+?(?=<\/body>)' -AllMatches | % { $_.Matches } | % { $_.Value }
gc test.html -Raw | Select-String '(?s)(?<=<body>).+?(?=<\/body>)' -AllMatches | % { $_.Matches } | % { $_.Value } | sc results.html
$testhtml = Invoke-WebRequest -Uri http://www.pgatour.com
$testhtml -match '(?s)(?<=<body>).+?(?=<\/body>)'
$matches[0]
$testhtml -match '(?s)(<body>).+?(<\/body>)'
$matches[0]
$testhtml = Invoke-WebRequest -Uri http://www.pgatour.com
$testhtml -match '(?s)(?<=<body>).+?(?=<\/body>)'
$matches[0] | sc results.html$testhtml -match '(?s)(<body>).+?(<\/body>)'
$matches[0] | sc results.html
$testhtml = Invoke-WebRequest -Uri http://www.pgatour.com
$testhtml -match '(<div class="success-message">)(?s).+?(<\/div>)'
$matches[0]Invoke-WebRequest -Uri http://www.pgatour.com | sc results.html
(gc -raw results.html) -match '(<div class="success-message">)(?s).+?(<\/div>)'
$matches[0]
$response = Invoke-WebRequest -Uri http://www.pgatour.com
$response.ParsedHtml.body.getElementsByClassName('success-message')
$( $response.ParsedHtml.getElementsByTagName('div') | ?{$_.className -eq 'success-message'} ).outerHTML
$( $response.ParsedHtml.body.getElementsByTagName('div') | Where {$_.getAttributeNode('class').
Game Highlights (Week 4) | NFL 2020
is the most unique pattern in the source.
Of 256k characters it only occurs once. The playlistId occurs
after list= and before ","webpagetype
"runs":[{"text":"Baldy Breakdowns | NFL","navigationEndpoint":{"clickTrackingParams":"CEAQljUYACITCLnRyYi8oewCFTDDFgkdFiYOzTIJYzQtdmlkZW9zWhhVQ0RWWVE0WmhibTNTMmRsejdQMUdCRGc=","commandMetadata":{"webCommandMetadata":{"url":"/watch?v=z5xm1yUnF_A\u0026list=PLRdw3IjKY2gkxzCrNTjJ64jnCc6ZLjkg4","webPageType":"WEB_PAGE_TYPE_WATCH","rootVe":3832}},}}]"runs":[{"text":"Game Highlights (Week 4) | NFL 2020","navigationEndpoint":{"clickTrackingParams":"CDUQljUYDyITCKnihZHZnuwCFdXhggodkEkDEzIJYzQtdmlkZW9zWhhVQ0RWWVE0WmhibTNTMmRsejdQMUdCRGc=","commandMetadata":{"webCommandMetadata":{"url":"/watch?v=qAZj4vQRleo\u0026
list=
PLRdw3IjKY2gmo2FVKs1NlGtfQX6FB_JkE
","webPageType
":"WEB_PAGE_TYPE_WATCH","rootVe":3832}},}}]
https://www.bing.com/search?&q=nfl+2020+schedule
# BEGIN Get the YouTube channel NFL "Game Highlights (Week X)" playlistId with $env:windows2\_27.ps1# Get the start date of the NFL season into a text file so you can use the text file to determine the week of the season next week.if(!(Test-Path $env:windows2\_27.ps1NFLstart.txt)) {$zyear=get-date -Format "yyyy"start "https://www.bing.com/search?&q=NFL+$zyear+schedule"$zstart=Read-Host -Prompt 'Go to the browser, get the start date of the NFL season, close the browser and enter the start date into this window (mm/dd/yy i.e. 09/10/20) 'if ($zstart) {$zstart|out-file $env:windows2\_27.ps1NFLstart.txtWrite-output "The start date of the NFL season in mm/dd/yy format. See _27.ps1" | add-content $env:windows2\_27.ps1NFLstart.txt} else {Write-Host "You must enter the start date. Script will exit in 60 seconds."start-sleep 60exit }}$zyear=get-date -Format "yyyy"$zstart=gc $env:windows2\_27.ps1NFLstart.txt -first 1 ; # load start date into memory$zweek=New-TimeSpan -Start $zstart -End (get-date -format MM/dd/yy) ; # how many days have passed since the season began?# $zweek.days / 7 ; # Display how many weeks have passed since the season began.if(($zweek.days / 7) -match '\.'){$zweek=[math]::ceiling($zweek.days / 7)}else{$zweek=($zweek.days / 7 + 1)} ; # If $zweek has a decimal round $zweek up even if the fraction is < .5 If it is an integer add one to it.$zweek=[int]$zweek ; # The week of the season as an integer.# $zweek ; # Display the week of the season.if ($z0 -eq "Fri" -or $z0 -eq "Mon" -or $z0 -eq "Tue"){$z=Invoke-restmethod https://www.youtube.com/c/NFL/playlists; # If it is Fri or Mon or Tue load the youtube page containing the playlistId into memory.$z=$z -replace "[^a-zA-Z0-9_-]" ; # Strip out all non-word characters except underscore and hyphen$z -match "(?s)GameHighlightsWeek$zweekNFL$zyear.+?list(.+?)webPageType" | out-null ; # Match the playlistId with a regular expression. The Id is captured by (.+?). See Explanation of the regular expression by Regex Buddy below.$zid=$matches[1]; # The playlistIdWrite-host "$zid is the playlistId of the playlist `"Game Highlights Week ($zweek) NFL | $zyear`""; # Display the playlistId#pushd "$env:userprofile\downloads\_1nfl" # Change to directory $env:userprofile\downloads\_1nfl$host.ui.rawui.WindowTitle = "This is _27.ps1. First $z0 $zid" #powershell window title for first pass# youtube-dl --download-archive $env:temp2\archive.txt --playlist-items 1-16 $zidyoutube-dl --download-archive $env:temp2\archive.txt "$zid" # Download all the videos in the playlist (~15)$host.ui.rawui.WindowTitle = "This is _27.ps1. Second $z0 $zid" #powershell window title for second passwhile (test-path *.part){# youtube-dl --download-archive $env:temp2\archive.txt --playlist-items 1-16 $zidyoutube-dl --download-archive $env:temp2\archive.txt "$zid" # While loop to restart download at point where download failed until download successful.popd # Return to directory before pushd}}## END Get the YouTube channel NFL "Game Highlights (Week X)" playlistId
Work local:
$html = @'<!doctype html><html style="font-size: 10px;font-family: Roboto, Arial, sans-serif;" lang="en-US" dir="ltr" gl="US"><head>{"runs":[{"text":"Can't-Miss Plays (Week 4) | NFL 2020","navigationEndpoint":{"clickTrackingParams":"CEQQljUYACITCKnihZHZnuwCFdXhggodkEkDEzIJYzQtdmlkZW9zWhhVQ0RWWVE0WmhibTNTMmRsejdQMUdCRGc=","commandMetadata":{"webCommandMetadata":{"url":"/watch?v=359dcOIvOZ0\u0026list=PLRdw3IjKY2gn8JlCazlMFvhxDp0QIbrFY","webPageType":"WEB_PAGE_TYPE_WATCH","rootVe":3832}},"watchEndpoint":{"videoId":"359dcOIvOZ0","playlistId":"PLRdw3IjKY2gn8JlCazlMFvhxDp0QIbrFY","params":"OAI%3D"}}}]}{"runs":[{"text":"Game Highlights (Week 4) | NFL 2020","navigationEndpoint":{"clickTrackingParams":"CDUQljUYDyITCKnihZHZnuwCFdXhggodkEkDEzIJYzQtdmlkZW9zWhhVQ0RWWVE0WmhibTNTMmRsejdQMUdCRGc=","commandMetadata":{"webCommandMetadata":{"url":"/watch?v=qAZj4vQRleo\u0026list=PLRdw3IjKY2gmo2FVKs1NlGtfQX6FB_JkE","webPageType":"WEB_PAGE_TYPE_WATCH","rootVe":3832}},"watchEndpoint":{"videoId":"qAZj4vQRleo","playlistId":"PLRdw3IjKY2gmo2FVKs1NlGtfQX6FB_JkE","params":"OAI%3D"}}}]}</body></html>'@$zyear=get-date -Format "yyyy"$zstart=gc $env:windows2\_27.ps1NFLstart.txt -first 1 ; # load start date into memory$zweek=New-TimeSpan -Start $zstart -End (get-date -format MM/dd/yy) ; # how many days have passed since the season began?# $zweek.days / 7 ; # Display how many weeks have passed since the season began.if(($zweek.days / 7) -match '\.'){$zweek=[math]::ceiling($zweek.days / 7)}else{$zweek=($zweek.days / 7 + 1)} ; # If $zweek has a decimal round $zweek up even if the fraction is < .5 If it is an integer add one to it.$zweek=[int]$zweek ; # The week of the season as an integer.# $zweek ; # Display the week of the season.if ($z0 -eq "Fri" -or $z0 -eq "Mon" -or $z0 -eq "Tue"){$z=Invoke-restmethod https://www.youtube.com/c/NFL/playlists; # If it is Fri or Mon or Tue load remote NFL source file into memory.$z=$z -replace "[^a-zA-Z0-9_-]" ; # Strip out all non-word characters except underscore and hyphen$z -match "(?s)GameHighlightsWeek$zweekNFL$zyear.+?list(.+?)webPageType" | out-null ; # Match the playlistId with a regular expression. The Id is captured by (.+?)$zid=$matches[1]; # The playlistIdWrite-host "$zid is the playlistId of the playlist `"Game Highlights Week ($zweek) NFL | $zyear`""; # Display the playlistId#
Options: case insensitive
Powershell default file sort is oldest files first:
gci -file | Sort-Object creationtime | select name,creationtime
Sort by newest file
gci -file | sort -desc creationtime | select name,creationtime
Write new creationtime. Each file is one minute newer. Force causes gci to include hidden files.
$z=get-date$arr = @(gci -force | Sort-Object creationtime)$arr | ForEach {$_.CreationTime = $z$z = $z.addMinutes(-1)}
(gci *searchyoutube*.lnk) | Rename-Item -NewName {$_.name -replace "SearchYouTube","DownLoadYoutube"}
gci $env:userprofile\pictures -Filter *.jpg -File | Rename-Item -NewName { $_.BaseName.Split(',')[0] + $_.Extension } -WhatIf
$z=gci * | Measure-Object | %{$_.Count}if ($z -gt 9){$i = [ref]10}if ($z -gt 99){$i = [ref]100}if ($z -gt 999){$i = [ref]1000}gci *.mp3 | Sort lastwritetime | rename-item -NewName {'a{0}{1}' -f $i.value++, $_.Name} -whatif
$delim = "."gci * -Name | `foreach { $nameArray = $_.Split($delim)$newname = $nameArray[1]+"."+$nameArray[2] -replace " ", ""$newName = $newName -replace ",", ""$newName = $newName -replace ";", ""$newName = $newName -replace "\(",""$newName = $newName -replace "\)",""Write-Output $newNamerename-item $_ $newName -whatif}
$z2=(get-content $env:userprofile\downloads\$zname`lasttime.txt) -notmatch '`(`?<!`\d`)0`(?!`\d`)' ; # gc of all lines that does not have only: 0 i.e. Get 160 but not 0. $z=[math]::Ceiling(($z2 | measure -sum | % sum) / [int]$z2.count) ; write-output "`n Average seconds needed: $z"
See "G:\MYAPPS\WINDOWS\_46.ps1" on laptop and thumb drive.
See Expresso regex tester project file "C:\Users\_56\Documents\Expresso Projects\_playlistIdYouTube2022NFLGameHighlights.xso" on laptop
Pattern:
playlistId((?:(?!playlistId).)*?)(?:(?!.thumbnailthumbnail.*runstext).)*?2022NFLWeek9GameHighlights
"playlistId((?:(?!playlistId).)*?)(?:(?!.thumbnailthumbnail.*runstext).)*?$zseason$zleague`Week$zweek`GameHighlights"
Explanation:
|
Windows 10. Powershell 5.Regular expression that works in both Powershell 5 and Notepad++ v8.1.4 (32-bit) Build time : Aug 21 2021 - 12:58:42A ~329K string (DOCTYPE html) is added to every few days.SNL Season 47 Episode 5 only occurs once.PlaylistRendererplaylistId occurs many times.Regular expression in Powershell 5 to match PLS_gQd8UB-hJqEpQXXHi5axYnKJ0nrIsURegex:PlaylistRendererplaylistId((?:(?!PlaylistRendererplaylistId).)*?)((?:(?!.thumbnailthumbnail.*runstext).)*?)SNL Season 47 Episode 5String:PlaylistRendererplaylistIdPLS_gQd8UB-hKj8u3SsdIFJQj7nGJxr_tQthumbnailthumbnailsurlhttpsiytimgcomviAIuWQ41m7yshqdefaultjpgsqp-oaymwEXCOADEI4CSFryq4qpAwkIARUAAIhCGAEu0026rsAOn4CLBR9e9TcJsxqvgT-fXtdGZJLNSgcgwidth480height270titlerunstextPleaseDontDestroyPlaylistRendererplaylistIdPLS_gQd8UB-hJqEpQXXHi5axYnKJ0nrIsUthumbnailthumbnailsurlhttpsiytimgcomviCU-WdnXJabshqdefaultjpgsqp-oaymwEXCOADEI4CSFryq4qpAwkIARUAAIhCGAEu0026rsAOn4CLDqZkaq-158Q0JCgIbgpPLgK2HA6gwidth480height270titlerunstextSNL Season 47 Episode 5
Matches, but is there a better way? A more logical way? For example this regex does not work in Notepad++
Demo at regex101.com
Powershell 5: # ~16 videos ; $z = Invoke-RestMethod https://www.youtube.com/snl/playlists ; $z = $z -replace "[^a-zA-Z0-9 _-]" ; # Strip out all non-word characters except whitespace, underscore and hyphen # $z2=get-date -f 'ddhhmmss' ; # Create a unique file basename # $z|out-file "$z2.txt" ; # Save page to local file # $z=gc "$z2.txt" ; # Load local file # BEGIN What Season (Year) of SNL? $zyear='10/11/1975' ; $zyear = New-TimeSpan -Start $zyear -End (Get-Date -Format MM/dd/yy) ; # What Season (Year) of SNL? ; $zyear ; $zyear.days / 365 ; if (($zyear.days / 365) -match '\.') { $zyear = [string][math]::Ceiling($zyear.days / 365) } ; $zyear ; # END What Season (Year) of SNL? # BEGIN What Episode (Week) of the Season (Year) of SNL? $zweek='10/02/2021' ; $zweek = New-TimeSpan -Start $zweek -End (Get-Date -Format MM/dd/yy) ; # What Episode (Week) of the Season? $zweek ; $zweek.days / 7 ; if (($zweek.days / 7) -match '\.') { $zweek = [string][math]::Floor($zweek.days / 7) } ; $zweek ; # END What Episode (Week) of the Season (Year) of SNL? $z -match "PlaylistRendererplaylistId((?:(?!PlaylistRendererplaylistId).)*?)((?:(?!.thumbnailthumbnail.*runstext).)*?)SNL Season $zyear Episode $zweek" | Out-Null ; $zid = $matches[1] ; # The playlistId $zid ;
"DirName1"="e:\\Program Files\\Jasc Software Inc\\Paint Shop Pro 7\\Shapes""DirName2"="e:\\Program Files\\Jasc Software Inc\\Paint Shop Pro 7\\Brushes""DirName3"="d:\\Program Files (x86)\\Jasc Software Inc\\Paint Shop Pro 7\\Tubes"Find what: "dirname[^1]"=".+?"
Replace with: Options: case insensitiveMatch the characters “"dirname” literally «"dirname»Match any character that is NOT a “1” «[^1]»Match the characters “"="” literally «"="»Match any single character that is not a line break character «.+?»Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»Match the character “"” literally «"»Created with RegexBuddyBecomes:"DirName1"="e:\\Program Files\\Jasc Software Inc\\Paint Shop Pro 7\\Shapes"
Find what: <div.+?>
Replace with: <div>
(?<=<body>)([\s\S]*)(?=<div class="container">)
Explanation:
Options: case insensitiveAssert that the regex below can be matched, with the match ending at this position (positive lookbehind) «(?<=<body>)»Match the characters “<body>” literally «<body>»Match the regular expression below and capture its match into backreference number 1 «([\s\S]*)»Match a single character present in the list below «[\s\S]*»Between zero and unlimited times, as many times as possible, giving back as needed (greedy) «*»A whitespace character (spaces, tabs, line breaks, etc.) «\s»Any character that is NOT a whitespace character «\S»Assert that the regex below can be matched, starting at this position (positive lookahead) «(?=<div class="container">)»Match the characters “<div class="container">” literally «<div class="container">»
Test string from "... \htdocs\imagemagick\script\index.html":
<body> <nav class="navbar navbar-expand-md navbar-dark fixed-top bg-dark"> <a class="navbar-brand" href="/"><img class="d-block" id="icon" alt="ImageMagick" width="32" height="32" src="/script/../image/wand.ico"/></a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarsMagick" aria-controls="navbarsMagick" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="navbar-collapse collapse" id="navbarsMagick" style=""> <ul class="navbar-nav mr-auto"> <li class="nav-item"> <a class="nav-link" href="/script/../">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="/script/../script/download.php">Download</a> </li> <li class="nav-item"> <a class="nav-link" href="/script/../script/command-line-tools.php">Tools</a> </li> <li class="nav-item"> <a class="nav-link" href="/script/../script/command-line-processing.php">Command-line</a> </li> <li class="nav-item"> <a class="nav-link" href="/script/../script/resources.php">Resources</a> </li> <li class="nav-item"> <a class="nav-link" href="/script/../script/develop.php">Develop</a> </li> <li class="nav-item"> <a class="nav-link" target="_blank" href="https://github.com/ImageMagick/ImageMagick/discussions">Community</a> </li> </ul> </div> <form class="form-inline my-2 my-lg-0" action="/script/../script/search.php"> <input class="form-control mr-sm-2" type="text" name="q" placeholder="Search" aria-label="Search"> <button class="btn btn-outline-success my-2 my-sm-0" type="submit" name="sa">Search</button> </form> </nav> <div class="container">
Pause 7000 [6]
<map name="Map">(.+?)<\/map>
https://superuser.com/questions/277642/how-to-merge-audio-and-video-file-in-ffmpegffmpeg -i 1.mp4 -i 1.m4a -c:v copy -c:a aac 2.mp4
# Concatenate .mp4 with Windows 10 64-bit, powershell 5 and ffmpeg using intermediate .ts file# get sample .mp4 https://www.vjloops.com/stock-video/circle-flow-offsets-01-138855.html# BEGIN PREP$ErrorActionPreference="SilentlyContinue" ; $z=Get-Date -f 'MMddyy-hhmmss';ni -ItemType Directory $z > $null ;# make 3 copies of 1.mp4 1..3 | foreach { copy-item 1.mp4 "$z\$_.mp4" > $null}remove-item "$z\list3.txt" # END PREP# BEGIN CONCATENATE foreach ($i in gci "$z\*.mp4" | % basename) {ffmpeg -y -i "$z\$i.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts "$z\$i.ts"}foreach ($i in gci "$z\*.mp4" | % name) {echo "file '$z\$i'" | out-file "$z\list3.txt" -append -Force -Encoding ASCII}&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" -crf 23 "$env:userprofile\desktop\NotifyAnimation.mp4" # Change quality from default of 23 to ?. 51= worst. 0 = best.# END CONCATENATE#CLEAN UPremove-item "$z" -Recurse -confirm
# Concatenate .mp4 with Windows 10 64-bit, powershell 5 and ffmpeg using intermediate .ts file# get sample .mp4 https://www.vjloops.com/stock-video/circle-flow-offsets-01-138855.html# BEGIN PREP$ErrorActionPreference="SilentlyContinue" ; # $ErrorActionPreference = "Continue" ;$z=Get-Date -f 'MMddyy-hhmmss';ni -ItemType Directory "$z" > $null ;# make copies of .mp4 1..3 | foreach { copy-item 1.mp4 "$z\$_.mp4" > $null}# END PREP# BEGIN CONCATENATE # copy .mp4 to .tsforeach ($i in gci "$z\*.mp4" | % basename) {ffmpeg -y -i "$z\$i.mp4" -c copy -bsf:v h264_mp4toannexb -f mpegts "$z\$i.ts"}# http://trac.ffmpeg.org/wiki/Concatenate# Create ASCII list of files for ffmpeg -i input in format "file 'directory\name' = file '081721-015117\3.ts'remove-item "$z\list3.txt" # next line out-file must use -append AND must use -Encoding ASCIIforeach ($i in gci "$z\*.mp4" | % name) {echo "file '$z\$i'" | out-file "$z\list3.txt" -append -Force -Encoding ASCII}# http://trac.ffmpeg.org/wiki/Concatenate&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" "$env:userprofile\desktop\NotifyAnimation.mp4"# reduce quality from default of 23 to 30. 51= worst 0 = best.#&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" -crf 30 "$env:userprofile\desktop\NotifyAnimation.mp4"#&ffmpeg -y -f concat -safe 0 -i "$z\list3.txt" -crf 40 "$env:userprofile\desktop\NotifyAnimation.mp4"# END CONCATENATE#CLEAN UPri "$z" -Recurse -confirm
rem Concatenate .mp4 with Windows 10 64-bit, cmd and ffmpeg using intermediate .ts filerem get sample .mp4 https://www.vjloops.com/stock-video/circle-flow-offsets-01-138855.htmlrem BEGIN PREPrem make directory mmddyy-hhmmss i.e. 081721-085851FOR /f "TOKENS=1-4" %%g in ('time/T') do set zhhmmss=%%g%%i%TIME:~10,2%FOR /f "TOKENS=1-4" %g in ('time/T') do set zhhmmss=%g%i%TIME:~10,2%set zfolder=%DATE:~-10,2%%DATE:~-7,2%%DATE:~-2,2%-%zhhmmss%md "%zfolder%"for /l %g in (2,1,4) do copy /y "1.mp4" "%zfolder%\%g.mp4"for /l %%g in (2,1,4) do copy /y "1.mp4" "%zfolder%\%%g.mp4"rem END PREPrem BEGIN CONCATENATE for %g in (%zfolder%\*.mp4) do (echo ffmpeg -y -i "%g" -c copy -bsf:v h264_mp4toannexb "%zfolder%\%~ng.ts")for %g in ("%zfolder%\*.ts") do (echo file '%g')>>list.txtrem -crf quality 23 = default, 51 = worst, 0 = best ffmpeg -f concat -safe 0 -i "list.txt" -crf 40 output.mp4rem copy .mp4 to .tsfor %%g in (%zfolder%\*.mp4) do (ffmpeg -y -i "%%g" -c copy -bsf:v h264_mp4toannexb "%zfolder%\%%~ng.ts")rem Make ASCII list of filesfor %%g in ("%zfolder%\*.ts") do (echo file '%%g')>>list.txtffmpeg -f concat -safe 0 -i "list.txt" -c copy output.mp4rem -crf quality 23 = default, 51 = worst, 0 = best ffmpeg -f concat -safe 0 -i "list.txt" -crf 40 output.mp4pause rem END CONCATENATErem CLEAN UPrd /q /s %zfolder%
ffmpeg -ss 00:02:00 -i 1.mkv -vf "[in]drawtext=fontsize=48:fontcolor=white:bordercolor=black:borderw=2:text='To the Well for the Water':x=10:y=(h)/4:enable='between(t,0,10)', drawtext=fontsize=48:fontcolor=white:bordercolor=black:borderw=2:text='June 21st, 2021': x=(w-text_w)/2:y=((h)/4)+60:enable='between(t,0,10)', drawtext=fontsize=48:fontcolor=white:bordercolor=black:borderw=2:text='St. Pauls Episcopal Church':x=10:y=((h)/4)+120:enable='between(t,0,10)', drawtext=fontsize=48:fontcolor=white:bordercolor=black:borderw=2:text='Concord, New Hampshire':x=(w-text_w)/2:y=((h)/4)+180:enable='between(t,0,10)'[out]" -y -t 00:00:30 output.mkv
ffmpeg -ss 00:02:00 -y -i 1.mkv -i 1.jpg -filter_complex "[0:v][1:v] overlay=25:25:enable='between(t,0,10)'" -codec:a copy -t 00:00:30 output.mkv
ffmpeg -ss 00:02:00 -y -i 1.mkv -i 1.jpg -filter_complex "overlay=x=(w)/8:y=(h)/2:enable='between(t,0,10)'" -codec:a copy -t 00:00:30 output.mkv
https://stackoverflow.com/a/52592245/8826818ffmpeg -y -i 1.mkv -i 1.jpg -filter_complex "[1]format=yuva444p,colorchannelmixer=aa=0.5[1.jpg];[1.jpg][0]scale2ref[1.jpg][1.mkv];[1.mkv][1.jpg]overlay" -t 00:00:30 output.mkv
rem ffprobe -i 3.mpgDuration: 00:09:52.86 Bitrate: 5.338 Mbps Stream #0:0Video: mpeg2video, yuv420p(tv, progressive), 1280x720 [SAR 1:1 DAR 16:9], Closed Captions, 59.94 fps, 59.94 tbr, 90k tbn, rem 119.88 tbc Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 224 kb/s Stream #0:2(eng): Audio: ac3, 48000 Hz, stereo, fltp, 128 kb/sffmpeg -ss 00:03:35 -y -i "State of Happiness S01E01 - Treasure Hunt 1080P x264 RB58.mp4" -b:v 1125k -filter:v scale=720:480 -ar 48000 -b:a 384k -t 00:01:30 "State of Happiness S01E01 - Treasure Hunt 720P x264 RB58.mp4"rem Recording made by WinTV = 2.6GB / hour = .TS extension. Auto convert to .mpg = 2.26GB / hour.rem Cut commercials with Womble. 377MB / 9 minutes takes ~4 minutes to bookmark and ~ 8 minutes to export to .mp4.rem Compress with ffmpeg. crf lower (0-50. 23 = default) + preset slower (medium = default) = better rem 27 + slow = 00:02:54 for 77MB / 5 MINUTES. 51% smaller = 38MB = 456MB / hour. Quality good enough for 1360x768 720dpi 20"TVffmpeg -y -i "3.mpg.womble.mp4" -crf 27.0 -vcodec libx264 -filter:v scale=1280:720 -preset slow -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "3.mpg.womble.mp4.27slow.mp4"rem 25 + veryslow = 00:05:38 for 77MB / 5 MINUTES. 36% smaller = 50MB = 600MB / hour. Quality good enough.ffmpeg -y -i "3.mpg.womble.mp4" -crf 25.0 -vcodec libx264 -filter:v scale=1280:720 -preset veryslow -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "3.mpg.womble.mp4.25veryslow.mp4"rem 23 + veryfast = 00:07:52 for 438MB. 68% smaller = 114MB. Quality not quite good enough.ffmpeg -y -i "2.ts" -crf 23.0 -vcodec libx264 -filter:v scale=1280:720 -preset veryfast -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "2.ts.23veryfast.mp4"rem 20 + veryfast = 00:26:08 for 438MB. 53% smaller = 211MB. Quality good enough.ffmpeg -y -i "2.ts" -crf 20.0 -vcodec libx264 -filter:v scale=1280:720 -preset veryfast -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "2.ts.20veryfast.mp4"rem 20 + veryslow = 00:23:34 for 438MB. 46% smaller = 238MB. Quality good enough.ffmpeg -y -i "2.ts" -crf 20.0 -vcodec libx264 -filter:v scale=1280:720 -preset veryslow -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "2.ts.20veryslow.mp4"rem 25 + veryslow = 00:15:45 for 438MB. 72% smaller = 124MB. Quality good enough.ffmpeg -y -i "2.ts" -crf 25.0 -vcodec libx264 -filter:v scale=1280:720 -preset veryslow -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "2.ts.25veryslow.mp4"rem 25 + veryslow = 00:28:13 for 77MB. 39% smaller = 47MB. Quality good enough. ffmpeg -y -i "3.mpg.womble.mp4" -crf 25.0 -vcodec libx264 -filter:v scale=1280:720 -preset veryslow -acodec copy "3.mpg.womble.25veryslow.audiocopy.mp4"rem recording made by BeyondTV. 3GB / hour. TP extension.rem make a 00:01:30 second sample starting at 00:03:35FOR /f "delims=" %g IN ('DIR /b /a-d /od /tw *.tp') DO ffmpeg -ss 00:03:35 -y -i "%g" -b:v 1125k -filter:v scale=720:480 -ar 48000 -b:a 384k -t 00:01:30 "%~ng.mp4"rem do the whole fileFOR /f "delims=" %g IN ('DIR /b /a-d /od /tw *.tp') DO ffmpeg -y -i "%g" -b:v 1125k -filter:v scale=720:480 -ar 48000 -b:a 384k "%~ng.mp4"ffprobe -i golf.mp4 rem delay audio 3 secondsffmpeg -y -i golf.mp4 -itsoffset 3 -i golf.mp4 -codec copy -map 0:0 -map 0:1 golf2.mp4rem delay video 3 seconds at 00:09:36ffmpeg -y -itsoffset 3 -i golf.mp4 -i golf.mp4 -codec copy -map 0:0 -map 0:1 golf2.mp4ffmpeg -y -i golf.mp4 -itsoffset 3 -i golf.mp4 -c:a copy -c:v copy -map 0:1 -map 0:0 golf2.mp4rem https://superuser.com/a/1557090/1003800ffmpeg -y -i "manual.mpg" -crf 20.0 -vcodec libx264 -filter:v scale=1280:720 -preset slow -acodec aac -ar 48000 -b:a 128k -coder 1 -flags +loop -cmp chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 "%userprofile%\Desktop\manual.mpg.mp4"
rem recording made by BeyondTVrem make a 00:01:30 second sample starting at 00:03:35FOR /f "delims=" %g IN ('DIR /b /a-d /od /tw *.tp') DO "C:\Windows\ffmpeg.exe" -ss 00:03:35 -y -i "%g" -b:v 1125k -filter:v scale=720:480 -ar 48000 -b:a 384k -t 00:01:30 "%~ng.mp4"rem do the whole fileFOR /f "delims=" %g IN ('DIR /b /a-d /od /tw *.tp') DO "C:\Windows\ffmpeg.exe" -y -i "%g" -b:v 1125k -filter:v scale=720:480 -ar 48000 -b:a 384k "%~ng.mp4"rem delay video 3 secondsffmpeg -y -itsoffset 3 -i golf.mp4 -i golf.mp4 -codec copy -map 0:0 -map 0:1 golf2.mp4rem Recording made by WinTV. 1GB / hour. TS extension.rem Cut commerials with Womble
"$z=$env:windir\ffmpeg.exe.lnk -y -i"gci *.mp3 -Name | foreach { #ffmpeg -y -i $_ -metadata title="$_" -c copy 2$_rename-item $_ b-$_ -whatif}
xxx
22 November 2021
Microsoft’s oldest .NET desktop framework, Windows Forms, has been improved for .NET 6, though fullsupport for high resolution displays is “a challenging undertaking,” according to software engineer IgorVelikorossov.
The first release of Windows Forms was in February 2002, when it was positioned as the successor to VisualBasic 6.0 (1998) as a rapid application development framework for Windows desktop applications. Therewas huge friction in that transition, but it was nevertheless popular and easy to use. Underneath WindowsForms lies the Win32 API and the GDI+ graphics API.
In late 2006, Microsoft introduced Windows Vista and along with it a new .NET desktop framework calledWindows Presentation Foundation (WPF). Unlike Windows Forms, it used DirectX to render graphics,enabling richer designs with hardware accelerated performance.WPF was also designed to scale nicely irrespective of the display resolution and Windows display settings,thanks to use of layout managers for positioning user interface elements.
Windows Forms in Visual Studio 2022
Why is Microsoft still investing in Windows Forms, the oldest .NET desktop framework, when it has beenreplaced several times, first by WPF, then by Windows 8 with its Windows Runtime APIs, then by UWP(Universal Windows Platform), and most recently by WinUI 3 (also known as Project Reunion)? The answer is simply the popularity of the framework and the number of legacy business applications that use it. Third-party component vendors also gave good support to the platform.
It seems that despite the technical superiority of WPF, many business developers find Windows Formseasier, perhaps because of its apparently simple form designer where a button or checkbox stays where it isplaced, at least until users with different display settings complain about overlapping text or chopped-offcharacters.
Windows Forms is only for Windows and not much was done to it for some years, especially as it was for.NET Framework and most development effort was going into the open source .NET Core. That changedwhen .NET Core 3.0 was released, with support for both Windows Forms and WPF. At this point bothframeworks became open source, though this was a fork and Velikorossov’s post about what’s new inWindows Forms concerns the .NET 6.0 version, not the .NET Framework one.
Migration of an existing application is not straightforward and may be impossible without major surgery.
Some features of .NET Framework, include Application Domains, .NET Remoting, Windows WorkflowFoundation, and Windows Communication Foundation (WCF), with WCF being the most problematic.
Remote communication using SOAP (an XML remoting standard) and WCF was widely used, often withASP.NET on the web server and a Windows Forms client.
Despite these issues, Microsoft has added features including accessibility improvements – such as betterscreen narrator support and user interface automation – updated templates to support the new .NET 6.0global using directive, and new runtime designers. “In .NET Core 3.0 we started to modernize and rejuvenateWindows Forms,” said Velikorossov.
The biggest challenge remains scaling and high DPI (dots per inch) displays. The original scaling method forWindows Forms was based on the default system font, on whose size all the autoscaling of a formdepended. It was not a good system. There were rounding errors, issues with user controls and with forminheritance, and “forms and their child controls could only be concurrently designed by multiple developers iftheir machine resolutions were the same,” say the docs.
There were tweaks, but high DPI support did not arrive until .NET Framework 4.7 and only worked onWindows 10 Creators Update and later. When the .NET Core version came along, Velikorossov describeshow the team changed the default font and “quickly learned that a great number of things depended on thisdefault font metrics.”
The aim of full support for per-monitor V2 DPI awareness remains, meaning that applications are never bitmap scaled by Windows (causing fuzzy fonts) but are notified when DPI changes, maybe because of a setting change or a window being dragged to another display. “It is a challenging undertaking, and sadly we couldn’t achieve as much as we’d hoped,” said Velikorossov, but there are improvements with correct scaling of container controls and MDI child windows “in most scenarios.”
There are also community contributions to Windows Forms for .NET 6.0 including MessageBox, used for quick dialogs requiring user confirmation or input, optionally getting two new buttons: Try Again, and Continue.
Developers reacted to Velikorossov’s post with some requests. “Please add native dark mode,” was one, though apparently a challenge here is that “Windows still does not have a documented way to check whether the system is in light or dark mode.” Another commented gratefully that the “Form Designer in release VS 2022 works much better, it was way too slow.”
When the .NET Foundation conducted a developer survey earlier this year, WPF and Windows Forms came out as more widely used than Microsoft’s more recent efforts.
It is not a good choice for a GUI application today being Windows-only and a weak option even on Windows yet legacy combined with its initial ease of use means it will be around for many years to come something developers are less sure about with some other .NET technologies. ®
Windows Registry Editor Version 5.00;RIGHT CLICK taskbar pinned EXPLORER; INCREASE NUMBER OF QUICK ACCESS TOOLBAR BUTTONS.[HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced]"JumpListItems_Maximum"=dword:00000025"Start_JumpListItems"=dword:0000001e;http://superuser.com/questions/1035179/how-do-i-increase-the-number-of-items-on-a-jump-list-in-windows-10;https://www.tenforums.com/general-support/7983-increase-number-items-jump-lists.html
Sunday, ?August ?29, ?2021, ??9 : 12 : 11 AM
get-date "Sunday, August 29, 2021, 9 : 12 : 11 AM"Cannot convert value "Sunday, August 29, 2021, 9 : 12 : 11 AM" to type "System.DateTime". Error: "String was not recognized as a valid DateTime."
get-date "Sunday, August 29, 2021, 9 : 12 : 11 AM"Cannot convert value "Sunday, ‎August ‎29, ‎2021, â€â€Ž9 : 12 : 11 AM" to type "System.DateTime". Error: "The string was not recognized as a valid DateTime."
%windir%\system32\control.exe /name microsoft.troubleshooting
%systemroot%\system32\msdt.exe -id NetworkDiagnosticsNetworkAdapter
Get a card at least as fast as the internal memory. The SD class speed logos, in order from slowest (class 2) to fastest (UHS class 3). If you see no speed class symbol, you have a class 0 SD card. These cards were designed and produced before the speed class rating system was introduced. They may be slower than even a class 2 card. Format it for internal or portable storage. The newest, fastest "app class" microSD cards are still not very good for apps.
Sandisk 32GB U1 MicroSD formatted for internal storage.About phone Software version Tap seven times Back to SettingsSystem AdvancedDeveloper options USB debugging - enable Default USB configuration - USB - File Transfer.
Class 4 MicroSD card.About phone SW Version Tap seven times Back to SettingsDeveloper options USB debugging - enable
# delay while cpu and disk usage is high
# powershell F:\MYAPPS\WINDOWS\_13.ps1
# https://www.znetlive.com/blog/monitor-disk-io-windows-linux/
$zred = 80
$zgreen = 60000
$zblue = 1600
while (($red -gt 2) -or ($zgreen -gt 8) -or ($zblue -gt 44)) {
$zred = Get-Counter '\Processor Information(_total)\% Processor Time' |
ForEach-Object {$_.CounterSamples[0].CookedValue}
$zgreen = Get-Counter '\Process(_total)\IO Data Operations/sec' |
ForEach-Object {$_.CounterSamples[0].CookedValue}
$zblue = Get-Counter '\PhysicalDisk(0 C: D: E: F: G:)\Disk Transfers/sec' |
ForEach-Object {$_.CounterSamples[0].CookedValue}
}
exit
$host.UI.RawUI.WindowTitle = "Delay while cpu and disk usage is high"
Write-Host "This is"$MyInvocation.MyCommand
$zprotime = 80
$zdisk = 1600
$zprocess = 60000
while (($zprotime -gt 16) -or ($zdisk -gt 72) -or ($zprocess -gt 32000)) {
$zprotime = Get-Counter '\Processor Information(_total)\% Processor Time' |
ForEach-Object {$_.CounterSamples[0].CookedValue}
$zdisk = Get-Counter '\PhysicalDisk(0 C: D: E: F: G:)\Disk Transfers/sec' |
ForEach-Object {$_.CounterSamples[0].CookedValue}
$zprocess = Get-Counter '\Process(_total)\IO Data Operations/sec' |
ForEach-Object {$_.CounterSamples[0].CookedValue}
}
Write-Host "Red = $zprotime = Processor info % processor time"
Write-Host "Blue = $zdisk = Physical disk disk transfers"
Write-Host "Green = $zprocess = Process IO data operations"
Write-Host "This is Delay while cpu and disk usage is high"
exit
soundcapture /?syntax: soundcapture[/br bitrate] : MP3 encoding bitrate (Max in case of VBR).[/vbr] : MP3 variable bitrate encoding.[/cbr] : MP3 constant bitrate encoding.[/sr sample rate] : Sample Rate.[/s] [/m] : length in seconds (/s) or minutes (/m)[/in "Audio Input"] : select the audio input.[/title "name"] : Set the title for the ID3 tag.default length is: 30 minutesdefault output is: C:\capture.mp3[/mkdef] : Makes the current settings the default for future use.[/vwdef] : View the default settings.
ffmpeg -i malformed.ts -c copy repaired.tsffmpeg -i repaired.ts -c copy working.mp4
Switch the order of your commands so that the video processing
filters come after your input.
ffmpeg -i "%userprofile%\Desktop\1.ts" -hide_banner -report -f "v4l2" -vf "fps=fps=30.000,scale=-2:720:flags=fast_bilinear,format=yuv420p" -vstats -r "30.000" -c:v "libx264" -crf "23" -an -dn -sn -map_metadata "-1" -preset "faster" -f "matroska" output.mkv
First you have to find out whether your hardware is maxing out because of the "capture and decode" vs the "encode".
Use the fps filter to drop the number of frames you are trying to process at the start of the filter chain using both fps filter and -r command. You can always revert to 60fps if you find that this is not the limiting factor. You may also find that decimate may be less intensive than fps, but fps is a more elegant method of primary frame rate conversion. I suspect that you will not want to drop the frame rate, but at least try it to see whether it helps reduce the amount of frames you are trying to encode.
Drop the resolution to 1280x720 using the scale filter. See if it makes a difference? If it makes no difference, bring it back to 1920x1080. Try fast bilinear scaling, which gets you about 10% extra over the default scaling. There is also cuda scaling.
Iconoclast personal opinion: 1080p60 + ultrafast may sound like it is going to give you the best visual quality, but if the system is struggling to keep up, 720p30 + faster/fast/medium preset may give you a better final quality. Ultrafast is not always visually appealing and can be blocky with washed out colors. Well-encoded 720p is sometimes better than badly-encoded 1080p. It all depends on the screensize and distance that you are viewing from.
Of course, you can try going down the hardware decode, hardware scale and hardware encode route. YMMV. https://trac.ffmpeg.org/wiki/HWAccelIntro. The benefit is massively dependent on your hardware. On my laptop, it hardly makes much difference compared to good old x264.ffmpeg -hide_banner -hwaccels will help you work out what hardware accelerations are available.
Leave -threads alone while you are trying to find out where your bottlenecks are. Add back if you are trying to restrict FFmpeg, otherwise the default of -threads "0" seems to optimize itself out just fine.
Play with the following, tweaking the frame rate, resolution and preset.
ffmpeg -i "%userprofile%\Desktop\1.ts" -hide_banner -report -f "v4l2" -vf "fps=fps=30.000,scale=-2:720:flags=fast_bilinear,format=yuv420p" -vstats -r "30.000" -c:v "libx264" -crf "23" -an -dn -sn -map_metadata "-1" -preset "faster" -f "matroska" output.mkv
Also, try dumping your raw stream to null to measure the effect on CPU of just the input/decode chain.
ffmpeg -i TestVideo.ts -hide_banner -report -f "v4l2" -c:v "wrapped_avframe" -an -dn -sn -map_metadata "-1" -f "null" /dev/null
START "" /min "streamripper.exe.lnk" http://c4icyelb.prod.playlists.ihrhls.com/1269_icy -A -a ALICE3 -d "%cd%" -l 7200 -u "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" --quietrem Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0sleep 5START "" /min "streamripper.exe.lnk" http://bbcmedia.ic.llnwd.net/stream/bbcmedia_radio1_mf_q -A -a BBC13 -d "%cd%" -l 7200 -u "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.97 Safari/537.11" --quietrem Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Firefox/78.0sleep 5:concatenate
dir *).*> NUL 2>&1
IF NOT ERRORLEVEL 1 (
SETLOCAL ENABLEDELAYEDEXPANSION
%WINDIR%\TIMER.EXE /NOLOGO /Q
echo.
echo DEL *.CUE
del /q *.cue
echo.
echo dir /b *^).*
dir /b *^).*
echo.
sleep 1
for /f %%g in ('dir "*).*" ^| find "File(s)"') do SET zcnt1=%%g
rem in different2 (1).aac g="different2" h=(1) and i=aac w/o the quotes
for /f "tokens=1,2,3 delims=. " %%g in ('dir /b "*).*"') do ( copy /b /y "%%g (*).%%i" + "%%g.%%i" "%%g.%%i.tmp" del /q %%g*.%%i )
for /f %%g in ('dir "*.tmp" ^| find "File(s)"') do SET zcnt2=%%g
for /f "tokens=1,2,3 delims=. " %%g in ('dir /b "*.tmp"') do ( ren %%g.%%h.%%i %%g.%%h )
echo. &echo Concatenate !zcnt1! files with !zcnt2! files:
SETLOCAL DISABLEDELAYEDEXPANSION
%WINDIR%\TIMER.EXE /NOLOGO /S
)
:ffmpeg
sleep 1
TITLE FFMPEG
ECHO.
ECHO FFMPEG
start "" /min "%windir%\ffmpeg.exe.lnk" -y -i "%cd%\bbc13.mp3" -metadata title="BBC RADIO 1" -metadata artist="HITS. NEW MUSIC." -metadata album="bbc.co.uk/sounds" -metadata album_artist="HITS. NEW MUSIC." -ss 00:01:15 -c copy "%cd%\bbc1.mp3"
sleep 1
How to process video:With most highly compressed formats like Divx you have to make your splits on a keyframe (I frame). Anywhere else will cause problems. Formats like Divx/XviD have keyframes about every 300 frames by default. That's one way they get high compression. A keyframe is a complete frame and the ones following and proceeding are just partial frames. If you split anywhere else, you would have to re-encode that portion to preserve audio/video sync. In avidemux, you navigate by keyframes using the "<<" and ">>". In vdub , it the arrows "<" ">" with the key picture underneath. If neither of these work there is likely something wrong with your video. I say this because you shouldn't have to cut on keyframes with avidemux when using XviD/DivX because it automatically asks you if you want to enable "smart copy" which will render around the cut site if the cut is not on a keyframe.
BEGIN How to split files by size:
"%ProgramFiles%\MKVToolNix\mkvmerge.exe" --split 2G --compression 0:none --compression 1:none --clusters-in-meta-seek -o "2.mkv" "1.mkv"
This command will split the file into segments 2-001.mkv, 2-002.mkv,
etc. In general, if the file plays on your computer but does NOT
play on tv or disc player (bluray, dvd), your problem will usually
be header compression.
How to get Womble to not crash. Split the video into one hour segments. DOES NOT PREVENT WOMBLE FROM CRASHING. Starting at minute 9 copy 1 hour to a new video.
ffmpeg -ss 00:09:00 -y -i "1.ts" -b:v 2000k -r 30000/1001 -filter:v scale=852:480 -async 10 -t 01:00:00 "2.mp4"
Concatenate the files:
ffmpeg -y -i "concat:1.mpg|2.mpg|3.mpg|4.mpg" -c copy 5.mpg
I’ve had both 3L and 3N Neco branded nut type 10B21 spindle on the blue Panasonic bicycle. The 3N is currently on the blue Panasonic bicycle.
The 3L is 32 x 52 x 32 x 116. The 3N is 32 x 52 x 36 x 120. The 3N has ~3/16” / 5mm clearance between a chain ring nut head and the frame. The 3N cup set and axle: Sunlite EZ-Off BB Cup Set Bb Set Sunlt Ez-off 1.37x24 Bk Eng for $10.40 and Sunlite 3N Bb Axle Sunlt W/nut 3n 32.0x52x36.0x120 for $11.74 from Bell’s Bike Shop Philadelphia via eBay.
Bottom Bracket Cartridge 68 x 122mm
https://www.randombikeparts.com/collections/bottom-brackets $12.79 + $0. Minnesota. Pull from new bike.
Neco Bottom Bracket Bolt Type Cotterless Axle B906 10B21
Spindle, DustSeal & Pre-Lubed Cartridge, Steel Cups,
Plastic Body Axle Models:2P, 2N, 2SS, 2NL
https://www.xanhbattang.com/index.php?main_page=product_info&products_id=276821
https://www.necoparts.com/en/product/Cartridge-Cotterless-B.B.-Sets/B906%2C+B906E%2C+B906B.html
https://www.necoparts.com/Templates/att/2020-2021CATALOGUE-BOTTOM%20BRACKETS.pdf?lng=en
bicycle2020-2021catalogue-bottom-brackets.pdf (4MB .pdf)
2020 Hot sale Mountain Bike Bottom Bracket 10B21 Spindle, Dust Seal &Pre-Lubed Cartridge Steel Cups, Plastic Body
https://www.alibaba.com/product-detail/2020-Hot-sale-Mountain-Bike-Bottom_1700001872225.html
SPECIFICATIONS
LD906: BSA 1.37”x24T, R/L
LD906B: Italian 36mmx24T, R/R
LD906E: BSA 1.37”x24T, R/L, E-Type
WEIGHT 296g
SPINDLE LENGTH
110.5mm, 113.5mm, 115mm, 116mm, 118mm, 122.5mm &
126.5mm for 68mm & 70mm Widths
COMPONENTS
10B21 Spindle, Dust Seal & Pre-Lubed Cartridge Steel Cups, Plastic Body
I also had a Zhongya 122.5 and 124.5mm that failed after 41 days.
bicycle bottom bracket: Three piece crank. JIS square-taper cranksets https://www.sheldonbrown.com/bbtaper.html Spindle Length: 145mm BB Shell Width: 071mm. 1/4" x 9 bearings w/ race / cage / retainer. 1/4" x 11 if not using race / cage / retainer drive side of axle / spindle is slightly longer ( ~1/8" longer). A raised ring circles the axle / spindle < 1cm from the outer edge of the bearing race on the drive side. bc-1 lockring
(gc K:\Downloads\DoNotDelete\archive.txt,C:\Users\_56\AppData\Local\Temp\DoNotDelete\archive.txt) -replace '\t\t ','' | sort | get-unique | out-file -encoding ascii combine.txt
# youtube-dl archive lists: Find unique, output to file and copy# C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -noexit -ExecutionPolicy Bypass gc "F:\MYAPPS\WINDOWS\102.ps1"|powershell(gc "F:\Users\_9doug\AppData\Local\Temp\DoNotDelete\archive.txt","J:\Downloads\DoNotDelete\archive.txt","Z:\DoNotDeleteArchive.txt") | sort | get-unique | out-file -encoding ascii "combine.txt"copy combine.txt "F:\Users\_9doug\AppData\Local\Temp\DoNotDelete\archive.txt"copy combine.txt "J:\Downloads\DoNotDelete\archive.txt"copy combine.txt "Z:\DoNotDeleteArchive.txt"
### Expires Headers YSlow START# Browser caching optimization by Sam Riveros##<IfModule mod_headers.c> # Turn on Expires and set default to 0 ExpiresActive On ExpiresDefault A0 # Set up caching on media files for 1 year (forever?) <FilesMatch "\.(ico|pdf|mp4|ogg|webm|svg+xml|ttf|otf|woff|woff2)$"> ExpiresDefault A29030400 Header append Cache-Control "public" </FilesMatch> # Set up caching on media files for 1 week <FilesMatch "\.(jpg|jpeg|png)$"> ExpiresDefault A604800 Header append Cache-Control "public" </FilesMatch> # Set up caching for commonly updated static files for 1 week <FilesMatch "\.(txt|html|js|css)$"> ExpiresDefault A604800 Header append Cache-Control "proxy-revalidate" </FilesMatch> # Force no caching for dynamic files <FilesMatch "\.(php)$"> ExpiresActive Off Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform" Header set Pragma "no-cache" </FilesMatch></IfModule><IfModule mod_expires.c> #Redundancy in case server admin turn mod_headers.c off ExpiresActive on ExpiresDefault "access plus 1 month" #CSS ExpiresByType text/css "access plus 1 year" #Data interchange ExpiresByType application/json "access plus 0 seconds" ExpiresByType application/xml "access plus 0 seconds" ExpiresByType text/xml "access plus 0 seconds" #Favicon ExpiresByType image/x-icon "access plus 1 year" #HTML components (HTCs) ExpiresByType text/x-component "access plus 1 month" #HTML ExpiresByType text/html "access plus 1 week" #Javascript ExpiresByType application/javascript "access plus 1 year" #Manifest files ExpiresByType application/x-web-app-xanifest+json "access plus 0 seconds" ExpiresByType text/oache-xanifest "access plus 0 seconds" #Media ExpiresByType image/jpg "access plus 1 week" ExpiresByType image/jpeg "access plus 1 week" ExpiresByType image/png "access plus 1 week" ExpiresByType audio/ogg "access plus 1 year" ExpiresByType video/mp4 "access plus 1 year" ExpiresByType video/ogg "access plus 1 year" ExpiresByType video/webm "access plus 1 year" #Web feeds ExpiresByType application/atom+xml "access plus 1 hour" ExpiresByType application/rss+xml "access plus 1 hour" #Web fonts ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType application/x-font-ttf "access plus 1 year" ExpiresByType application/x-font-truetype "access plus 1 year" ExpiresByType application/x-font-opentype "access plus 1 year" ExpiresByType application/font-woff "access plus 1 year" ExpiresByType application/font-woff2 "access plus 1 year" ExpiresByType application/vnd.ms-fontobject "access plus 1 year" ExpiresByType application/vnd.xs-fontobject "access plus 1 year" ExpiresByType application/font-sfnt "access plus 1 year"</IfModule><IfModule mod_deflate.c> # Compress HTML, CSS, JavaScript, Text, XML and fonts AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/vnd.ms-fontobject AddOutputFilterByType DEFLATE application/x-font AddOutputFilterByType DEFLATE application/x-font-opentype AddOutputFilterByType DEFLATE application/x-font-otf AddOutputFilterByType DEFLATE application/x-font-truetype AddOutputFilterByType DEFLATE application/x-font-ttf AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE font/opentype AddOutputFilterByType DEFLATE font/otf AddOutputFilterByType DEFLATE font/ttf AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE image/x-icon AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/xml # Remove browser bugs (only needed for really old browsers) BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4\.0[678] no-gzip BrowserMatch \bMSIE !no-gzip !gzip-only-text/html Header append Vary referer</IfModule>### Expires Headers YSlow END##
#GZIP COMPRESSION<IfModule mod_gzip.c>mod_gzip_on Yesmod_gzip_dechunk Yesmod_gzip_item_include file \.(html?|txt|css|js|php|pl)$mod_gzip_item_include handler ^cgi-script$mod_gzip_item_include mime ^text/.*mod_gzip_item_include mime ^application/x-javascript.*mod_gzip_item_exclude mime ^image/.*mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*</IfModule># END GZIP COMPRESSION# START DEFLATE COMPRESSION<IfModule mod_deflate.c>AddOutputFilterByType DEFLATE "application/atom+xml" \"application/javascript" \"application/json" \"application/ld+json" \"application/manifest+json" \"application/rdf+xml" \"application/rss+xml" \"application/schema+json" \"application/vnd.geo+json" \"application/vnd.ms-fontobject" \"application/x-font" \"application/x-font-opentype" \"application/x-font-otf" \"application/x-font-truetype" \"application/x-font-ttf" \"application/x-javascript" \"application/x-web-app-manifest+json" \"application/xhtml+xml" \"application/xml" \"font/eot" \"font/otf" \"font/ttf" \"font/opentype" \"image/bmp" \"image/svg+xml" \"image/vnd.microsoft.icon" \"image/x-icon" \"text/cache-manifest" \"text/css" \"text/html" \"text/javascript" \"text/plain" \"text/vcard" \"text/vnd.rim.location.xloc" \"text/vtt" \"text/x-component" \"text/x-cross-domain-policy" \"text/xml"</IfModule># END DEFLATE COMPRESSION# START ENABLE KEEPALIVE<ifModule mod_headers.c>Header set Connection keep-alive</ifModule># END ENABLE KEEPALIVE# START EXPIRES CACHING #<IfModule mod_expires.c>ExpiresActive OnExpiresByType text/css "access 1 month"ExpiresByType text/html "access 1 month"ExpiresByType image/gif "access 1 year"ExpiresByType image/png "access 1 year"ExpiresByType image/jpg "access 1 year"ExpiresByType image/jpeg "access 1 year"ExpiresByType image/x-icon "access 1 year"ExpiresByType image/svg+xml "access plus 1 month"ExpiresByType audio/ogg "access plus 1 year"ExpiresByType video/mp4 "access plus 1 year"ExpiresByType video/ogg "access plus 1 year"ExpiresByType video/webm "access plus 1 year"ExpiresByType application/atom+xml "access plus 1 hour"ExpiresByType application/rss+xml "access plus 1 hour"ExpiresByType application/pdf "access 1 month"ExpiresByType application/javascript "access 1 month"ExpiresByType text/x-javascript "access 1 month"ExpiresByType text/x-component "access plus 1 month"ExpiresByType application/x-shockwave-flash "access 1 month"ExpiresByType font/opentype "access plus 1 month"ExpiresByType application/vnd.ms-fontobject "access plus 1 month"ExpiresByType application/x-font-ttf "access plus 1 month"ExpiresByType application/font-woff "access plus 1 month"ExpiresByType application/font-woff2 "access plus 1 month"ExpiresDefault "access 1 month"</IfModule># END EXPIRES CACHING ## BEGIN Cache-Control Headers<ifModule mod_headers.c><filesMatch "\.(ico|jpe?g|png|gif|swf)$">Header set Cache-Control "public"</filesMatch><filesMatch "\.(css)$">Header set Cache-Control "public"</filesMatch><filesMatch "\.(js)$">Header set Cache-Control "private"</filesMatch><filesMatch "\.(x?html?|php)$">Header set Cache-Control "private, must-revalidate"</filesMatch></ifModule>#END Cache-Control Headers# ENABLE MOD PAGESPEED START# COMBINE CSS, COMPRESS IMAGES, REMOVE HTML WHITE SPACE AND COMMENTS<IfModule pagespeed_module>ModPagespeed onModPagespeedEnableFilters rewrite_css,combine_cssModPagespeedEnableFilters recompress_imagesModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webpModPagespeedEnableFilters collapse_whitespace,remove_comments</IfModule># ENABLE LITESPEED CACHE START<IfModule LiteSpeed>CacheEnable publicRewriteEngine OnRewriteCond %{REQUEST_METHOD} ^GET|HEAD$RewriteCond %{HTTP_HOST} ^sample.com|sample.net|sample.org [NC]RewriteCond %{REQUEST_URI} !login|admin|register|post|cronRewriteCond %{QUERY_STRING} !nocacheRewriteRule .* - [E=Cache-Control:max-age=300]</IfModule>#ENABLE LITESPEED CACHE ENDerver level caching.
<FilesMatch "weather-seven-day-forecast-graphic.*.jpg$">ExpiresByType image/jpeg "modification plus 86400 seconds"</FilesMatch>
infinityfree.net directory privacy is broken in the control panel/directory privacy. Download protectedDirectory/.htaccess and delete protectedDirectory/.htaccess Delete protectedDirectory/htpasswd.
Check if you have some important code before deleting .htaccess I had days worth of directory listing styling in .htaccess
Don’t use the Directory Privacy from the control panel anymore. Use Protected Directories from the client area. Login in to your account https://dash.infinityfree.com/login select the account. Click the hamburger and choose Protected Directories or choose Protected Directories.
