-
Notifications
You must be signed in to change notification settings - Fork 0
Sourcery refactored main branch #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
| filename = os.path.join(TRANSCRIPT_FOLDER, video_id + ".json") | ||
|
|
||
| metadata = {} | ||
| metadata["speaker"] = "" | ||
| metadata["title"] = playlist_item["snippet"]["title"] | ||
| metadata["videoId"] = playlist_item["snippet"]["resourceId"]["videoId"] | ||
| metadata["description"] = playlist_item["snippet"]["description"] | ||
|
|
||
| filename = os.path.join(TRANSCRIPT_FOLDER, f"{video_id}.json") | ||
|
|
||
| metadata = { | ||
| "speaker": "", | ||
| "title": playlist_item["snippet"]["title"], | ||
| "videoId": playlist_item["snippet"]["resourceId"]["videoId"], | ||
| "description": playlist_item["snippet"]["description"], | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function gen_metadata refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation) - Merge dictionary assignment with declaration [×4] (
merge-dict-assign)
|
|
||
| video_id = playlist_item["snippet"]["resourceId"]["videoId"] | ||
| filename = os.path.join(TRANSCRIPT_FOLDER, video_id + ".json.vtt") | ||
| filename = os.path.join(TRANSCRIPT_FOLDER, f"{video_id}.json.vtt") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function get_transcript refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation)
| # Get the next page token from the response and create a new request object | ||
| next_page_token = response.get("nextPageToken") | ||
| if next_page_token: | ||
| if next_page_token := response.get("nextPageToken"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 149-167 refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Replace unused for index with underscore (
for-index-underscore)
This removes the following comments ( why? ):
# Get the next page token from the response and create a new request object
| word_count = len(words) | ||
| if word_count > 0: | ||
| append_text = " ".join(words[0 : int(word_count * PERCENTAGE_OVERLAP)]) | ||
| append_text = " ".join(words[:int(word_count * PERCENTAGE_OVERLAP)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function append_text_to_previous_segment refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index)
| if current_seconds < seg_finish_seconds and total_tokens < MAX_TOKENS: | ||
| # add the text to the transcript | ||
| text += current_text + " " | ||
| text += f"{current_text} " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function parse_json_vtt_transcript refactored with the following changes:
- Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation)
| if len(time_value) == 3: | ||
| h, m, s = time_value | ||
| return int(h) * 3600 + int(m) * 60 + int(s) | ||
| else: | ||
| if len(time_value) != 3: | ||
| return 0 | ||
| h, m, s = time_value | ||
| return int(h) * 3600 + int(m) * 60 + int(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function convert_time_to_seconds refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| """This function removes the text from each dictionary in the list.""" | ||
| return [ | ||
| {k: v for k, v in seg.items() if k != "text" and k != "description"} | ||
| {k: v for k, v in seg.items() if k not in ["text", "description"]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function remove_text refactored with the following changes:
- Replace multiple comparisons of same variable with
inoperator (merge-comparisons)
| # create multiple threads to process the queue | ||
| threads = [] | ||
| for i in range(PROCESSING_THREADS): | ||
| for _ in range(PROCESSING_THREADS): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 228-228 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| # create multiple threads to process the queue | ||
| threads = [] | ||
| for i in range(PROCESSOR_THREADS): | ||
| for _ in range(PROCESSOR_THREADS): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 179-179 refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore)
| if len(time_value) == 3: | ||
| h, m, s = time_value | ||
| return int(h) * 3600 + int(m) * 60 + int(s) | ||
| else: | ||
| if len(time_value) != 3: | ||
| return 0 | ||
| h, m, s = time_value | ||
| return int(h) * 3600 + int(m) * 60 + int(s) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function convert_time_to_seconds refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
Branch
mainrefactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
mainbranch, then run:Help us improve this pull request!