Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/contentcreatormanager/media/lbry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.__init__ refactored with the following changes:

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)
Expand All @@ -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()

Expand All @@ -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]
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.get_valid_name refactored with the following changes:

result = "".join(getVals)
self.logger.info(f"Returning stream name: {result}")
return result
Expand Down Expand Up @@ -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
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:

return result

def update_from_request(self, request):
Expand Down Expand Up @@ -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
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:

m="File hash and sd_hash do not match. Returning False"
self.logger.error(m)
return False
29 changes: 14 additions & 15 deletions src/contentcreatormanager/media/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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:

self.thumbnail = os.path.join(os.getcwd(), self.get_valid_thumbnail_file_name())

def compare_thumbs(self, other_obj):
Expand All @@ -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)
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:


def get_valid_thumbnail_file_name(self, desired_file_name : str = ''):
"""
Expand All @@ -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
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:

return "".join(getVals)

def is_downloaded(self):
Expand Down
10 changes: 5 additions & 5 deletions src/contentcreatormanager/media/post/facebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def upload(self):
Method to send this post to the facebook page tied to the
Facebook Platform Object tied to this object
"""
result = self.platform.api_post_feed(ID=self.platform.id,
message=self.body,
page_access_token=self.platform.page_access_token)

return result
return self.platform.api_post_feed(
ID=self.platform.id,
message=self.body,
page_access_token=self.platform.page_access_token,
)
49 changes: 24 additions & 25 deletions src/contentcreatormanager/media/video/lbry.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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:

return result

def make_thumb(self):
Expand Down Expand Up @@ -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
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:

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)))
Expand All @@ -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
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:

self.logger.info(m)
time.sleep(60)
if self.is_uploaded():
Expand Down
10 changes: 5 additions & 5 deletions src/contentcreatormanager/media/video/rumble.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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:

self.logger.info(f"Rumble Video Object initialized with ID {self.id}")

def upload(self):
Expand Down
32 changes: 16 additions & 16 deletions src/contentcreatormanager/media/video/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
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 Video.__init__ refactored with the following changes:

self.title = title
self.description = description

Expand All @@ -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
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 Video.get_valid_video_file_name refactored with the following changes:

return result

def combine_audio_and_video_files(self, video_file, audio_file):
Expand Down
Loading