Some tweaks
This commit is contained in:
		
							parent
							
								
									d4ab82c07e
								
							
						
					
					
						commit
						8f8ffe3e7b
					
				
					 7 changed files with 164 additions and 87 deletions
				
			
		|  | @ -1,39 +0,0 @@ | |||
| from tests import CLIENT | ||||
| 
 | ||||
| 
 | ||||
| def test_channel_by_id(channel_id: str='UCuAXFkgsw1L7xaCfnd5JJOw') -> None: | ||||
|     """ | ||||
|         Prints out information about a channel by its ID. | ||||
|     """ | ||||
| 
 | ||||
|     channel = CLIENT.get_channel_by_id(channel_id) | ||||
|     assert channel.id == channel_id | ||||
| 
 | ||||
|     print(f""" | ||||
|         Channel ID: {channel_id} | ||||
|         Name: {channel.name} | ||||
|         Description: {channel.description} | ||||
|         Subscriber count: {channel.subscriber_count} | ||||
|     """) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| def test_channel_by_name(channel_name: str='SusanWojcicki') -> None: | ||||
|     """ | ||||
|         Prints out information about a channel by its ID. | ||||
|     """ | ||||
| 
 | ||||
|     channel = CLIENT.get_channel_by_name(channel_name) | ||||
| 
 | ||||
|     print(f""" | ||||
|         Channel ID: {channel.id} | ||||
|         Name: {channel.name} | ||||
|         Description: {channel.description} | ||||
|         Subscriber count: {channel.subscriber_count} | ||||
|     """) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     test_channel_by_id() | ||||
|     test_channel_by_name() | ||||
							
								
								
									
										58
									
								
								tests/test_channels.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								tests/test_channels.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,58 @@ | |||
| from tests import CLIENT | ||||
| 
 | ||||
| from datetime import timedelta | ||||
| from random import choice | ||||
| 
 | ||||
| 
 | ||||
| def test_channel_by_id(channel_id: str='UCuAXFkgsw1L7xaCfnd5JJOw') -> None: | ||||
|     """ | ||||
|         Prints out information about a channel by its ID. | ||||
|     """ | ||||
| 
 | ||||
|     channel = CLIENT.get_channel_by_id(channel_id) | ||||
| 
 | ||||
|     video_id =  channel.uploaded_videos[0].url.removeprefix('/watch?v=') | ||||
|     likes = CLIENT.get_video(video_id).likes | ||||
| 
 | ||||
|     print(f"Total likes for last video of {channel.name}: {likes}") | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| def test_channel_by_name(channel_name: str='SusanWojcicki') -> None: | ||||
|     """ | ||||
|         Prints out information about a channel by its ID. | ||||
|     """ | ||||
| 
 | ||||
|     channel = CLIENT.get_channel_by_name(channel_name) | ||||
| 
 | ||||
|     print(f""" | ||||
|         Channel ID: {channel.id} | ||||
|         Name: {channel.name} | ||||
|         Description: {channel.description} | ||||
|         Subscriber count: {channel.subscriber_count} | ||||
|     """) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| def test_get_watchtime_trending() -> None: | ||||
|     """ | ||||
|         Prints out the total watchtime for recent videos of a random trending channel  | ||||
|     """ | ||||
| 
 | ||||
|     trending_channel_id = choice(CLIENT.get_trending('SK')).uploader_url.removeprefix('/channel/') | ||||
|     trending_channel = CLIENT.get_channel_by_id(trending_channel_id) | ||||
| 
 | ||||
| 
 | ||||
|     total_watchtime = timedelta(milliseconds=0) | ||||
| 
 | ||||
|     for video in trending_channel.uploaded_videos: | ||||
|         total_watchtime += video.duration | ||||
| 
 | ||||
|     print(f"Total watchtime for recent {len(trending_channel.uploaded_videos)} videos of {trending_channel.name} (https://youtube.com/channel/{trending_channel.id}): {total_watchtime}") | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     test_channel_by_name() | ||||
|     test_channel_by_id() | ||||
|     test_get_watchtime_trending() | ||||
							
								
								
									
										17
									
								
								tests/test_suggestions.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										17
									
								
								tests/test_suggestions.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,17 @@ | |||
| from tests import CLIENT | ||||
| 
 | ||||
| 
 | ||||
| def test_suggestions(search_query: str='Susan') -> None: | ||||
|     """ | ||||
|         Obtains search suggestions for a query. | ||||
|     """ | ||||
| 
 | ||||
|     suggestions = CLIENT.get_search_suggestions(search_query) | ||||
| 
 | ||||
|     assert len(suggestions) > 0 | ||||
|     print(suggestions) | ||||
| 
 | ||||
| 
 | ||||
| 
 | ||||
| if __name__ == '__main__': | ||||
|     test_suggestions() | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue