Closed poya0524 closed 4 years ago
You can just call the download_comments
function from a separate script. For instance:
import io, json
from downloader import download_comments
with open('input.txt', 'r') as fp:
youtube_ids = fp.readlines()
for youtube_id in youtube_ids:
print('Downloading', youtube_id)
with io.open('output.txt', 'w', encoding='utf8') as fp:
for comment in download_comments(youtube_id):
comment['video_id'] = youtube_id
comment_json = json.dumps(comment, ensure_ascii=False)
print(comment_json.decode('utf-8') if isinstance(comment_json, bytes) else comment_json, file=fp)
I'm guessing this is much cleaner than the method I was using with the pure shell.. :)
It works!!! Thank you so much!!
You're welcome! Since your question seems to be answered, I'll close this issue.
Hello, First thanks for the code, it works! Since I am a beginner of Python and I would like to download comments of 80 videos. (I have already made the list of the ids.) I am wandering Is it possible to download all of them at once and add video id in the output which looks like: {"video id": -----, "cid":------, "text":-------, etc) I guess maybe this can be deal with for loop...?
I'll really appreciate if someone can help me. Thank you!