웹마스터 팁

말그대로 폴더에 올린 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 */

?>

제목 글쓴이 날짜
도메인 변경 또는 설치 폴더 변경시 이미지 주소변경하기 file 해피정닷컴 2018.06.08
.htaccess 를 이용해서 도메인 접속시 xe폴더로 자동 이동 시키기 [3] file Double'U' 2014.09.25
FTP로 폴더가 삭제가 안될때~! [6] file 웹엔진 2012.01.30
사이트접속시 제로보드XE폴더로 이동되게 하는 쉬운방법 [8] 부찬™ 2007.08.17
화일첨부 디렉토리의 빈 폴더 삭제... [13] 카르마 2012.01.20
XE 설치 시 안전한 폴더권한 설정하기 (chown 사용) 컴토피아 2014.08.07
사이트 주소로 접속했을때 XE 폴더로 이동하기 팁 [42] 베니 2007.08.16
홈페이지 접속시 XE를 바로 실행하기(XE를 /xe/ 폴더에 설치한 경우) [5] Firstlove 2011.06.12
XE 를 루트로 옮기는 방법과 문제 대응책 정리 (도메인 접속시 xe폴더로 이동 없이 바로 사이트 뜨게 하기) [8] file Gekkou 2009.12.06
grep로 하위 폴더내 파일까지 내용 검색하기 fsfsdas 2011.02.20
wo.to (유료서버) 의 아파치 폴더 인증 방법. 이성헌 2005.12.15
네임서버 설정 ver.1 [/etc 폴더편] [2] 손택수 2002.10.24
제로보드 data 폴더 일괄적으로 소유권 변경 스크립트 [2] 라지엘 2002.07.01
[리눅스]proftp 에서 사용자가 상위 폴더로 이동을 못하게... [3] teenteenv 2002.02.22
웹 계정에서 지워지지 않는 폴더 및 파일 삭제하는 방법 [3] Rising.kr 2008.01.24
폴더에 사진올려놓고 리스트자동으로 만들기 [7] 김인기 2004.02.22
[추천 팁] 폴더내의 파일중에서 특정정보만 뽑아오기. [2] M2Vis 2002.07.12
폴더에 올린 mp3를 자동으로 podcast로 만들어주는 소스... ^^ [2] 하얀마법 2010.09.11
files 폴더안의 cache 폴더/파일 1초만에 지우기 [3] 999 2010.06.21
설치하여 사용 중이던 XE의 폴더 옮기기 [1] file 영구만세 2009.12.02