Skip to content

Sourcery refactored main branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main
Open

Sourcery refactored main branch#1
sourcery-ai[bot] wants to merge 1 commit intomainfrom
sourcery/main

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Aug 23, 2023

Branch main refactored 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 main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from ironsniper1 August 23, 2023 22:12
Comment thread src/first_gui_test.py
Comment on lines -285 to +300
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()

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CCMApp.__lbry_init_plat refactored with the following changes:

Comment thread src/first_gui_test.py
Comment on lines -471 to -480
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CCMApp.__populate_yt_upload_lb_from_lbry refactored with the following changes:

Comment thread src/first_gui_test.py
Comment on lines -515 to -526
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CCMApp.__populate_lbry_upload_lb_from_yt refactored with the following changes:

Comment thread src/first_gui_test.py
Comment on lines -534 to +528
count = 0
count_2 = 0
for o in self.lbry_plat.media_objects:
for count, o in enumerate(self.lbry_plat.media_objects):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CCMApp.__populate_lbry_lb refactored with the following changes:

Comment thread src/first_gui_test.py
Comment on lines -549 to +545
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):
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CCMApp.__populate_yt_lb refactored with the following changes:

Comment on lines -83 to +92
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRYMedia.set_file_based_on_title refactored with the following changes:

Comment on lines -246 to +259

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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRYMedia.check_file_hash refactored with the following changes:

Comment on lines -22 to +34

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 = ''

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Media.__init__ refactored with the following changes:

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)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Media.make_thumb refactored with the following changes:

Comment on lines -65 to +73
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]

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Media.get_valid_thumbnail_file_name refactored with the following changes:

Comment on lines -38 to +43
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FacebookPost.upload refactored with the following changes:

Comment on lines -91 to +100
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRYVideo.set_file_based_on_title refactored with the following changes:

Comment on lines -156 to +187

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")

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRYVideo.download refactored with the following changes:

Comment on lines -201 to -219

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"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRYVideo.upload refactored with the following changes:

Comment on lines -37 to +50
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RumbleVideo.__init__ refactored with the following changes:

Comment on lines -59 to +78

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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Facebook.post refactored with the following changes:

Comment on lines -27 to +40
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()
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function claim_list refactored with the following changes:

Comment on lines -109 to +106
result = self.api_channel_list(claim_id=[self.id])

return result
return self.api_channel_list(claim_id=[self.id])
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.__get_channel refactored with the following changes:

Comment on lines -123 to +127

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']]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.__add_channel_videos refactored with the following changes:

Comment on lines -195 to +186

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.add_video_with_name refactored with the following changes:

Comment on lines -242 to +246
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.api_get refactored with the following changes:

Comment on lines -273 to +278
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.api_channel_list refactored with the following changes:

Comment on lines -415 to +429
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.api_file_delete refactored with the following changes:

Comment on lines -454 to +455
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.api_file_save refactored with the following changes:

Comment on lines -554 to +555
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)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function LBRY.api_stream_update refactored with the following changes:

Comment on lines -373 to +370
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]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YouTube.__get_video_data_from_csvs refactored with the following changes:

Comment on lines -416 to +409
tags = []
if not ('tags' not in request['snippet']):
tags = request['snippet']['tags']
tags = [] if 'tags' not in request['snippet'] else request['snippet']['tags']
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YouTube.add_video_with_request refactored with the following changes:

Comment on lines -556 to +547

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YouTube.api_videos_insert_req refactored with the following changes:

Comment on lines -632 to +627
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
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YouTube.api_videos_insert_exec refactored with the following changes:

Comment on lines -809 to +807
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

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YouTube.api_playlistitems_list refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants