egbertbouman / youtube-comment-downloader

Simple script for downloading Youtube comments without using the Youtube API
MIT License
881 stars 223 forks source link

[Feature Request] YouTube community post support #102

Closed minamotorin closed 2 years ago

minamotorin commented 2 years ago

Example of post: https://www.youtube.com/post/Ugkx2meuOt7vCSaQP4QsS5v4v-VG5WnVb7RU

For adding support, no adjustments other than the interface are required. Just replace YouTube video URL of downloader.py with YouTube post URL as follows and it works fine.

@@ -40,7 +40,7 @@ class YoutubeCommentDownloader:
                 time.sleep(sleep)

     def get_comments(self, youtube_id, sort_by=SORT_BY_RECENT, language=None, sleep=.1):
-        response = self.session.get(YOUTUBE_VIDEO_URL.format(youtube_id=youtube_id))
+        response = self.session.get('https://www.youtube.com/post/Ugkx2meuOt7vCSaQP4QsS5v4v-VG5WnVb7RU')

         if 'uxe=' in response.request.url:
             self.session.cookies.set('CONSENT', 'YES+cb', domain='.youtube.com')

Thanks.

egbertbouman commented 2 years ago

I'm not sure I understand. How would this improve the script?

minamotorin commented 2 years ago

Thanks for your reply, and sorry for the lack of information. This is just a new feature request.

This script can scrape comments from only YouTube videos currently, but I want to scrape comments from YouTube community posts as follows. This leads to enhancements.

youtube-comment-downloader --postid Ugkx2meuOt7vCSaQP4QsS5v4v-VG5WnVb7RU -o output.json

I don't know what will happen in the future, but at least for now, YouTube community posts can be scraped in the same method as YouTube videos. In the code below, just put a post URL instead of a video URL and it works fine. https://github.com/egbertbouman/youtube-comment-downloader/blob/b59eaf9b336d9bc39410a62de0027669d0fa33f2/youtube_comment_downloader/downloader.py#L43

egbertbouman commented 2 years ago

OK, I get it now. I think that's a great idea! I'll probably implement this in the near future.

Perhaps I'll just add a --url option. This way users can just copy-paste the url and it should work for both community posts and for videos.

egbertbouman commented 2 years ago

I just added this functionality. You can now download community comments as follows:

youtube-comment-downloader --url https://www.youtube.com/post/Ugkx2meuOt7vCSaQP4QsS5v4v-VG5WnVb7RU --output output.json

It works for video URLs as well:

youtube-comment-downloader --url https://www.youtube.com/watch?v=ScMzIvxBSi4 --output output.json
minamotorin commented 2 years ago

Thanks so much! It's also useful for YouTube videos.