Showing
2 changed files
with
15 additions
and
16 deletions
| ... | @@ -157,26 +157,18 @@ def main(): | ... | @@ -157,26 +157,18 @@ def main(): |
| 157 | Youtube_id1 = input('Youtube_ID 입력 :') | 157 | Youtube_id1 = input('Youtube_ID 입력 :') |
| 158 | ## Cutting Link를 받고 id만 딸 수 있도록 | 158 | ## Cutting Link를 받고 id만 딸 수 있도록 |
| 159 | Youtube_id1 = video_id(Youtube_id1) | 159 | Youtube_id1 = video_id(Youtube_id1) |
| 160 | - Output1 = input('결과를 받을 파일 입력 :') | 160 | + youtube_id = Youtube_id1 |
| 161 | - Limit1 = input('제한 갯수 입력 : ') | ||
| 162 | - ##### argument로 받지 않고 input으로 받기 위한 것 | ||
| 163 | try: | 161 | try: |
| 164 | # args = parser.parse_args(argv) | 162 | # args = parser.parse_args(argv) |
| 165 | 163 | ||
| 166 | #youtube_id = args.youtubeid | 164 | #youtube_id = args.youtubeid |
| 167 | #output = args.output | 165 | #output = args.output |
| 168 | #limit = args.limit | 166 | #limit = args.limit |
| 169 | - result_List =[] | 167 | + result_List = [] |
| 170 | - youtube_id = Youtube_id1 | ||
| 171 | - output = Output1 | ||
| 172 | ## input 값을 받고 값에 할당 | 168 | ## input 값을 받고 값에 할당 |
| 173 | 169 | ||
| 174 | - if Limit1 == '' : | ||
| 175 | - Limit1 = 100 | ||
| 176 | - Limit1 = int(Limit1) | ||
| 177 | - limit = Limit1 | ||
| 178 | ## Limit에 빈 값이 들어갈 경우 Default 값으로 100을 넣게 하였음 | 170 | ## Limit에 빈 값이 들어갈 경우 Default 값으로 100을 넣게 하였음 |
| 179 | - if not youtube_id or not output: | 171 | + if not youtube_id : |
| 180 | #parser.print_usage() | 172 | #parser.print_usage() |
| 181 | #raise ValueError('you need to specify a Youtube ID and an output filename') | 173 | #raise ValueError('you need to specify a Youtube ID and an output filename') |
| 182 | raise ValueError('올바른 입력 값을 입력하세요') | 174 | raise ValueError('올바른 입력 값을 입력하세요') |
| ... | @@ -185,21 +177,30 @@ def main(): | ... | @@ -185,21 +177,30 @@ def main(): |
| 185 | count = 0 | 177 | count = 0 |
| 186 | Number = input(' 저장 - 0 저장 안함- 1 : ') | 178 | Number = input(' 저장 - 0 저장 안함- 1 : ') |
| 187 | if Number == '0' : | 179 | if Number == '0' : |
| 180 | + Output1 = input('결과를 받을 파일 입력 :') | ||
| 181 | + Limit1 = input('제한 갯수 입력 : ') | ||
| 182 | + if Limit1 == '' : | ||
| 183 | + Limit1 = 100 | ||
| 184 | + Limit1 = int(Limit1) | ||
| 185 | + limit = int(Limit1) | ||
| 186 | + | ||
| 187 | + output = Output1 | ||
| 188 | + ##### argument로 받지 않고 input으로 받기 위한 것 | ||
| 188 | with io.open(output, 'w', encoding='utf8') as fp: | 189 | with io.open(output, 'w', encoding='utf8') as fp: |
| 189 | for comment in download_comments(youtube_id): | 190 | for comment in download_comments(youtube_id): |
| 190 | comment_json = json.dumps(comment, ensure_ascii=False) | 191 | comment_json = json.dumps(comment, ensure_ascii=False) |
| 191 | print(comment_json.decode('utf-8') if isinstance(comment_json, bytes) else comment_json, file=fp) | 192 | print(comment_json.decode('utf-8') if isinstance(comment_json, bytes) else comment_json, file=fp) |
| 192 | count += 1 | 193 | count += 1 |
| 193 | - sys.stdout.write('Downloaded %d comment(s)\r' % count) | ||
| 194 | sys.stdout.flush() | 194 | sys.stdout.flush() |
| 195 | if limit and count >= limit: | 195 | if limit and count >= limit: |
| 196 | - break | 196 | + print('Downloaded {} comment(s)\r'.format(count)) |
| 197 | print('\nDone!') | 197 | print('\nDone!') |
| 198 | + break | ||
| 199 | + | ||
| 198 | else : | 200 | else : |
| 199 | i = 0 | 201 | i = 0 |
| 200 | for comment in download_comments(youtube_id): | 202 | for comment in download_comments(youtube_id): |
| 201 | result_List.append(comment) | 203 | result_List.append(comment) |
| 202 | - print(result_List[i]) | ||
| 203 | count += 1 | 204 | count += 1 |
| 204 | i += 1 | 205 | i += 1 |
| 205 | if limit and count >= limit: | 206 | if limit and count >= limit: | ... | ... |
-
Please register or login to post a comment