Skip to content

Commit

Permalink
Introduce a dedicated class for generic operations
Browse files Browse the repository at this point in the history
  • Loading branch information
kasparsd committed Nov 27, 2019
1 parent e4c61b9 commit 5b96aa6
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 24 deletions.
26 changes: 2 additions & 24 deletions src/ComposerScripts.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,9 @@ class ComposerScripts {
const PODCAST_PLIST_PATH = 'Library/Containers/com.apple.podcasts/Data/Documents/PodcastsDB.plist';

public static function toOpml( Event $event ) {
$parser = new Parser( self::defaultPlist() );
$opml = new OpmlWriter();
$tools = new Tools( self::defaultPlist() );

foreach ( $parser->subscriptions() as $feed ) {
$item = [
'type' => 'rss',
'title' => $feed['title'],
'feedUrl' => $feed['feedUrl'],
];

if ( ! empty( $feed['storeId'] ) ) {
$item['htmlUrl'] = self::podcastIdToUrl( $feed['storeId'] );
}

$opml->addItem( $item );
}

echo $opml->render();
}

public static function podcastIdToUrl( $id ) {
return sprintf(
'https://podcasts.apple.com/us/podcast/id%d',
$id
);
echo $tools->toOpml();
}

public static function defaultPlist() {
Expand Down
41 changes: 41 additions & 0 deletions src/Tools.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace Kasparsd\ApplePodcastsTools;

class Tools {

protected $db_file;

public function __construct( $db_file ) {
$this->db_file = $db_file;
}

public function podcastIdToUrl( $id ) {
return sprintf(
'https://podcasts.apple.com/us/podcast/id%d',
$id
);
}

public function toOpml() {
$parser = new Parser( $this->db_file );
$opml = new OpmlWriter();

foreach ( $parser->subscriptions() as $feed ) {
$item = [
'type' => 'rss',
'title' => $feed['title'],
'feedUrl' => $feed['feedUrl'],
];

if ( ! empty( $feed['storeId'] ) ) {
$item['htmlUrl'] = $this->podcastIdToUrl( $feed['storeId'] );
}

$opml->addItem( $item );
}

return $opml->render();
}

}

0 comments on commit 5b96aa6

Please sign in to comment.