Skip to content

Commit

Permalink
Implement recursive folder support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-xo committed Feb 22, 2018
1 parent 3be576d commit a94ebed
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
4 changes: 3 additions & 1 deletion README.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
dir2cast by Ben XO v1.9 (2017-12-27)
dir2cast by Ben XO v1.10 (2018-02-22)
================================================================================

https://github.com/ben-xo/dir2cast/
Expand Down Expand Up @@ -151,6 +151,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
HISTORY
================================================================================

1.10 2018-01-21 Added RECURSIVE_DIRECTORY_ITERATOR option for scanning nested
folders. Suggested by ognjiscar
1.9.1 18-01-21 Small PHP7 fix.
1.9 2017-12-27 Merged changes from cbz:
* Upgraded getID3
Expand Down
3 changes: 3 additions & 0 deletions dir2cast.ini
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
; it will fail. If your MP3 URLs are all wrong, try putting this in manually.
;MP3_URL = http://www.example.foo/my_mp3_folder/

; Uncomment this if you want to check in every sub-folder for new files as well.
;RECURSIVE_DIRECTORY_ITERATOR = true



; *** INFORMATION ABOUT YOUR PODCAST - you SHOULD set this how you like it ***
Expand Down
25 changes: 21 additions & 4 deletions dir2cast.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
/* DEFAULTS *********************************************/

// error handler needs these, so let's set them now.
define('VERSION', '1.9.1');
define('VERSION', '1.10');
define('DIR2CAST_HOMEPAGE', 'https://github.com/ben-xo/dir2cast/');
define('GENERATOR', 'dir2cast ' . VERSION . ' by Ben XO (' . DIR2CAST_HOMEPAGE . ')');

Expand Down Expand Up @@ -485,16 +485,20 @@ class RSS_File_Item extends RSS_Item {
public function __construct($filename)
{
$this->filename = $filename;
$this->extension =
$this->setLinkFromFilename($filename);
parent::__construct();
}

public function setLinkFromFilename($filename)
{
$url = rtrim(MP3_URL, '/') . '/' . rawurlencode(basename($filename));
$url = rtrim(MP3_URL, '/') . '/' . str_replace('%2F', '/', rawurlencode($this->stripBasePath($filename)));
$this->setLink($url);
}

protected function stripBasePath($filename)
{
return ltrim(substr($filename, strlen(MP3_DIR)), '/');
}

public function getType()
{
Expand Down Expand Up @@ -810,7 +814,17 @@ protected function scan()

// scan the dir

$di = new DirectoryIterator($this->source_dir);
if(RECURSIVE_DIRECTORY_ITERATOR)
{
$di = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($this->source_dir),
RecursiveIteratorIterator::SELF_FIRST
);
}
else
{
$di = new DirectoryIterator($this->source_dir);
}

$item_count = 0;
foreach($di as $file)
Expand Down Expand Up @@ -1374,6 +1388,9 @@ public static function defaults()

if(!defined('DESCRIPTION_SOURCE'))
define('DESCRIPTION_SOURCE', 'id3');

if(!defined('RECURSIVE_DIRECTORY_ITERATOR'))
define('RECURSIVE_DIRECTORY_ITERATOR', false);
}

public static function load_from_ini($file)
Expand Down

0 comments on commit a94ebed

Please sign in to comment.