Skip to content

Commit

Permalink
Make channels?part=membership deterministic
Browse files Browse the repository at this point in the history
As requested by someone on [Discord](https://discord.com/channels/@me/1127939666792951859/1235245766789042246).

Verified with 12 requests in a row thanks to:

```py
import requests
from tqdm import tqdm

url = 'http://localhost/YouTube-operational-API/channels'
params = {
    'part': 'membership',
    'id': 'UCADXSO2msINXrTXAHxKoUgg',
}
progressBar = tqdm()
while True:
    response = requests.get(url, params)
    if response.status_code == 500 or response.json()['items'][0]['isMembershipEnabled'] != True:
        break
    progressBar.update(1)
```
  • Loading branch information
Benjamin-Loison committed May 1, 2024
1 parent 852c1d3 commit d8e89c7
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ function getItem($id, $order, $continuationToken)

if ($options['membership']) {
$result = getJSONFromHTML("https://www.youtube.com/channel/$id");
$item['isMembershipEnabled'] = array_key_exists('sponsorButton', $result['header']['c4TabbedHeaderRenderer']);
$item['isMembershipEnabled'] = doesPathExist($result, 'header/c4TabbedHeaderRenderer/sponsorButton') || getValue($result, 'header/pageHeaderRenderer/content/pageHeaderViewModel/actions/flexibleActionsViewModel/actionsRows/0/actions/1/buttonViewModel/targetId', $defaultValue = null) === 'sponsorships-button';
}

if ($options['playlists']) {
Expand Down

1 comment on commit d8e89c7

@Benjamin-Loison
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also verified with 14 requests in a row in production.

Please sign in to comment.