Skip to content

Commit b43ff05

Browse files
authored
Merge pull request #60 from ben-xo/feature/support-m4b-audiobooks-59
Feature/support m4b audiobooks 59
2 parents bb56a6a + e515a45 commit b43ff05

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

CHANGELOG.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
Changelog
22
=========
33

4-
1.33 unreleased * README fixed by @denilsonsa - thanks!
4+
1.34 2022-07-28 * Add support for M4B audiobook files as requested by @crosbyh
5+
Many thanks for your support!
6+
7+
1.33 2022-05-25 * README fixed by @denilsonsa - thanks!
58
* Caching algorithm changed to so that it is no longer dependent
69
on added media files having a newer file date (GitHub #51),
710
and will look for any changes in filesize or date, as well

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Testing dir2cast](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml/badge.svg)](https://github.com/ben-xo/dir2cast/actions/workflows/testing.yml)
22

3+
34
dir2cast by Ben XO v1.34 (2022-07-28)
45
================================================================================
56

@@ -22,10 +23,10 @@ Features:
2223
pick up most of the podcast text straight from the tags in the file (such as
2324
the artist, title and comment tags.)
2425

25-
* supports MP3, MP4, and M4A files
26+
* supports MP3, MP4, M4A and M4B files
2627

2728
* dir2cast will automatically use the ID3 fields from your files for the Author,
28-
Title, etc. ID3v2 is supported, as are the regular tags found in MP4 and M4A
29+
Title, etc. ID3v2 is supported, as are the usual tags found in MP4 / M4A / M4B
2930
files. (Uses getID3, which is bundled with dir2cast.)
3031

3132
* dir2cast will automatically use the cover art embedded in your file as well.
@@ -81,7 +82,7 @@ Please note: the config file will make more sense if you read all of this `READM
8182
before trying the installation instructions.
8283

8384
dir2cast is quite flexible but the general idea is that you add cover art and
84-
tags to your media files - mp3, mp4 or m4a currently supported - and then the
85+
tags to your media files (mp3, mp4, m4a and m4b currently supported) and then the
8586
podcast that it generates uses the tags from your files.
8687

8788
1. Edit `dir2cast.ini` to your taste.

dir2cast.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
/******************************************************************************
4-
* Copyright (c) 2008-2021, Ben XO (me@ben-xo.com).
4+
* Copyright (c) 2008-2022, Ben XO (me@ben-xo.com).
55
*
66
* All rights reserved.
77
*
@@ -56,7 +56,7 @@
5656
/* DEFAULTS *********************************************/
5757

5858
// error handler needs these, so let's set them now.
59-
define('VERSION', '1.33');
59+
define('VERSION', '1.34');
6060
define('DIR2CAST_HOMEPAGE', 'https://github.com/ben-xo/dir2cast/');
6161
define('GENERATOR', 'dir2cast ' . VERSION . ' by Ben XO (' . DIR2CAST_HOMEPAGE . ')');
6262

@@ -1200,6 +1200,7 @@ public function addItem($filename)
12001200
break;
12011201

12021202
case 'm4a':
1203+
case 'm4b':
12031204
$this->addRssFileItem(new M4A_RSS_Item($filename));
12041205
break;
12051206

test/Dir_PodcastTest.php

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,14 @@ public function createTestItems()
3131
file_put_contents('test2.mp4', 'content');
3232
file_put_contents('test3.m4a', 'content');
3333
file_put_contents('test4.other', 'content');
34+
file_put_contents('test5.m4b', 'content');
3435

3536
$filemtime = time();
3637
touch('test1.mp3', $filemtime+50);
3738
touch('test2.mp4', $filemtime);
3839
touch('test3.m4a', $filemtime-50);
3940
touch('test4.other', $filemtime-100);
41+
touch('test5.m4b', $filemtime-75);
4042

4143
return $filemtime;
4244
}
@@ -47,12 +49,14 @@ public function createEmptyTestItems()
4749
file_put_contents('test2.mp4', '');
4850
file_put_contents('test3.m4a', '');
4951
file_put_contents('test4.other', '');
52+
file_put_contents('test5.m4b', '');
5053

5154
$filemtime = time();
5255
touch('test1.mp3', $filemtime+50);
5356
touch('test2.mp4', $filemtime);
5457
touch('test3.m4a', $filemtime-50);
5558
touch('test4.other', $filemtime-100);
59+
touch('test5.m4b', $filemtime-75);
5660

5761
return $filemtime;
5862
}
@@ -65,7 +69,7 @@ public function test_empty_dir_leads_to_empty_podcast()
6569
$this->assertEquals(0, $mp->getMaxMtime());
6670
}
6771

68-
public function test_three_supported_files_of_zero_length_not_added_to_podcast()
72+
public function test_four_supported_files_of_zero_length_not_added_to_podcast()
6973
{
7074
$filemtime = $this->createEmptyTestItems();
7175

@@ -75,17 +79,18 @@ public function test_three_supported_files_of_zero_length_not_added_to_podcast()
7579
$this->assertEquals(0, $mp->getMaxMtime());
7680
}
7781

78-
public function test_three_supported_files_added_to_podcast()
82+
public function test_four_supported_files_added_to_podcast()
7983
{
8084
$filemtime = $this->createTestItems();
8185
$mp = $this->newPodcast();
8286
$content = $mp->generate();
83-
$this->assertCount(3, $mp->getItems());
87+
$this->assertCount(4, $mp->getItems());
8488

8589
$items = $mp->getItems();
8690
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
8791
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
8892
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
93+
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
8994
$this->assertEquals($filemtime+50, $mp->getMaxMtime());
9095
}
9196

@@ -100,12 +105,13 @@ public function test_generating_twice_doesnt_rescan()
100105

101106
$content = $mp->generate(); // generate again
102107

103-
$this->assertCount(3, $mp->getItems());
108+
$this->assertCount(4, $mp->getItems());
104109

105110
$items = $mp->getItems();
106111
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
107112
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
108113
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
114+
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
109115
$this->assertEquals($filemtime+50, $mp->getMaxMtime());
110116
}
111117

@@ -122,6 +128,7 @@ public function test_regenerates_if_metadata_files_added()
122128
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
123129
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
124130
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
131+
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
125132
$this->assertEquals($filemtime+50 - 200, $mp->getMaxMtime());
126133

127134
unset($mp); // releases locks
@@ -144,6 +151,7 @@ public function test_regenerates_if_metadata_files_added()
144151
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
145152
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
146153
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
154+
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
147155
$this->assertEquals($now-500, $mp->getMaxMtime());
148156
$this->assertEquals('party123', $items[1]->getSummary());
149157

@@ -157,10 +165,10 @@ public function test_helpers_added_to_found_items()
157165
$mp = $this->newPodcast();
158166

159167
$helper = $this->createMock(Podcast_Helper::class);
160-
$helper->expects($this->exactly(3))->method('appendToItem');
168+
$helper->expects($this->exactly(4))->method('appendToItem');
161169

162170
$helper2 = $this->createMock(Podcast_Helper::class);
163-
$helper2->expects($this->exactly(3))->method('appendToItem');
171+
$helper2->expects($this->exactly(4))->method('appendToItem');
164172

165173
$mp->addHelper($helper);
166174
$mp->addHelper($helper2);
@@ -200,6 +208,7 @@ protected function delete_test_files()
200208
file_exists('test3.m4a') && unlink('test3.m4a');
201209
file_exists('test4.other') && unlink('test4.other');
202210
file_exists('test2.txt') && unlink('test2.txt');
211+
file_exists('test5.m4b') && unlink('test5.m4b');
203212
}
204213

205214
public function tearDown(): void

test/Dir_Podcast_RecursiveTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,19 @@ public function createTestItems()
2222
mkdir('test2');
2323
mkdir('test3');
2424
mkdir('test4');
25+
mkdir('test5');
2526
file_put_contents('test1/test1.mp3', 'content');
2627
file_put_contents('test2/test2.mp4', 'content');
2728
file_put_contents('test3/test3.m4a', 'content');
2829
file_put_contents('test4/test4.other', 'content');
30+
file_put_contents('test5/test5.m4b', 'content');
2931

3032
$filemtime = time();
3133
touch('test1/test1.mp3', $filemtime+50);
3234
touch('test2/test2.mp4', $filemtime);
3335
touch('test3/test3.m4a', $filemtime-50);
3436
touch('test4/test4.other', $filemtime-100);
37+
touch('test5/test5.m4b', $filemtime-75);
3538

3639
return $filemtime;
3740
}
@@ -42,16 +45,19 @@ public function createEmptyTestItems()
4245
mkdir('test2');
4346
mkdir('test3');
4447
mkdir('test4');
48+
mkdir('test5');
4549
file_put_contents('test1/test1.mp3', '');
4650
file_put_contents('test2/test2.mp4', '');
4751
file_put_contents('test3/test3.m4a', '');
4852
file_put_contents('test4/test4.other', '');
53+
file_put_contents('test5/test5.m4b', '');
4954

5055
$filemtime = time();
5156
touch('test1/test1.mp3', $filemtime+50);
5257
touch('test2/test2.mp4', $filemtime);
5358
touch('test3/test3.m4a', $filemtime-50);
5459
touch('test4/test4.other', $filemtime-100);
60+
touch('test5/test5.m4b', $filemtime-75);
5561

5662
return $filemtime;
5763
}
@@ -69,10 +75,12 @@ protected function delete_test_files()
6975
file_exists('test2/test2.mp4') && unlink('test2/test2.mp4');
7076
file_exists('test3/test3.m4a') && unlink('test3/test3.m4a');
7177
file_exists('test4/test4.other') && unlink('test4/test4.other');
78+
file_exists('test5/test5.m4b') && unlink('test5/test5.m4b');
7279
is_dir('test1') && rmdir('test1');
7380
is_dir('test2') && rmdir('test2');
7481
is_dir('test3') && rmdir('test3');
7582
is_dir('test4') && rmdir('test4');
83+
is_dir('test5') && rmdir('test5');
7684
parent::delete_test_files();
7785
}
7886

@@ -89,6 +97,7 @@ public function test_regenerates_if_metadata_files_added()
8997
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
9098
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
9199
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
100+
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
92101
$this->assertEquals($filemtime+50 - 200, $mp->getMaxMtime());
93102

94103
unset($mp); // releases locks
@@ -111,6 +120,7 @@ public function test_regenerates_if_metadata_files_added()
111120
$this->assertInstanceOf(MP3_RSS_Item::class, $items[0]);
112121
$this->assertInstanceOf(MP4_RSS_Item::class, $items[1]);
113122
$this->assertInstanceOf(M4A_RSS_Item::class, $items[2]);
123+
$this->assertInstanceOf(M4A_RSS_Item::class, $items[3]);
114124
$this->assertEquals($now-500, $mp->getMaxMtime());
115125
$this->assertEquals('party123', $items[1]->getSummary());
116126

0 commit comments

Comments
 (0)