-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ def __init__(self, lbry_channel, file_name : str = "", | |
| """ | ||
| super().__init__(platform=lbry_channel, ID=ID) | ||
| self.logger = self.settings.LBRY_logger | ||
|
|
||
| self.logger.info("Initializing Media Object as an LBRY Media Object") | ||
| vid_dir = os.path.join(os.getcwd(), 'videos') | ||
| self.file = os.path.join(vid_dir, file_name) | ||
|
|
@@ -35,12 +35,12 @@ def __init__(self, lbry_channel, file_name : str = "", | |
| self.tags = tags | ||
| self.bid = bid | ||
| self.title = title | ||
| if name == '': | ||
| name = self.title | ||
| if not name: | ||
| name = self.title | ||
| self.name = self.get_valid_name(name) | ||
| self.license = lic | ||
| self.license_url = license_url | ||
|
|
||
| if not new_media: | ||
| self.update_local() | ||
|
|
||
|
|
@@ -50,7 +50,7 @@ def get_valid_name(self, name : str): | |
| """ | ||
| v='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890-' | ||
| valid_chars = v | ||
| getVals = list([val for val in name if val in valid_chars]) | ||
| getVals = [val for val in name if val in valid_chars] | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| result = "".join(getVals) | ||
| self.logger.info(f"Returning stream name: {result}") | ||
| return result | ||
|
|
@@ -80,16 +80,16 @@ def set_file_based_on_title(self): | |
| v='`~!@#$%^&+=,-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | ||
| valid_chars = v | ||
| file_name = self.title | ||
| 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) | ||
|
|
||
|
Comment on lines
-83
to
+92
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return result | ||
|
|
||
| def update_from_request(self, request): | ||
|
|
@@ -243,20 +243,20 @@ def check_file_hash(self): | |
| it to what is on LBRY blockchain. Returns True if it matches. | ||
| """ | ||
| BUF_SIZE = 65536 #lets read stuff in 64kb chunks (arbitrary)! | ||
|
|
||
| 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 | ||
|
|
||
|
Comment on lines
-246
to
+259
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| m="File hash and sd_hash do not match. Returning False" | ||
| self.logger.error(m) | ||
| return False | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,19 +19,19 @@ def __init__(self, platform, ID : str): | |
| self.settings = platform.settings | ||
| self.logger = self.settings.Media_logger | ||
| self.platform = platform | ||
|
|
||
| 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 = '' | ||
|
|
||
|
Comment on lines
-22
to
+34
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.thumbnail = os.path.join(os.getcwd(), self.get_valid_thumbnail_file_name()) | ||
|
|
||
| def compare_thumbs(self, other_obj): | ||
|
|
@@ -52,8 +52,7 @@ def make_thumb(self): | |
| step_three = step_two.output(self.get_valid_thumbnail_file_name(), | ||
| vframes=1) | ||
| 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) | ||
|
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| def get_valid_thumbnail_file_name(self, desired_file_name : str = ''): | ||
| """ | ||
|
|
@@ -62,16 +61,16 @@ def get_valid_thumbnail_file_name(self, desired_file_name : str = ''): | |
| """ | ||
| v='`~!@#$%^&+=,-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | ||
| valid_chars = v | ||
| 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] | ||
|
|
||
|
Comment on lines
-65
to
+73
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return "".join(getVals) | ||
|
|
||
| def is_downloaded(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,16 +88,16 @@ def __upload_new_video(self): | |
| def set_file_based_on_title(self): | ||
| valid = '`~!@#$%^&+=,-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | ||
| file_name = self.title | ||
| 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) | ||
|
|
||
|
Comment on lines
-91
to
+100
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return result | ||
|
|
||
| def make_thumb(self): | ||
|
|
@@ -153,39 +153,38 @@ def download(self): | |
| if not self.is_uploaded(): | ||
| self.logger.error("Video not on LBRY can not download it") | ||
| return | ||
|
|
||
| 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") | ||
|
|
||
|
Comment on lines
-156
to
+187
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| shutil.copy(actual_file_path, desired_file_path) | ||
| os.remove(actual_file_path) | ||
| os.remove(os.path.join(os.getcwd(), os.path.basename(desired_file_path))) | ||
|
|
@@ -198,25 +197,25 @@ def upload(self): | |
| m="You already uploaded this Video to LBRY. Exitting method" | ||
| self.logger.error(m) | ||
| return | ||
|
|
||
| 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" | ||
|
Comment on lines
-201
to
-219
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.logger.info(m) | ||
| time.sleep(60) | ||
| if self.is_uploaded(): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -34,20 +34,20 @@ def __init__(self, rumble_channel, guid : str = '', title : str = '', | |
| thumbnail_file_name=thumbnail_file_name) | ||
| self.logger = self.settings.Rumble_logger | ||
| self.logger.info("Initializing Video Object as Rumble Video Object") | ||
| 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 | ||
|
|
||
|
Comment on lines
-37
to
+50
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.logger.info(f"Rumble Video Object initialized with ID {self.id}") | ||
|
|
||
| def upload(self): | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,30 +21,30 @@ def __init__(self, platform, ID : str = '', file_name : str = '', | |
| description, and thumbnail_file_name string. The Strings | ||
| are all optional but ID or file_name must be provided | ||
| """ | ||
| if ID == '' and file_name == '': | ||
| if not ID and not file_name: | ||
| m="You must set either the file_name or ID to create a Video" | ||
| platform.settings.Video_logger.error(m) | ||
| raise Exception() | ||
|
|
||
| super().__init__(platform=platform, ID=ID) | ||
|
|
||
| self.logger = self.settings.Video_logger | ||
| self.logger.info("Initializing Media Object as a Video object") | ||
|
|
||
| vid_dir = os.path.join(os.getcwd(), 'videos') | ||
| if file_name == '': | ||
| if not file_name: | ||
| self.file = os.path.join(vid_dir, self.get_valid_video_file_name()) | ||
| else: | ||
| self.file = os.path.join(vid_dir, file_name) | ||
| self.thumbnail = os.path.join(os.getcwd(), | ||
| self.get_valid_thumbnail_file_name(thumbnail_file_name)) | ||
|
|
||
| file_does_not_exist = not os.path.isfile(self.file) | ||
| if file_does_not_exist and ID == '': | ||
|
|
||
| if file_does_not_exist and not ID: | ||
| m=f"no file found for file_name {file_name} and no ID set" | ||
| self.logger.error(m) | ||
|
|
||
|
Comment on lines
-24
to
+47
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| self.title = title | ||
| self.description = description | ||
|
|
||
|
|
@@ -68,18 +68,18 @@ def get_valid_video_file_name(self, desired_file_name : str = ''): | |
| v='`~!@#$%^&+=,-_.() abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' | ||
| valid_chars = v | ||
| file_name = desired_file_name | ||
| if desired_file_name[-4:] == '.mp4': | ||
| if desired_file_name.endswith('.mp4'): | ||
| self.logger.info("file name given already has .mp4 in it") | ||
| file_name = desired_file_name[:-4] | ||
| if desired_file_name == '': | ||
| if not desired_file_name: | ||
| file_name = self.title | ||
| getVals = list([val for val in f"{file_name}.mp4" if val in valid_chars]) | ||
|
|
||
| getVals = [val for val in f"{file_name}.mp4" if val in valid_chars] | ||
|
|
||
| result = "".join(getVals) | ||
|
|
||
| self.logger.info(f"returning the following file name: {result}") | ||
|
|
||
|
Comment on lines
-71
to
+82
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
| return result | ||
|
|
||
| def combine_audio_and_video_files(self, video_file, audio_file): | ||
|
|
||
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
LBRYMedia.__init__refactored with the following changes:simplify-empty-collection-comparison)