웹마스터 팁

말그대로 폴더에 올린 mp3를 자동으로 podcast로 만들어주는 소스입니다.

이번에 아이폰4 출시를 기념으로 이것저것 소스 수정해서 만들었습니다.


특정 폴더에 이 소스올리시고, 해당경로에 mp3를 태그먹여서 올려주시면 자동으로 podcast용 rss 피드를 생성해줍니다.

페이지 방식과 xml 파일생성 방식을 병행할 수 있는데 저는 페이지 방식을 선호합니다.

바로바로 피드가 생성되거든요..


버그가 있는데요, 

1. 한글태그값을 가져오지 못합니다. 제가 문자인코딩부분을 잘 처리못해서 그런것 같습니다.

2. 한글파일처리가 미흡합니다. 링크는 나오는데 다운이 안됩니다. ㅠㅠ 영문파일명으로 사용해야합니다.


수정해서 올려주실 분이 있으시다면 감사하겠습니다.



아래 소스...



<?php


    /* Script: podcastxml_libs.php

     * Description: Lib's used for podcastxml.php script

     * History:

     * Author               Date            Description

     * Sherif Mansour       5/31/2008       Initial Version

     */


    // Functions and Classes

    function stripJunk ($text) {

        $outText = "";

    // Strip non-text characters

        for ($c=0; $c<strlen($text); $c++) {

            if (ord($text[$c]) >= 32 AND ord($text[$c]) <= 122)

                $outText.=$text[$c];

        }


        return $outText;

    }


    class CMP3File {

        //properties

        var $title;

        var $artist;

        var $album;

        var $year;

        var $comment;

        var $genre;

        

        function getid3 ($file)

        { // read the ID3 tag from an MP3 file

            if (file_exists($file))

            { //after verifying the file exists,

                $id_start = filesize($file) - 128;

                

                $fp = fopen($file, "r");

                fseek($fp, $id_start);

                $tag = fread($fp,3);

                if ($tag == "TAG")

                {

                    $this->title    = stripJunk(trim(fread($fp, 30)));

                    $this->artist    = stripJunk(trim(fread($fp, 30)));

                    $this->album    = stripJunk(trim(fread($fp, 30)));

                    $this->year        = stripJunk(trim(fread($fp, 4)));

                    $this->comment    = stripJunk(trim(fread($fp, 30)));

                    $this->genre    = stripJunk(trim(fread($fp, 1)));

                    fclose($fp);

                    return true;

                }

                else

                { //there is no ID3 tag in the file

                    fclose($fp);

                    return false;

                }

            } else //the file doesn't exist

                return false;

        }

    }


    function getDir($mp3Dir) {  

    // Returns directory as array[file]=date in newest to oldest order

        $dirArray = array();

        $diskdir = "./$mp3Dir/";

        if (is_dir($diskdir)) {

            $dh = opendir($diskdir);

            while (($file = readdir($dh)) != false ) {

                if (filetype($diskdir . $file) == "file" && $file[0]  != ".") {

                    if (stristr($file, ".") == ".mp3") {

                        $ftime = filemtime($mp3Dir."/".$file); 

                        $dirArray[$file] = $ftime;

                    }

                }

            }

            closedir($dh);

        }

        //asort($dirArray); Use this if you want sorted by last modified date

        ksort($dirArray); //use this if you want sorted by the key (IE the filename)

        $dirArray = array_reverse($dirArray);

        return $dirArray;

    }



/* Script: podcastxml.php

 * Description: Create an XML feed for podcast by reading a folder of MP3's and reading the ID3 tag for each file.

 * History:

 * Author Date Description

 * Sherif Mansour 05/11/2008 Initial Version

 * Sherif Mansour 3/10/2009 Fixed HTML Entities Bug

 */


/* START: Script Configuration */

error_reporting(E_ALL); //Error reporting flag

$cfg = array(); //The Main Config Array


/* START: Method of operation.*/

/* This defines how you want the script to work. You have two options:

* 'file' OR 'stdout'

* If you chose 'file': This means every time this script runs, it will write the podcast to a file you specify. Use this if there are many podcasts (better perfomance, and schedule a cron job)

* If you choose 'stdout': This will write the podcast XML to the browser using this file itself. Us this if there arent many podcasts, and can affort to have this script run every time someone access it.

*/

$cfg['operation'] = "stdout"; //Values can be 'file' OR 'stdout'

$cfg['file_name'] = "podcast.xml"; //If you have selected file, enter the name of the file

$cfg['file_location'] = "./"; //If you have selected file, enter the relative location of where you want to write the xml file. Dont forget trailing slash!

//NOTE: If you have selected the 'file' mode of operation, make sure you CHMOD that folder to 777 where you want to write to!

/* END: Method of operation. */



    /* START: Config values */

        $cfg['max_feed'] = 10;                                                                          //Maximum number of files to display in the feed

$cfg['tag_title'] = "수원중앙침례교회 PODCAST";                                                     //The Podcast Title

$cfg['tag_description']= "과연! 그 교회, 중앙교회 PODCAST 입니다.";                                          //The Poddcast Description

$cfg['tag_link'] = "http://central.or.kr/podcasts";                                         //The URL for the person providing the podcast

$cfg['root_url'] = "http://central.or.kr/podcasts";                                         //The URL for the person providing the podcast

        $cfg['tag_lang'] = "kr";                                                                     //Language Tag

        $cfg['tag_copyright'] = "수원중앙침례교회";                                              //Copyright

        $cfg['tag_docs'] = "http://central.or.kr/podcasts/";                           //Language Tag

        $cfg['tag_webMaster'] = "admin@central.or.kr";                                         //Author's email

        $cfg['tag_generator']= "PHP Podcast Generator - blog.sherifmansour.com";                        //Generator name (This script!)

        $cfg['tag_ttl']= 60;                                                                            //Podcast Time to Live

        $cfg['abs_url'] = "./";                                                                          //Absolute reference of where the MP3's are stored on the server

        $cfg['tag_author'] = "수원중앙침례교회 음향실";                                                      //Lib files used for this script

$cfg['tag_subtitle'] = "수원중앙침례교회 PODCAST";                                                      //Lib files used for this script

$cfg['tag_summary'] = "수원중앙침례교회의 각종 예배와 행사, 광고, 기사등을 방송합니다.";                                                      //Lib files used for this script

$cfg['tag_owner_name'] = "수원중앙침례교회";                                                      //Lib files used for this script

$cfg['tag_owner_email'] = "admin@central.or.kr";

$cfg['tag_image'] = "";                                                      //Lib files used for this script

$cfg['tag_category'] = "종교/기독교";                                                      //Lib files used for this script


    /* END: Config values */


/* END: Script Configuration */



/*****************************************************************

 * DO NOT EDIT PAST THIS POINT UNLESS YOU KNOW WHAT YOU ARE DOING

 *****************************************************************/


/* START: Script, do not edit past this point */

$output_string = "";


/* Compile header string */

$cfg['root_url'] =  substr($cfg['root_url'], 0, strrpos ($cfg['root_url'], "/")); // Trim off script name itself

$output_string .= "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";

$output_string .= "<rss xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\" version=\"2.0\">\n";

$output_string .=" \n";

$output_string .=" <channel>\n\n";

$output_string .=" <title>".$cfg['tag_title']."</title>\n";

$output_string .=" <description>".$cfg['tag_description']."</description>\n";

$output_string .=" <link>".$cfg['tag_link']."</link>\n";

$output_string .=" <language>".$cfg['tag_lang']."</language>\n";

$output_string .=" <copyright>".$cfg['tag_copyright']."</copyright>\n";

$output_string .=" <lastBuildDate>" . date("r") ."</lastBuildDate>\n";

$output_string .=" <pubDate>" . date("r") ."</pubDate>\n";

$output_string .=" <docs>".$cfg['tag_docs']."</docs>\n";

$output_string .=" <webMaster>".$cfg['tag_webMaster'+ '+ ']."</webMaster>\n";

$output_string .=" \n";

$output_string .=" <itunes:author>".$cfg['tag_author']."</itunes:author>\n";

$output_string .=" <itunes:subtitle>".$cfg['tag_subtitle']."</itunes:subtitle>\n";

$output_string .=" <itunes:summary>".$cfg['tag_summary']."</itunes:summary>\n";

$output_string .=" \n\n";

$output_string .=" <itunes:owner>\n";

$output_string .=" <itunes:name>".$cfg['tag_owner_name']."</itunes:name>\n";

$output_string .=" <itunes:email>".$cfg['tag_owner_email']."</itunes:email>\n";

$output_string .=" </itunes:owner>\n";

$output_string .=" \n";

$output_string .=" \n";

$output_string .=" <itunes:explicit>No</itunes:explicit>\n\n";

$output_string .=" <itunes:image herf=\"".$cfg['tag_image']."\" />\n\n";

$output_string .=" <itunes:category>".$cfg['tag_category']."</itunes:category>\n\n";


/* Loop through the folder and compile the body tags in a string for each MP3 */

$dirArray = getDir($cfg['abs_url']); // Get a list of the current directory


while (list($filename, $filedate) = each($dirArray) AND $cfg['max_feed'] > 0) {

$mp3file = new CMP3File;

$mp3file->getid3 ($filename);

$output_string .= " <item>\n";

$output_string .= " <title>".htmlentities($mp3file->title)."</title>\n";

$output_string .= " <title>".iconv("euc-kr","utf-8","$mp3file->title")."</title>\n";

$output_string .= " <title>".iconv("utf-8","euc-kr","$mp3file->title")."</title>\n";

$output_string .= " <link>".$cfg['tag_link']."/". str_replace(" ", "%20", urlencode($filename)) ."</link>\n";

$output_string .= " <guid>".$cfg['tag_link']."/". str_replace(" ", "%20", urlencode($filename)) ."</guid>\n";

$output_string .= " <description>by ".htmlentities($mp3file->artist). htmlentities($mp3file->album). htmlentities($mp3file->comment)."</description>\n";

$output_string .= " <enclosure url=\"".$cfg['tag_link']."/". str_replace(" ", "%20", urlencode($filename)) ."\" length=\"";

$output_string .= filesize($filename);

$output_string .= "\" type=\"audio/mpeg\"/>\n"; // Training slash for XML

$output_string .=" <category>".$cfg['tag_category']."</category>\n";

$output_string .= " <pubDate>".date("r",$filedate)."</pubDate>\n";

$output_string .= " </item>\n\n";

$cfg['max_feed']--;

}


/* Compile the footer string*/

$output_string .= " </channel>\n</rss>\n";


/* START: Writing string to desired output */

switch ($cfg['operation']){

case 'stdout': header('Content-type: text/xml; charset=UTF-8', true);

echo $output_string;

break;

case 'file': $output_file = $cfg['+ 'file_location'].$cfg['file_name'];

$fh = fopen($output_file, 'w') or die("Error: Cant open file for writing. Check you have the right file, file path and directory is writable.");;

ftruncate($fh, 0);

fwrite($fh, $output_string);

fclose($fh);

break;

default: echo "Error: You havent selected a valid mode of operation in the cfg['operation'] array. Possible values are 'file'|'stdout'";

}

/* END: Writing to desired output */

/* END: Script */

?>

제목 글쓴이 날짜
FTP로 폴더가 삭제가 안될때~! [6] file 웹엔진 2012.01.30
[시니시즘] 파일첨부 버튼 2개 만들기 팁 [1] 시니시즘 2012.01.27
bodex 게시판 댓글 삭제 안 되는 문제(해결) NA답답이 2012.01.28
1.5.1.3용 youtube, vimeo, ted 썸네일 적용 document.item.php 수정 안내 [2] file 하얀마법 2012.01.27
가가라이브 위젯이 메뉴를 가릴때 수정방법 [2] 웹엔진 2012.01.26
XE 1.5 에서 확장변수 검색이 안 되시는 경우 해결책 [5] sejin7940 2012.01.24
v1.5 관리자 페이지에서 v1.4처럼 모듈 목록 펼쳐놓기 [14] file 우진홈 2012.01.21
화일첨부 디렉토리의 빈 폴더 삭제... [13] 카르마 2012.01.20
네이버 신디케이션(syndication)이 standby로 바뀌는 문제 대처 방안 [4] Define 2012.01.19
Xe 1.5에서 파일첨부 안될때 해결방법 [19] file 황비 2012.01.17
v1.5 룰셋(ruleset)과 BOOKMARK 모듈 만들기 [2] file 우진홈 2012.01.16
Xe1.5 + board 1.4[목록설정] [분류관리][게시글관리]느린 로딩해결법 [30] 황비 2012.01.14
1.5.x 버전에서 migration tool 동작불가 문제 [1] 모노소프트 2012.01.13
파일 첨부 버튼이 눌러 지지 않을 때(xe_1.5.2) - 서버에서 해결하기 대암지기 2012.01.11
모듈 이름은 대소문자 구분을 하지 않아요. SkyKiDS 2012.01.09
SEO:타이틀중 게시글제목과 게시판제목의 위치를 바꾸기 [4] 해커다 2012.01.05
FTP 쉬운설치 에러나시는분들 [4] 조양각 2012.01.05
외부페이지에서 롤오버오류 !! oem팩토리 2012.01.03
XE 1.5.1.1 업데이트후 갑자기 댓글 에디터가 나오지않는 문제 해결팁 [3] 재주꾼 2012.01.02
XE 외부페이지 직접접속 차단 및 다국어 설정팁 [4] 라르크앙시엘 2012.01.01