Conversation
| count = 1 | ||
| choices = {} | ||
| options = [] | ||
| for channel in channels['result']['items']: | ||
| for count, channel in enumerate(channels['result']['items'], start=1): | ||
| options.append(f"{count}. {channel['name']}") | ||
| choices[f'{count}'] = channel | ||
| count += 1 | ||
|
|
||
| self.lbry_channel_chooser = SimpleChoiceBox(title="LBRY Channel", text="Pick Your LBRY Channel", choices=options) | ||
| self.lbry_channel_chooser.c.wait_variable(self.lbry_channel_chooser.selection) | ||
|
|
||
| choice = self.lbry_channel_chooser.selection.get()[0] | ||
|
|
||
| self.lbry_plat = lbry_plat.LBRY(settings=self.settings, ID=choices[choice]['claim_id'], init_videos=True) | ||
|
|
||
| self.settings.Base_logger.info("Attempting to populate the LBRY ListBoxes") | ||
| self.__populate_lbry_lb() | ||
| self.deiconify() | ||
|
|
There was a problem hiding this comment.
Function CCMApp.__lbry_init_plat refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| self.settings.Base_logger.info(f"Thumbnail already present no need to download") | ||
| self.settings.Base_logger.info("Thumbnail already present no need to download") | ||
| yvid.thumbnail = obj.thumbnail | ||
| self.settings.Base_logger.info(f"Adding {yvid.title} to list of vids not on YouTube that are on LBRY") | ||
| list3.append(yvid) | ||
| count = 0 | ||
| self.settings.Base_logger.info("Populating the YouTube upload ListBox") | ||
| for o in list3: | ||
| for count, o in enumerate(list3): | ||
| self.settings.Base_logger.info(f"Adding {o.title} to the upload listbox for YouTube") | ||
| self.yt_upload_lb.insert(count, o.title) | ||
| count += 1 |
There was a problem hiding this comment.
Function CCMApp.__populate_yt_upload_lb_from_lbry refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| self.settings.Base_logger.info(f"Thumbnail already present no need to download") | ||
| self.settings.Base_logger.info("Thumbnail already present no need to download") | ||
| lvid.thumbnail = obj.thumbnail | ||
| self.settings.Base_logger.info(f"Setting bid for new LBRY Vid to {self.default_bid}") | ||
| lvid.bid = self.default_bid | ||
| self.settings.Base_logger.info(f"Adding {lvid.title} to list of vids not on LBRY that are on YouTube") | ||
| list3.append(lvid) | ||
| count = 0 | ||
| self.settings.Base_logger.info("Populating the LBRY upload ListBox") | ||
| for o in list3: | ||
| for count, o in enumerate(list3): | ||
| self.settings.Base_logger.info(f"Adding {o.title} to the upload listbox for LBRY") | ||
| self.lbry_upload_lb.insert(count, o.title) | ||
| count += 1 |
There was a problem hiding this comment.
Function CCMApp.__populate_lbry_upload_lb_from_yt refactored with the following changes:
- Replace f-string with no interpolated values with string (
remove-redundant-fstring) - Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| count = 0 | ||
| count_2 = 0 | ||
| for o in self.lbry_plat.media_objects: | ||
| for count, o in enumerate(self.lbry_plat.media_objects): |
There was a problem hiding this comment.
Function CCMApp.__populate_lbry_lb refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| def __populate_yt_lb(self): | ||
| def __populate_yt_lb(self): | ||
| """ | ||
| Private Method to populate the YouTube List Boxes | ||
| """ | ||
| count = 0 | ||
| count_2 = 0 | ||
| for o in self.yt_plat.media_objects: | ||
| for count, o in enumerate(self.yt_plat.media_objects): |
There was a problem hiding this comment.
Function CCMApp.__populate_yt_lb refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block) - Replace manual loop counter with call to enumerate (
convert-to-enumerate)
| getVals = list([val for val in f"{file_name}" if val in valid_chars]) | ||
|
|
||
| getVals = [val for val in f"{file_name}" if val in valid_chars] | ||
|
|
||
| result = "".join(getVals) | ||
|
|
||
| m=f"returning and setting the following file name: {result}" | ||
| self.logger.info(m) | ||
|
|
||
| self.file = os.path.join(os.getcwd(), result) | ||
|
|
There was a problem hiding this comment.
Function LBRYMedia.set_file_based_on_title refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension) - Replace unneeded comprehension with generator (
comprehension-to-generator)
|
|
||
| sha384 = hashlib.sha384()#this is the hash type lbry uses for file hash | ||
|
|
||
| with open(self.file, 'rb') as f: | ||
| while True: | ||
| data = f.read(BUF_SIZE) | ||
| if not data: | ||
| if data := f.read(BUF_SIZE): | ||
| sha384.update(data) | ||
|
|
||
| else: | ||
| break | ||
| sha384.update(data) | ||
|
|
||
| if sha384.hexdigest() == self.file_hash: | ||
| self.logger.info("Hash matches file. Returning True") | ||
| return True | ||
|
|
There was a problem hiding this comment.
Function LBRYMedia.check_file_hash refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression) - Lift code into else after jump in control flow (
reintroduce-else) - Swap if/else branches (
swap-if-else-branches)
|
|
||
| self.logger.info(f"Initializing Media Object with id {ID}") | ||
| self.id = ID | ||
| self.uploaded = False | ||
| self.file = None | ||
| if self.id == '' or self.id is None: | ||
|
|
||
| if not self.id or self.id is None: | ||
| self.set_unique_id() | ||
|
|
||
| self.title = '' | ||
| self.tags = [] | ||
| self.description = '' | ||
|
|
There was a problem hiding this comment.
Function Media.__init__ refactored with the following changes:
- Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison)
| step_four = step_three.overwrite_output() | ||
| result = step_four.run(capture_stdout=False,capture_stderr=False) | ||
| return result | ||
| return step_four.run(capture_stdout=False,capture_stderr=False) |
There was a problem hiding this comment.
Function Media.make_thumb refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if desired_file_name == '': | ||
| getVals = list([val for val in f"{self.title}.jpg" if val in valid_chars]) | ||
|
|
||
| if not desired_file_name: | ||
| getVals = [val for val in f"{self.title}.jpg" if val in valid_chars] | ||
| else: | ||
| if desired_file_name[-4:] == '.jpg': | ||
| file_name = desired_file_name[:-4] | ||
| if desired_file_name.endswith('.jpg'): | ||
| file_name = desired_file_name[:-4] | ||
| else: | ||
| file_name = desired_file_name | ||
| getVals = list([val for val in f"{file_name}.jpg" if val in valid_chars]) | ||
| file_name = desired_file_name | ||
| getVals = [val for val in f"{file_name}.jpg" if val in valid_chars] | ||
|
|
There was a problem hiding this comment.
Function Media.get_valid_thumbnail_file_name refactored with the following changes:
- Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison) - Replace list(), dict() or set() with comprehension [×2] (
collection-builtin-to-comprehension) - Replace unneeded comprehension with generator [×2] (
comprehension-to-generator) - Replace str prefix/suffix check with call to
startswith/endswith(str-prefix-suffix)
| result = self.platform.api_post_feed(ID=self.platform.id, | ||
| message=self.body, | ||
| page_access_token=self.platform.page_access_token) | ||
|
|
||
| return result No newline at end of file | ||
| return self.platform.api_post_feed( | ||
| ID=self.platform.id, | ||
| message=self.body, | ||
| page_access_token=self.platform.page_access_token, | ||
| ) No newline at end of file |
There was a problem hiding this comment.
Function FacebookPost.upload refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| getVals = list([val for val in f"{file_name}.mp4" if val in valid]) | ||
|
|
||
| getVals = [val for val in f"{file_name}.mp4" if val in valid] | ||
|
|
||
| result = "".join(getVals) | ||
|
|
||
| self.logger.info(f"returning and setting the following file name: {result}") | ||
|
|
||
| vid_dir = os.path.join(os.getcwd(), 'videos') | ||
| self.file = os.path.join(vid_dir, result) | ||
|
|
There was a problem hiding this comment.
Function LBRYVideo.set_file_based_on_title refactored with the following changes:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension) - Replace unneeded comprehension with generator (
comprehension-to-generator)
|
|
||
| get_result = self.platform.api_get(uri=self.permanent_url, | ||
| download_directory=self.settings.folder_location, | ||
| file_name=os.path.basename(self.file)) | ||
|
|
||
| try: | ||
| streaming_url = get_result['result']['streaming_url'] | ||
| except KeyError as e: | ||
| if e.args[0] == 'streaming_url': | ||
| m="The Video You are trying to download not found on LBRY" | ||
| self.logger.error(m) | ||
| return 'get_error' | ||
| else: | ||
| if e.args[0] != 'streaming_url': | ||
| raise e | ||
| m="The Video You are trying to download not found on LBRY" | ||
| self.logger.error(m) | ||
| return 'get_error' | ||
| m=f"running a request {streaming_url} to wait for blobs to finish downloading" | ||
| self.logger.info(m) | ||
| requests.get(streaming_url) | ||
|
|
||
| if os.path.isfile(self.file): | ||
| os.remove(self.file) | ||
|
|
||
| file_save_result = self.platform.api_file_save(claim_id=self.id, | ||
| download_directory=self.settings.folder_location, | ||
| file_name=os.path.basename(self.file)) | ||
|
|
||
| actual_file_path = file_save_result['result']['download_path'] | ||
| desired_file_path = self.file | ||
|
|
||
| if actual_file_path == desired_file_path: | ||
| return get_result | ||
|
|
||
| self.logger.info(f"we want {desired_file_path} we got {actual_file_path} copying to desired location and deleting original") | ||
|
|
There was a problem hiding this comment.
Function LBRYVideo.download refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
|
|
||
| file_name = os.path.basename(self.file) | ||
|
|
||
| if not os.path.isfile(self.file): | ||
| self.logger.error(f"Can not find file: {file_name}") | ||
|
|
||
| self.logger.info("attempting to upload thumbnail") | ||
| self.upload_thumbnail(update_video=False, use_existing_thumb_if_present=True) | ||
|
|
||
| self.logger.info(f"Attempting to upload {file_name}") | ||
| result = self.__upload_new_video() | ||
|
|
||
| if result is None or 'error' in result: | ||
| m="No Upload made not updating any properties of LBRY Video Object" | ||
| self.logger.error(f'{m}\n{result}') | ||
| else: | ||
| finished = False | ||
| m="Sleeping for 1 min before checking for completion of upload" | ||
| while not finished: | ||
| m="Sleeping for 1 min before checking for completion of upload" |
There was a problem hiding this comment.
Function LBRYVideo.upload refactored with the following changes:
- Hoist statements out of for/while loops (
hoist-statement-from-loop)
| if guid == '': | ||
|
|
||
| if not guid: | ||
| self.set_unique_id() | ||
| else: | ||
| self.set_unique_id(guid) | ||
|
|
||
| # The method sets id to a unique random so setting guid with it | ||
| # (rumble id will be set on upload) | ||
| self.guid = self.id | ||
| self.url = '' | ||
|
|
||
| self.license_type = license_type | ||
| self.uploaded = uploaded | ||
|
|
There was a problem hiding this comment.
Function RumbleVideo.__init__ refactored with the following changes:
- Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison)
|
|
||
| try: | ||
| result = post.upload() | ||
| except facebook.GraphAPIError as e: | ||
| if e.message == 'Duplicate status message': | ||
| m="Posting Failed. You are trying to make a duplicate post" | ||
| self.logger.error(m) | ||
| post.uploaded = False | ||
| return post | ||
| else: | ||
| if e.message != 'Duplicate status message': | ||
| raise e | ||
|
|
||
|
|
||
| m="Posting Failed. You are trying to make a duplicate post" | ||
| self.logger.error(m) | ||
| post.uploaded = False | ||
| return post | ||
| #this should be changed to use a is_uploaded | ||
| # method from the facebook post class | ||
| m=f"Setting FB Post ID to {result['id']}, setting posted flag to true" | ||
| self.logger.info(m) | ||
| post.id = result['id'] | ||
| post.uploaded = True | ||
|
|
||
| self.add_media(post) | ||
|
|
There was a problem hiding this comment.
Function Facebook.post refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if not (account_id == '' or account_id is None): | ||
|
|
||
| if account_id and account_id is not None: | ||
| parameters['account_id']=account_id | ||
| if not (page == 0 or page is None): | ||
|
|
||
| if page != 0 and page is not None: | ||
| parameters['page']=page | ||
| if not (order_by == '' or order_by is None): | ||
|
|
||
| if order_by and order_by is not None: | ||
| parameters['order_by']=order_by | ||
|
|
||
|
|
||
| result = requests.post(LBRY.API_URL, | ||
| json={"method": "claim_list", | ||
| "params": parameters}).json() | ||
|
|
||
|
|
||
| return result | ||
|
|
||
|
|
||
| return requests.post( | ||
| LBRY.API_URL, json={"method": "claim_list", "params": parameters} | ||
| ).json() |
There was a problem hiding this comment.
Function claim_list refactored with the following changes:
- Replaces an empty collection equality with a boolean operation [×2] (
simplify-empty-collection-comparison) - Inline variable that is immediately returned (
inline-immediately-returned-variable) - Simplify logical expression using De Morgan identities [×3] (
de-morgan)
| result = self.api_channel_list(claim_id=[self.id]) | ||
|
|
||
| return result | ||
| return self.api_channel_list(claim_id=[self.id]) |
There was a problem hiding this comment.
Function LBRY.__get_channel refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
||
| page_amount = intial_result['result']['total_pages'] | ||
| item_amount = intial_result['result']['total_items'] | ||
|
|
||
| self.logger.info(f"Found {item_amount} claims on channel") | ||
|
|
||
| pages = [] | ||
|
|
||
| claims = [] | ||
|
|
||
| self.logger.info("adding initial request as 1st page of data") | ||
| pages.append(intial_result['result']['items']) | ||
|
|
||
| pages = [intial_result['result']['items']] |
There was a problem hiding this comment.
Function LBRY.__add_channel_videos refactored with the following changes:
- Move assignment closer to its usage within a block [×2] (
move-assign-in-block) - Merge append into list declaration (
merge-list-append) - Replace manual loop counter with call to enumerate (
convert-to-enumerate) - Remove unnecessary calls to
enumeratewhen the index is not used (remove-unused-enumerate)
|
|
There was a problem hiding this comment.
Function LBRY.add_video_with_name refactored with the following changes:
- Replaces an empty collection equality with a boolean operation [×2] (
simplify-empty-collection-comparison)
| if not (file_name == '' or file_name is None): | ||
|
|
||
| if file_name and file_name is not None: | ||
| parameters['file_name'] = file_name | ||
| if not (download_directory == '' or download_directory is None): | ||
|
|
||
| if download_directory and download_directory is not None: | ||
| parameters['download_directory'] = download_directory | ||
|
|
||
| result = requests.post(LBRY.API_URL, | ||
| json={"method": "get", | ||
| "params": parameters}).json() | ||
|
|
||
| m=f"get call with parameters {parameters} made to the LBRY API" | ||
| self.logger.info(m) | ||
|
|
There was a problem hiding this comment.
Function LBRY.api_get refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan) - Replaces an empty collection equality with a boolean operation [×2] (
simplify-empty-collection-comparison)
| if not (page == 0 or page is None): | ||
|
|
||
| if page != 0 and page is not None: | ||
| parameters['page'] = page | ||
| if not (name == '' or name is None): | ||
|
|
||
| if name and name is not None: | ||
| parameters['name'] = name | ||
|
|
||
|
|
||
| result = requests.post(LBRY.API_URL, | ||
| json={"method": "channel_list", | ||
| "params": parameters}).json() | ||
|
|
||
| m=f"channel_list call with params: {parameters} made to the LBRY API" | ||
| self.logger.info(m) | ||
|
|
There was a problem hiding this comment.
Function LBRY.api_channel_list refactored with the following changes:
- Simplify logical expression using De Morgan identities [×2] (
de-morgan) - Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison)
| if not(sd_hash == '' or sd_hash is None): | ||
|
|
||
| if sd_hash and sd_hash is not None: | ||
| parameters['sd_hash'] = sd_hash | ||
| if not(file_name == '' or file_name is None): | ||
|
|
||
| if file_name and file_name is not None: | ||
| parameters['file_name'] = file_name | ||
| if not(claim_id == '' or claim_id is None): | ||
|
|
||
| if claim_id and claim_id is not None: | ||
| parameters['claim_id'] = claim_id | ||
| if not(claim_name == '' or claim_name is None): | ||
|
|
||
| if claim_name and claim_name is not None: | ||
| parameters['claim_name'] = claim_name | ||
| if not(len(parameters) > 2): | ||
|
|
||
| if len(parameters) <= 2: | ||
| self.logger.error("Must provide something to delete") | ||
| return | ||
|
|
||
| result = requests.post(LBRY.API_URL, | ||
| json={"method": "file_delete", | ||
| "params": parameters}).json() | ||
|
|
||
| m=f"file_delete call with parameters {parameters} made to the LBRY API" | ||
| self.logger.info(m) | ||
|
|
There was a problem hiding this comment.
Function LBRY.api_file_delete refactored with the following changes:
- Simplify logical expression using De Morgan identities [×5] (
de-morgan) - Replaces an empty collection equality with a boolean operation [×4] (
simplify-empty-collection-comparison)
| if not(file_name == '' or file_name is None): | ||
|
|
||
| if file_name and file_name is not None: | ||
| parameters['file_name'] = file_name | ||
|
|
||
| result = requests.post(LBRY.API_URL, | ||
| json={"method": "file_save", | ||
| "params": parameters}).json() | ||
|
|
||
| m=f"file_save call with params: {parameters} made to the LBRY API" | ||
| self.logger.info(m) | ||
|
|
There was a problem hiding this comment.
Function LBRY.api_file_save refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison)
| if not (file_path == '' or file_path is None): | ||
|
|
||
| if file_path and file_path is not None: | ||
| parameters['file_path'] = file_path | ||
|
|
||
| result = requests.post(LBRY.API_URL, | ||
| json={"method": "stream_update", | ||
| "params": parameters}).json() | ||
|
|
||
| m=f"stream_update call with params: {parameters} made to the LBRY API" | ||
| self.logger.info(m) | ||
|
|
There was a problem hiding this comment.
Function LBRY.api_stream_update refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan) - Replaces an empty collection equality with a boolean operation (
simplify-empty-collection-comparison)
| pages = [] | ||
|
|
||
| for csv in csvs: | ||
| pages.append(self.__get_video_data_from_csv(csv)) | ||
| return pages | ||
| return [self.__get_video_data_from_csv(csv) for csv in csvs] |
There was a problem hiding this comment.
Function YouTube.__get_video_data_from_csvs refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| tags = [] | ||
| if not ('tags' not in request['snippet']): | ||
| tags = request['snippet']['tags'] | ||
| tags = [] if 'tags' not in request['snippet'] else request['snippet']['tags'] |
There was a problem hiding this comment.
Function YouTube.add_video_with_request refactored with the following changes:
- Move setting of default value for variable into
elsebranch (introduce-default-else) - Swap if/else branches (
swap-if-else-branches) - Replace if statement with if expression (
assign-if-exp)
|
|
There was a problem hiding this comment.
Function YouTube.api_videos_insert_req refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if e.resp.status in YouTube.RETRIABLE_STATUS_CODES: | ||
| e=f"Retriable HTTP error {e.resp.status} occurred:\n{e.content}" | ||
| error=e | ||
| else: | ||
| if e.resp.status not in YouTube.RETRIABLE_STATUS_CODES: | ||
| raise e | ||
| e=f"Retriable HTTP error {e.resp.status} occurred:\n{e.content}" | ||
| error=e |
There was a problem hiding this comment.
Function YouTube.api_videos_insert_exec refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches) - Remove unnecessary else after guard condition (
remove-unnecessary-else)
| if (playlistId == '' and ids == '') or (playlistId != '' and ids != ''): | ||
| if not playlistId and not ids or (playlistId != '' and ids != ''): | ||
| self.logger.error("ids (comma-separated list of one or more unique playlist item IDs.) or playlistId (unique ID of the playlist for which you want to retrieve playlist items) must be set but both can not be") | ||
| return | ||
|
|
||
| m="YouTube API Call to playlistitems.list cost of 1 quota unit" | ||
| self.logger.info(m) | ||
| quota_cost = 1 | ||
|
|
There was a problem hiding this comment.
Function YouTube.api_playlistitems_list refactored with the following changes:
- Replaces an empty collection equality with a boolean operation [×3] (
simplify-empty-collection-comparison) - Swap if/else branches (
swap-if-else-branches) - Merge else clause's nested if statement into elif (
merge-else-if-into-elif) - Remove redundant conditional (
remove-redundant-if) - Replace f-string with no interpolated values with string (
remove-redundant-fstring)
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!