Skip to content

Instantly share code, notes, and snippets.

@orazdow
Last active November 16, 2020 14:16
Show Gist options
  • Save orazdow/7b982cd255694827bb78843bc17894c9 to your computer and use it in GitHub Desktop.
Save orazdow/7b982cd255694827bb78843bc17894c9 to your computer and use it in GitHub Desktop.
site saving script. only _webdl.bat need (other uses cpp regex)
@echo off
rem webpage downloader: wget and sed for windows required
wget -k -E --default-page=webdl.html %1
setlocal enableDelayedExpansion
if exist webdl.html (
if [%2]==[] (
for /f "delims=" %%i in ('type webdl.html ^| sed -En "s/.*?<title>(.*?)<\/title>.*/\1/p"') do set n=%%i
set n=!n::=!
set n=!n:/=!
set n=!n:\=!
set n=!n:"=!
set n=!n:<=!
set n=!n:>=!
set n=!n:^|=!
echo renaming webdl.html to !n!.html
ren webdl.html "!n!".html
) else (
set n=%2
set n=!n:.html=!
echo renaming webdl.html to !n:"=!.html
ren webdl.html !n!.html
)
)
endlocal
#include <iostream>
#include <fstream>
#include <string>
#include <regex>
using namespace std;
int main(int argc, char* const argv[]){
if(argc == 1){
cerr << "no file specified";
return 0;
}
if(argc == 2){
cerr << "no regex specified";
return 0;
}
fstream file;
file.open(argv[1]);
if(file.fail()){
cerr << "could not open " << argv[1];
return 0;
}
string str, fstr;
while(getline(file, str)){
fstr += (str+'\n');
}
regex e(argv[2]);
smatch match;
regex_search (fstr,match,e);
if(match.size()){
cout << match[match.size()-1];
}
return 0;
}
@echo off
wget -k -E --default-page=webdl.html %1
setlocal enableDelayedExpansion
if exist webdl.html (
if [%2]==[] (
for /f "delims=" %%i in ('fregex webdl.html "<title>(.*?)</title>"') do set n=%%i
set n=!n::=!
set n=!n:/=!
set n=!n:\=!
set n=!n:"=!
set n=!n:<=!
set n=!n:>=!
set n=!n:^|=!
echo renaming webdl.html to !n!.html
ren webdl.html "!n!".html
) else (
set n=%2
set n=!n:.html=!
echo renaming webdl.html to !n:"=!.html
ren webdl.html !n!.html
)
)
endlocal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment