| 13 | self._args = args |
| 14 | |
| 15 | def run(self) -> str: |
| 16 | parsed_args = self._parse_args() |
| 17 | |
| 18 | if parsed_args.exclude_manually_created and parsed_args.exclude_generated: |
| 19 | return "" |
| 20 | |
| 21 | proxy_config = None |
| 22 | if parsed_args.http_proxy != "" or parsed_args.https_proxy != "": |
| 23 | proxy_config = GenericProxyConfig( |
| 24 | http_url=parsed_args.http_proxy, |
| 25 | https_url=parsed_args.https_proxy, |
| 26 | ) |
| 27 | |
| 28 | if ( |
| 29 | parsed_args.webshare_proxy_username is not None |
| 30 | or parsed_args.webshare_proxy_password is not None |
| 31 | ): |
| 32 | proxy_config = WebshareProxyConfig( |
| 33 | proxy_username=parsed_args.webshare_proxy_username, |
| 34 | proxy_password=parsed_args.webshare_proxy_password, |
| 35 | ) |
| 36 | |
| 37 | transcripts = [] |
| 38 | exceptions = [] |
| 39 | |
| 40 | ytt_api = YouTubeTranscriptApi( |
| 41 | proxy_config=proxy_config, |
| 42 | ) |
| 43 | |
| 44 | for video_id in parsed_args.video_ids: |
| 45 | try: |
| 46 | transcript_list = ytt_api.list(video_id) |
| 47 | if parsed_args.list_transcripts: |
| 48 | transcripts.append(transcript_list) |
| 49 | else: |
| 50 | transcripts.append( |
| 51 | self._fetch_transcript( |
| 52 | parsed_args, |
| 53 | transcript_list, |
| 54 | ) |
| 55 | ) |
| 56 | except Exception as exception: |
| 57 | exceptions.append(exception) |
| 58 | |
| 59 | print_sections = [str(exception) for exception in exceptions] |
| 60 | if transcripts: |
| 61 | if parsed_args.list_transcripts: |
| 62 | print_sections.extend( |
| 63 | str(transcript_list) for transcript_list in transcripts |
| 64 | ) |
| 65 | else: |
| 66 | print_sections.append( |
| 67 | FormatterLoader() |
| 68 | .load(parsed_args.format) |
| 69 | .format_transcripts(transcripts) |
| 70 | ) |
| 71 | |
| 72 | return "\n\n".join(print_sections) |