Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Merge pull request #176 from fabi321/main
Browse files Browse the repository at this point in the history
Made ChannelSearch more resilliant, Fixes #175
  • Loading branch information
mytja committed Apr 30, 2022
2 parents 77518c5 + 090d9fb commit 9bbc3d2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions tests/async/search.py
Expand Up @@ -31,6 +31,10 @@ async def main():
result = await search.next()
print(result)

channel = ChannelSearch('The Beatles - Topic', 'UC2XdaAVUannpujzv32jcouQ')
result = await search.next()
print(result)


search = VideosSearch('NoCopyrightSounds')
index = 0
Expand Down
3 changes: 3 additions & 0 deletions tests/sync/search.py
Expand Up @@ -39,3 +39,6 @@

channel = ChannelSearch("Watermelon Sugar", "UCZFWPqqPkFlNwIxcpsLOwew")
print(channel.result(mode=ResultMode.json))

channel = ChannelSearch('The Beatles - Topic', 'UC2XdaAVUannpujzv32jcouQ')
print(channel.result(mode=ResultMode.json))
10 changes: 9 additions & 1 deletion youtubesearchpython/core/channelsearch.py
Expand Up @@ -35,7 +35,15 @@ async def next(self):

def _parseChannelSearchSource(self) -> None:
try:
self.response = self.response["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][-1]["expandableTabRenderer"]["content"]["sectionListRenderer"]["contents"]
last_tab = self.response["contents"]["twoColumnBrowseResultsRenderer"]["tabs"][-1]
if 'expandableTabRenderer' in last_tab:
self.response = last_tab["expandableTabRenderer"]["content"]["sectionListRenderer"]["contents"]
else:
tab_renderer = last_tab["tabRenderer"]
if 'content' in tab_renderer:
self.response = tab_renderer["content"]["sectionListRenderer"]["contents"]
else:
self.response = []
except:
raise Exception('ERROR: Could not parse YouTube response.')

Expand Down

0 comments on commit 9bbc3d2

Please sign in to comment.