egbertbouman / youtube-comment-downloader

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

Python 2.x Print vs 3.x Print #3

Closed ghost closed 7 years ago

ghost commented 7 years ago

I am in no way a python expert, nor have I ever written my own script, but you claim that your script is 2.7+ capable and I don't think that's the case. I'm sure that doesn't only mean 2.x variants, but could be wrong.

Believed to have confirmed my guess as:

  File "downloader.py", line 144
    print 'Downloading Youtube comments for video:', youtube_id
                                                  ^
SyntaxError: invalid syntax

EDIT: works great on 2.7! Thanks!

Also I tried updating print to 3.x syntax and it appears there is more than print being the problem. Is it possible to make a script that reads user python version and acts accordingly?

d0tN3t commented 7 years ago

This worked for me on 3.6.1. I ran 2to3 (Python's 2.7 converter to 3.x) and below is what I needed to change. `xis-MacBook-Air:YT xi$ 2to3 downloader.py RefactoringTool: Skipping optional fixer: buffer RefactoringTool: Skipping optional fixer: idioms RefactoringTool: Skipping optional fixer: set_literal RefactoringTool: Skipping optional fixer: ws_comma RefactoringTool: Refactored downloader.py --- downloader.py (original) +++ downloader.py (refactored) @@ -139,19 +139,19 @@ parser.print_usage() raise ValueError('you need to specify a Youtube ID and an output filename')

You will get an error like this "Error: a bytes-like object is required, not 'str'". This just means you need to remove the 'b' in 'wb'. Line: 144 with open(output, 'w') as fp: Then I went into terminal (I'm on a OSX) and ran as my example this. python downloader.py -y fOXKGQw6Ing -o phily_output.json At the time of writing this it grabbed all 7,000 comments. Thanks! & Happy Coding!

egbertbouman commented 7 years ago

@hairypaulsack You're right only Python 2.7 was supported,

@d0tN3t Using your suggestions, I've just added Python 3 support. Thanks!