저는 ASP가 주종목이라 요번에 회사에서 외주개발자에게 php프로젝트 맡겼는데
몇몇 작업들은 저보고 하라고그래서 작업한 실소스입니다.
리눅스 php는 거의 초보수준이라 asp프로그래밍 로직에 대입해서 생각하면서
별것도 아닌 결과물을 쉽게 않게 처리했네요.
아래 게시물 중에 ffmpeg 관련된것도 같은 프로젝트 때문...유튜브야 뭐 소스 돌아다니는게 워낙 많아서
어렵지 않았지만, ffmpeg+nfs는 php리눅스 초보자로써는 참 골치아픈 작업이었네요.
제 소스들은 다 직접 사용해보고 올리는거라 믿음을 가지시고 참고하셔도 됩니다.
uccupload.php
<?php
$youtube_email = "유튜브 계정 이메일"; // Change this to your youtube sign in email.
$youtube_password = "패스워드"; // Change this to your youtube sign in password.
$postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=Example";
$curl = curl_init("https://www.google.com/youtube/accounts/ClientLogin");
curl_setopt($curl, CURLOPT_HEADER, "Content-Type:application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec($curl);
curl_close($curl);
list($auth, $youtubeuser) = explode("\n", $response);
list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", $youtubeuser));
' 제목값을 받아오는데 한글 깨져서 처리..그냥 이 페이지에서 입력받아도 됨.
$_REQUEST['title'] = iconv("euc-kr", "utf-8", $_REQUEST['title']);
$youtube_video_title = $_REQUEST['title']; // This is the uploading video title.
$youtube_video_description = "설명"; // This is the uploading video description.
$youtube_video_category = "Entertainment"; // This is the uploading video category. 카테고리는 일일이 확인하면서 간추렸는데...카테고리만 자동으로 불러오는 API는 모르겠음.
$youtube_video_keywords = "키워드"; // This is the uploading video keywords.
$data = '<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">'.$youtube_video_title.'</media:title>
<media:description type="plain">'.$youtube_video_description.'</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
<media:keywords>'.$youtube_video_keywords.'</media:keywords>
</media:group>
</entry>';
$key = "키값"; // Get your key here: http://code.google.com/apis/youtube/dashboard/.
$headers = array("Authorization: GoogleLogin auth=".$authvalue,
"GData-Version: 2",
"X-GData-Key: key=".$key,
"Content-length: ".strlen($data),
"Content-Type: application/atom+xml; charset=UTF-8");
$curl = curl_init("http://gdata.youtube.com/action/GetUploadToken");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
$response = simplexml_load_string(curl_exec($curl));
curl_close($curl);
?>
<?php
$nexturl = "http://경로/ucc_ret.php"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
//document.oncontextmenu=new Function('return false');
//document.ondragstart=new Function('return false');
//document.onselectstart=new Function('return false');
function checkForFile() {
if (document.getElementById('file').value) {
return true;
}
document.getElementById('errMsg').style.display = '';
document.getElementById('form_before').style.display='none';
document.getElementById('form_next').style.display='block';
return false;
}
</script>
</head>
<body>
<div id="form_before">
<form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data" onSubmit="return checkForFile();">
파일 : <input id="file" type="file" name="file"/>
<div id="errMsg" style="display:none;color:red">
영상 파일을 첨부해주세요.
</div><br>
제목 : <? echo($youtube_video_title); ?><br>
<input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
<input type="submit" value="유튜브로 전송" />
</form>
</div>
<br><br><br>
※ 업로드창이 자동으로 닫힐 때까지 창을 닫지 마세요.
</body>
</html>
------------------------------------------------------------------------------------------------------
ucc_ret.php
<?php
$ucc_url = $_REQUEST['id'];
$ucc_status = $_REQUEST['status'];
if($ucc_status == "200"){
?>
<script language="javascript">
<!--
//저는 부모창에다가 값 넘겨주는 식으로 처리함. 이 페이지에서 값 받은걸로 DB저장하든 뭘 하든 맘대로 하면됨.
opener.document.neighborhood_from.bb_2.value='http://www.youtube.com/v/<? echo $ucc_url ?>';
opener.document.getElementById('bb_2_div').innerHTML='http://www.youtube.com/v/<? echo $ucc_url ?>';
window.close();
//-->
</script>
<?php
}else{
?>
<script language="javascript">
<!--
alert("Fail");
window.close();
//-->
</script>
<?php
}
?>
------------------------------------------------------------------------------------------------------
그외에 리스트에서 유튜브 썸네일 불러올땐
http://i2.ytimg.com/vi/<?=str_replace('http://www.youtube.com/v/','',$row[bb_2])?>/default.jpg
이렇게 했습니다.
$row[bb_2]는 위에서 업로드하고 저장한 영상 주소 DB값입니다.
몇몇 작업들은 저보고 하라고그래서 작업한 실소스입니다.
리눅스 php는 거의 초보수준이라 asp프로그래밍 로직에 대입해서 생각하면서
별것도 아닌 결과물을 쉽게 않게 처리했네요.
아래 게시물 중에 ffmpeg 관련된것도 같은 프로젝트 때문...유튜브야 뭐 소스 돌아다니는게 워낙 많아서
어렵지 않았지만, ffmpeg+nfs는 php리눅스 초보자로써는 참 골치아픈 작업이었네요.
제 소스들은 다 직접 사용해보고 올리는거라 믿음을 가지시고 참고하셔도 됩니다.
uccupload.php
<?php
$youtube_email = "유튜브 계정 이메일"; // Change this to your youtube sign in email.
$youtube_password = "패스워드"; // Change this to your youtube sign in password.
$postdata = "Email=".$youtube_email."&Passwd=".$youtube_password."&service=youtube&source=Example";
$curl = curl_init("https://www.google.com/youtube/accounts/ClientLogin");
curl_setopt($curl, CURLOPT_HEADER, "Content-Type:application/x-www-form-urlencoded");
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1);
$response = curl_exec($curl);
curl_close($curl);
list($auth, $youtubeuser) = explode("\n", $response);
list($authlabel, $authvalue) = array_map("trim", explode("=", $auth));
list($youtubeuserlabel, $youtubeuservalue) = array_map("trim", explode("=", $youtubeuser));
' 제목값을 받아오는데 한글 깨져서 처리..그냥 이 페이지에서 입력받아도 됨.
$_REQUEST['title'] = iconv("euc-kr", "utf-8", $_REQUEST['title']);
$youtube_video_title = $_REQUEST['title']; // This is the uploading video title.
$youtube_video_description = "설명"; // This is the uploading video description.
$youtube_video_category = "Entertainment"; // This is the uploading video category. 카테고리는 일일이 확인하면서 간추렸는데...카테고리만 자동으로 불러오는 API는 모르겠음.
$youtube_video_keywords = "키워드"; // This is the uploading video keywords.
$data = '<?xml version="1.0"?>
<entry xmlns="http://www.w3.org/2005/Atom"
xmlns:media="http://search.yahoo.com/mrss/"
xmlns:yt="http://gdata.youtube.com/schemas/2007">
<media:group>
<media:title type="plain">'.$youtube_video_title.'</media:title>
<media:description type="plain">'.$youtube_video_description.'</media:description>
<media:category
scheme="http://gdata.youtube.com/schemas/2007/categories.cat">'.$youtube_video_category.'</media:category>
<media:keywords>'.$youtube_video_keywords.'</media:keywords>
</media:group>
</entry>';
$key = "키값"; // Get your key here: http://code.google.com/apis/youtube/dashboard/.
$headers = array("Authorization: GoogleLogin auth=".$authvalue,
"GData-Version: 2",
"X-GData-Key: key=".$key,
"Content-length: ".strlen($data),
"Content-Type: application/atom+xml; charset=UTF-8");
$curl = curl_init("http://gdata.youtube.com/action/GetUploadToken");
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER["HTTP_USER_AGENT"]);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_REFERER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
$response = simplexml_load_string(curl_exec($curl));
curl_close($curl);
?>
<?php
$nexturl = "http://경로/ucc_ret.php"; // This parameter specifies the URL to which YouTube will redirect the user's browser when the user uploads his video file.
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
//document.oncontextmenu=new Function('return false');
//document.ondragstart=new Function('return false');
//document.onselectstart=new Function('return false');
function checkForFile() {
if (document.getElementById('file').value) {
return true;
}
document.getElementById('errMsg').style.display = '';
document.getElementById('form_before').style.display='none';
document.getElementById('form_next').style.display='block';
return false;
}
</script>
</head>
<body>
<div id="form_before">
<form action="<?php echo($response->url); ?>?nexturl=<?php echo(urlencode($nexturl)); ?>" method="post" enctype="multipart/form-data" onSubmit="return checkForFile();">
파일 : <input id="file" type="file" name="file"/>
<div id="errMsg" style="display:none;color:red">
영상 파일을 첨부해주세요.
</div><br>
제목 : <? echo($youtube_video_title); ?><br>
<input type="hidden" name="token" value="<?php echo($response->token); ?>"/>
<input type="submit" value="유튜브로 전송" />
</form>
</div>
<br><br><br>
※ 업로드창이 자동으로 닫힐 때까지 창을 닫지 마세요.
</body>
</html>
------------------------------------------------------------------------------------------------------
ucc_ret.php
<?php
$ucc_url = $_REQUEST['id'];
$ucc_status = $_REQUEST['status'];
if($ucc_status == "200"){
?>
<script language="javascript">
<!--
//저는 부모창에다가 값 넘겨주는 식으로 처리함. 이 페이지에서 값 받은걸로 DB저장하든 뭘 하든 맘대로 하면됨.
opener.document.neighborhood_from.bb_2.value='http://www.youtube.com/v/<? echo $ucc_url ?>';
opener.document.getElementById('bb_2_div').innerHTML='http://www.youtube.com/v/<? echo $ucc_url ?>';
window.close();
//-->
</script>
<?php
}else{
?>
<script language="javascript">
<!--
alert("Fail");
window.close();
//-->
</script>
<?php
}
?>
------------------------------------------------------------------------------------------------------
그외에 리스트에서 유튜브 썸네일 불러올땐
http://i2.ytimg.com/vi/<?=str_replace('http://www.youtube.com/v/','',$row[bb_2])?>/default.jpg
이렇게 했습니다.
$row[bb_2]는 위에서 업로드하고 저장한 영상 주소 DB값입니다.
댓글 9개
게시글 목록
| 번호 | 제목 |
|---|---|
| 28403 | |
| 28402 | |
| 28401 | |
| 28398 | |
| 28397 | |
| 28394 | |
| 4504 | |
| 26593 |
퍼블리셔
이경우 어떻게 해야할까요??
6
|
| 4502 |
개발자
포인트 어떻게 올리나여
1
|
| 18132 | |
| 28388 | |
| 4496 | |
| 4491 | |
| 4486 |
개발자
도대체...포인트는요...
4
|
| 4483 | |
| 4482 |
개발자
우와 멋져요~
|
| 4479 | |
| 18122 | |
| 18120 |
JavaScript
흔한 트위터,페이스북 퍼가기 자바스크립트
1
|
| 26590 |
퍼블리셔
우왕..퍼블리셔도 생겼네요~
2
|
| 18113 |
Linux
리눅스 FFMPEG 자동실행소스(자작임)
6
|
| 24419 |
기획자
리뉴얼 축하드립니다
1
|
| 4474 |
개발자
리자님 익스7로좀 봐주세용
4
|
| 4465 |
개발자
사이트 리뉴얼의 전말
8
|
| 4461 | |
| 4460 |
개발자
상큼해졌요~
|
| 4451 |
개발자
새로 바뀐 검색 어떠세요?
8
|
| 26589 |
퍼블리셔
이뻐요^^
|
| 4450 | |
| 4448 |
개발자
아니 홈피가 바꼈네요.
1
|
| 24418 |
기획자
너무예쁘게 바뀌었네요.^^
|
| 31037 | |
| 26390 | |
| 4446 |
개발자
오늘 가입했습니다.
1
|
| 26585 |
퍼블리셔
저는 디자이너 이지만요..
3
|
| 26581 | |
| 26578 | |
| 18098 |
PHP
웹 소스 긁어오기
14
|
| 4443 | |
| 18097 | |
| 26388 | |
| 18094 |
Mobile
스마트폰에서 영상소스는?
2
|
| 30596 |
HTML
레이아웃이 비뚤합니다.
3
|
| 26387 | |
| 18091 |
정규표현식
정규식으로 html 태그 지우기
2
|
| 4445 | |
| 18088 |
jQuery
이미지 슬라이더 만들어보았습니다.
2
|
| 18086 |
jQuery
순차애니메이션 질문좀 드리겠습니다.
1
|
| 18085 | |
| 18082 | |
| 18081 | |
| 18078 | |
| 18076 | |
| 18074 |
node.js
node.js 0.8.2 번역 문서
1
|
| 18072 |
jQuery
CSS3처럼 이미지 라운딩 기능의 제이쿼리
1
|
| 18070 |
jQuery
이 플래시메뉴처럼 바꿔 만들려면...
1
|
| 18069 | |
| 18066 |
Mobile
가로 폭 문제
2
|
| 18064 |
MySQL
MySQL 테이블명 대소문자 구분안하기
1
|
| 18057 | |
| 18056 |
Flash
플래시 네비 관련
|
| 30588 |
HTML
DIV의 justify 정렬 문제
7
|
| 18055 |
JavaScript
ie 에서는 되는데 크롬에서는 왜 안될까요?
|
| 18054 | |
| 30585 | |
| 18051 | |
| 18050 |
jQuery
이미지 슬라이드 질문 드립니다.
|
| 18048 |
Mobile
모바일 페이지 확대 축소 도움부탁려요
1
|
| 18047 | |
| 18044 |
JavaScript
HTTP 로그인 인증창에 대해 질문합니다 도와주세요ㅠㅠ
2
|
| 26386 | |
| 18042 | |
| 30580 | |
| 4425 | |
| 18039 |
JavaScript
자바에서...
2
|
| 18037 | |
| 18031 |
JavaScript
list.skin.php에서 자바스크립트 출력 문제 입니다.
5
|
| 18028 | |
| 18027 |
Mobile
모바일 사이트는 웹표준 코딩 할려면 어떻게 하나요
|
| 18022 |
JavaScript
JScript.Encode 복호화 방법
4
|
| 18018 |
MySQL
db 값이 가끔 안넘어가는경우가.....
3
|
| 18016 | |
| 18009 | |
| 4423 | |
| 18003 |
jQuery
메인 탭 롤링 배너 입니다.
5
|
| 18000 |
JavaScript
jQuery 쉽게 참고 할만한 사이트 없나요?
2
|
| 17999 |
node.js
NodeJS 추천사이트
|
| 17996 |
JavaScript
팝업창 관련 질문드려요!
2
|
| 17993 |
JavaScript
고수님들 도와주세요. "웹 페이지 오류 세부 정보"에러가 뜨는데
2
|
| 17989 | |
| 17987 | |
| 17986 | |
| 17985 |
jQuery
jquery 드롭다운메뉴 질문입니다.
|
| 17984 |
jQuery
JQuery 소스 해결 좀 부탁드립니다.
|
| 4411 | |
| 17979 | |
| 30576 | |
| 26383 | |
| 17975 | |
| 30569 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기