This commit is contained in:
Dag 2023-10-16 03:43:18 +02:00 committed by GitHub
parent ef5bd83bd0
commit 563c2a345b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 23 deletions

View File

@ -113,7 +113,12 @@ class ARDAudiothekBridge extends BridgeAbstract
$item['timestamp'] = $audio->publicationStartDateAndTime;
$item['uid'] = $audio->id;
$item['author'] = $audio->programSet->publicationService->title;
$item['categories'] = [ $audio->programSet->editorialCategories->title ];
$category = $audio->programSet->editorialCategories->title ?? null;
if ($category) {
$item['categories'] = [$category];
}
$this->items[] = $item;
}
}

View File

@ -96,7 +96,6 @@ class YoutubeBridge extends BridgeAbstract
private function collectDataInternal()
{
$xml = '';
$html = '';
$url_feed = '';
$url_listing = '';
@ -115,16 +114,13 @@ class YoutubeBridge extends BridgeAbstract
if ($username) {
// user and channel
$request = $username;
$url_feed = self::URI . '/feeds/videos.xml?user=' . urlencode($request);
$url_listing = self::URI . '/user/' . urlencode($request) . '/videos';
$url_feed = self::URI . '/feeds/videos.xml?user=' . urlencode($username);
$url_listing = self::URI . '/user/' . urlencode($username) . '/videos';
} elseif ($channel) {
$request = $channel;
$url_feed = self::URI . '/feeds/videos.xml?channel_id=' . urlencode($request);
$url_listing = self::URI . '/channel/' . urlencode($request) . '/videos';
$url_feed = self::URI . '/feeds/videos.xml?channel_id=' . urlencode($channel);
$url_listing = self::URI . '/channel/' . urlencode($channel) . '/videos';
} elseif ($custom) {
$request = $custom;
$url_listing = self::URI . '/' . urlencode($request) . '/videos';
$url_listing = self::URI . '/' . urlencode($custom) . '/videos';
}
if ($url_feed || $url_listing) {
@ -152,7 +148,7 @@ class YoutubeBridge extends BridgeAbstract
// $jsonData = $jsonData->itemSectionRenderer->contents[0]->gridRenderer->items;
$this->fetchItemsFromFromJsonData($jsonData);
} else {
returnServerError('Unable to get data from YouTube. Username/Channel: ' . $request);
returnServerError('Unable to get data from YouTube');
}
} else {
// Fetch the xml feed
@ -162,13 +158,8 @@ class YoutubeBridge extends BridgeAbstract
$this->feedName = str_replace(' - YouTube', '', $html->find('title', 0)->plaintext);
} elseif ($playlist) {
// playlist
// TODO: this mode makes a lot of excess video query requests.
// To make less requests, we need to cache following dictionary "videoId -> datePublished, duration"
// This cache will be used to find out, which videos to fetch
// to make feed of 15 items or more, if there a lot of videos published on that date.
$request = $playlist;
$url_feed = self::URI . '/feeds/videos.xml?playlist_id=' . urlencode($request);
$url_listing = self::URI . '/playlist?list=' . urlencode($request);
$url_feed = self::URI . '/feeds/videos.xml?playlist_id=' . urlencode($playlist);
$url_listing = self::URI . '/playlist?list=' . urlencode($playlist);
$html = $this->fetch($url_listing);
$jsonData = $this->extractJsonFromHtml($html);
// TODO: this method returns only first 100 video items
@ -194,8 +185,7 @@ class YoutubeBridge extends BridgeAbstract
});
} elseif ($search) {
// search
$request = $search;
$url_listing = self::URI . '/results?search_query=' . urlencode($request) . '&sp=CAI%253D';
$url_listing = self::URI . '/results?search_query=' . urlencode($search) . '&sp=CAI%253D';
$html = $this->fetch($url_listing);
$jsonData = $this->extractJsonFromHtml($html);
$jsonData = $jsonData->contents->twoColumnSearchResultsRenderer->primaryContents;
@ -209,10 +199,9 @@ class YoutubeBridge extends BridgeAbstract
}
$this->fetchItemsFromFromJsonData($jsonData);
$this->feeduri = $url_listing;
$this->feedName = 'Search: ' . $request;
$this->feedName = 'Search: ' . $search;
} else {
returnClientError("You must either specify either:\n - YouTube
username (?u=...)\n - Channel id (?c=...)\n - Playlist id (?p=...)\n - Search (?s=...)");
returnClientError("You must either specify either:\n - YouTube username (?u=...)\n - Channel id (?c=...)\n - Playlist id (?p=...)\n - Search (?s=...)");
}
}