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['timestamp'] = $audio->publicationStartDateAndTime;
$item['uid'] = $audio->id; $item['uid'] = $audio->id;
$item['author'] = $audio->programSet->publicationService->title; $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; $this->items[] = $item;
} }
} }

View File

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