2021년 4월 17일 토요일
2020년 10월 14일 수요일
유튜브 영상을 광고 및 설치 없이 다운로드 하는 방법 (노설치)
SecureKim
오후 5:03
광고, 다운로드, 설치 안함, 자동으로, AdBlock, Javascript, y2mate, Youtube
No comments
저는 유튜브 영상 다운로드 할 때 y2mate.com 을 이용하곤 하는데
여기가 성인 광고가 엄청 많이 뜹니다.
게다가 다운로드를 클릭하면 하라는 다운로드는 안하고
계속 리다이렉트 되면서 광고가 뜨고
팝업 광고가 뜨고 마지막까지 창을 닫아도 광고가 뜹니다.
그런데 또 AdBlock 같은것을 설치해 광고를 막으면 아예 다운로드가 되지 않습니다.
저는 이게 너무 환멸이 나서 광고 없이 자동으로 다운로드하는 코드를 작성했습니다.
사용방법
1. 아래 코드를 더블클릭해서 "원하는유튜브주소" 부분만 수정한 뒤 ctrl+A+C로 복사합니다.
2. y2mate.com 으로 이동해서 F12를 누릅니다.
3. console 탭에 코드를 붙여넣고 엔터를 눌러 실행합니다.
4. 알아서 컨버팅 후 창이 닫히고 자동으로 다운로드가 실행 됩니다.
5. 다운로드 상태는 크롬 사용시 주소창에 chrome://downloads/ 를 치면 볼 수 있습니다.
(엣지의 경우 edge://downloads)
URL = "원하는유튜브주소"
y2m(URL)
var page;
function y2m(youtubeURL){
page = window.open("https://y2mate.com/kr/youtube/"+getURL(youtubeURL),"securekim", "width=400,height=300", true);
download();
}
function getURL(youtubeURL){
if(youtubeURL.split("://")[1].split(".")[0] == "youtu") return youtubeURL.split("be/")[1];
else return youtubeURL.split("watch?v=")[1].split("&")[0];
}
function download(){
clickFile = setInterval(function() {
try{
page.document.querySelector("#mp4 > table > tbody > tr:nth-child(1) > td.txt-center > a").click();
clearInterval(clickFile);
} catch(e){console.log("Loading : "+e)}
}, 1000);
downloadFile = setInterval(function() {
try{
a = page.document.querySelector("#process-result > div > a").href
page.window.location.href = a;
setTimeout(()=>{page.close();},5000);
clearInterval(downloadFile);
} catch(e){console.log("Converting : "+e)}
}, 1500);
setInterval(function() {
try{
var iframes = page.document.querySelectorAll('iframe');
for (var i = 0; i < iframes.length; i++) {
iframes[i].parentNode.removeChild(iframes[i]);
}
}catch(e){}
},500);
}
2020년 9월 21일 월요일
2019년 2월 9일 토요일
Javascript 배열 복사 (Deep copy, Shallow copy)
SecureKim
오전 2:01
깊은 복사, 복사, 얕은 복사, Array, Deep copy, Javascript, Node.js, Shallow copy
2 comments
자바스크립트 변수 중 배열을 복사하는 것은 두가지 유형이 있습니다.
copyArr = originArr 로는 일반적으로 의도하는 Deep copy가 이루어 지지 않기 때문에, 아래를 참조하시기 바랍니다.
1. 참조
origin = [1,2,3];var copy = origin;
copy 된 변수가 origin 을 가리키고 있는 상태입니다.
즉, copy 값이 변경되면 origin 도 함께 변경됩니다.
copy[1] = 5; // origin [1, 5, 3];
2. Shallow copy
copy 된 변수의 값이 변경되어도 origin 은 변하지 않습니다.Example
Speed
Deep copy 에서 가장 빠른것은 slice(0) 이므로 이것을 이용하면 되겠습니다.2018년 12월 27일 목요일
Node.js 에서 for 문 안에 있는 비동기 함수에 대해 동기 맞춰주는 방법
SecureKim
오전 12:37
비동기, 포문, async, await, for loop, Javascript, Node.js, pattern
No comments
for loop in async/await javascript pattern
/*
for 문 안에 있는 Async 함수를 Sync 하는 패턴으로
은근히 자주 쓰이는데 막상 쓰려면 찾기도 만들기도 어려운 개똥같은 패턴이라고 할 수 있다.
아래 시나리오는,
for 문을 돌면서 비동기 함수인 pushAsync 를 호출해서
datas 에 6,7,8,9,10 을 추가하려는 상황이다.
*/
console.log("=== START !");
datas = [1, 2, 3, 4, 5];
setTimeout (() => {
//의외로 [1, 2, 3, 4, 5] 가 나오지 않는다.
console.log("===== Amazing : " + datas);
}, 3000);
printAll();
/*
아래에서 번외로, printAll 에서 async 와 await 를 삭제하면 재미있는 일이 일어난다.
pushAsync 5개를 한꺼번에 실행하고 setTimeout 이 한꺼번에 등록되면서,
1초가 지난 후 연속적으로 5개가 실행 된다.
*/
async function printAll() {
for(var i = 0; i < 5; i++ ) { // for 안에서 비동기 함수가 동작할 것이다.
await pushAsync(i); //promise 를 리턴해야 await 로 사용 가능 하다.
}
console.log("=== END ? : " + datas);
}
function pushAsync(i) {
return new Promise((resolve) => {
setTimeout(() => {
console.log("Add " + (6 + i) + " to Array.");
datas.push(6 + i);
resolve(datas);
}, 1000);
});
}
// 비동기 프로그래밍을 많이 해왔다면
// 아래의 결과는 놀랍지 않을 것이다.
console.log("=== Not amazing : " + datas);
결과
=== START ! ===
Not amazing : 1,2,3,4,5
Add 6 to Array.
Add 7 to Array.
===== Amazing : 1,2,3,4,5,6,7
Add 8 to Array.
Add 9 to Array.
Add 10 to Array.
=== END ? : 1,2,3,4,5,6,7,8,9,10
2018년 8월 26일 일요일
Javascript 배열의 모든 것 1탄 ( 선언, 정렬, 2차원배열, 멀티 소팅, 순열, 조합 )
SecureKim
오전 2:09
2차원 배열, 배열, 복사, 순열, 자바스크립트, 정렬, 조합, Array, combination, copy, Javascript, Node.js, permutation, sort
No comments
ㆍ배열의 선언
// 5개 짜리 배열 선언
var origin = new Array (5);
// 5개 짜리 배열을 선언 할 때 0으로 초기화 하기
var origin = Array.apply(null, new Array(5)).map(Number.prototype.valueOf,0);
// 5개 짜리 배열을 선언 할 때 "securekim" 으로 초기화 하기
var origin = Array.apply(null, new Array(5)).map(String.prototype.valueOf,"securekim");
// 배열의 복사 (Deep copy)
// for 문 돌면서 직접 대입하는것이 가장 빠르지만, 이것이 그 다음으로 빠르다. 코드가 간결하다는 장점이 있다.
var copy = origin.slice(0);
//참고로 map 이 가장 느리다. (https://jsperf.com/cloning-arrays/3)
var copy = origin.map(x=>(x));
// 배열의 간단 정렬 - 내부 알고리즘은 Merge sort. 브라우저별로 다를 수 있음.
origin.sort(function(a, b) {
return a - b;
});
ㆍ2차원 배열
2차원 배열이라는게 따로 있는건 아니고 배열 안에 배열을 선언하는 것.
// x,y (4,2) 짜리 배열 선언
// ? ? ? ?
// ? ? ? ?
var origin = new Array( new Array(4), new Array(4) );
// 이런 이상한 모양의 배열도 만들 수 있음.
// ? ? ? ?
// ? ?
// ? ? ? ?
var origin = new Array( new Array(4), new Array(2), new Array(4) );
// 배열의 복사 (Deep copy)
// 방법 1.
var copy = new Array(origin.length);
for(var i in origin){
copy[i] = origin[i].slice(0);
}
// 방법 2.
var copy = origin.map(x => x.map( y=>(y) ));
// 배열 복사(Deep copy) 하면서 0으로 초기화 하기
// 방법 1.
var copy = new Array(origin.length);
for(var i in origin){
copy[i] = Array.apply(null, new Array(origin[i].length)).map(Number.prototype.valueOf,0);
}
// 방법 2.
var copy = origin.map(x => x.map( y=>(0) ));
ㆍ배열의 정렬 (멀티 소팅)
툰 아저씨가 만들어 놓은 것을 사용하자.
https://github.com/Teun/thenBy.js/blob/master/thenBy.js
| /*** | |
| Copyright 2013 Teun Duynstee | |
| Licensed under the Apache License, Version 2.0 (the "License"); | |
| you may not use this file except in compliance with the License. | |
| You may obtain a copy of the License at | |
| http://www.apache.org/licenses/LICENSE-2.0 | |
| Unless required by applicable law or agreed to in writing, software | |
| distributed under the License is distributed on an "AS IS" BASIS, | |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| See the License for the specific language governing permissions and | |
| limitations under the License. | |
| */ | |
| var firstBy = (function() { | |
| function identity(v){return v;} | |
| function ignoreCase(v){return typeof(v)==="string" ? v.toLowerCase() : v;} | |
| function makeCompareFunction(f, opt){ | |
| opt = typeof(opt)==="number" ? {direction:opt} : opt||{}; | |
| if(typeof(f)!="function"){ | |
| var prop = f; | |
| // make unary function | |
| f = function(v1){return !!v1[prop] ? v1[prop] : "";} | |
| } | |
| if(f.length === 1) { | |
| // f is a unary function mapping a single item to its sort score | |
| var uf = f; | |
| var preprocess = opt.ignoreCase?ignoreCase:identity; | |
| var cmp = opt.cmp || function(v1,v2) {return v1 < v2 ? -1 : v1 > v2 ? 1 : 0;} | |
| f = function(v1,v2) {return cmp(preprocess(uf(v1)), preprocess(uf(v2)));} | |
| } | |
| if(opt.direction === -1) return function(v1,v2){return -f(v1,v2)}; | |
| return f; | |
| } | |
| /* adds a secondary compare function to the target function (`this` context) | |
| which is applied in case the first one returns 0 (equal) | |
| returns a new compare function, which has a `thenBy` method as well */ | |
| function tb(func, opt) { | |
| /* should get value false for the first call. This can be done by calling the | |
| exported function, or the firstBy property on it (for es6 module compatibility) | |
| */ | |
| var x = (typeof(this) == "function" && !this.firstBy) ? this : false; | |
| var y = makeCompareFunction(func, opt); | |
| var f = x ? function(a, b) { | |
| return x(a,b) || y(a,b); | |
| } | |
| : y; | |
| f.thenBy = tb; | |
| return f; | |
| } | |
| tb.firstBy = tb; | |
| return tb; | |
| })(); |
var people = [{weight:70, height:170, name:"BRABO" },{weight:70, height:170, name:"CHARLIE" },{weight:70, height:170, name:"ALPHA" },{weight:70, height:175, name:"BRABO" },{weight:70, height:175, name:"CHARLIE" },{weight:70, height:175, name:"ALPHA" },{weight:75, height:170, name:"BRABO" },{weight:75, height:170, name:"CHARLIE" },{weight:75, height:170, name:"ALPHA" },{weight:90, height:170, name:"BRABO" },{weight:75, height:190, name:"CHARLIE" },{weight:75, height:190, name:"ALPHA" },]
people.sort( firstBy(function (v1, v2) { return v1.name < v2.name ? -1 : v1.name > v2.name ? 1: 0; }) .thenBy(function (v1, v2) { return v1.height- v2.height; }) .thenBy(function (v1, v2) { return v2.weight - v1.weight; }) );
// 2차원 배열인 경우.people.sort( firstBy(function (v1, v2) { return v1[2] < v2[2] ? -1 : v1[2] > v2[2] ? 1: 0; }) .thenBy(function (v1, v2) { return v1[1] - v2[1]; }) .thenBy(function (v1, v2) { return v2[0] - v1[0]; }) );
ㆍ배열의 순열과 조합


