diff --git a/src/contentcreatormanager/media/lbry.py b/src/contentcreatormanager/media/lbry.py index c11bb79..39bdf15 100644 --- a/src/contentcreatormanager/media/lbry.py +++ b/src/contentcreatormanager/media/lbry.py @@ -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] 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) - + 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 - + m="File hash and sd_hash do not match. Returning False" self.logger.error(m) return False \ No newline at end of file diff --git a/src/contentcreatormanager/media/media.py b/src/contentcreatormanager/media/media.py index 52790a0..e6e75c5 100644 --- a/src/contentcreatormanager/media/media.py +++ b/src/contentcreatormanager/media/media.py @@ -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 = '' - + 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) 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] + return "".join(getVals) def is_downloaded(self): diff --git a/src/contentcreatormanager/media/post/facebook.py b/src/contentcreatormanager/media/post/facebook.py index d096751..e1fb9cf 100644 --- a/src/contentcreatormanager/media/post/facebook.py +++ b/src/contentcreatormanager/media/post/facebook.py @@ -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 \ 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 diff --git a/src/contentcreatormanager/media/video/lbry.py b/src/contentcreatormanager/media/video/lbry.py index 97d4e2e..a4d46f2 100644 --- a/src/contentcreatormanager/media/video/lbry.py +++ b/src/contentcreatormanager/media/video/lbry.py @@ -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) - + 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") - + 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" self.logger.info(m) time.sleep(60) if self.is_uploaded(): diff --git a/src/contentcreatormanager/media/video/rumble.py b/src/contentcreatormanager/media/video/rumble.py index 2f2ee23..b7c084a 100644 --- a/src/contentcreatormanager/media/video/rumble.py +++ b/src/contentcreatormanager/media/video/rumble.py @@ -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 - + self.logger.info(f"Rumble Video Object initialized with ID {self.id}") def upload(self): diff --git a/src/contentcreatormanager/media/video/video.py b/src/contentcreatormanager/media/video/video.py index 97fa407..ccf55b1 100644 --- a/src/contentcreatormanager/media/video/video.py +++ b/src/contentcreatormanager/media/video/video.py @@ -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) - + 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}") - + return result def combine_audio_and_video_files(self, video_file, audio_file): diff --git a/src/contentcreatormanager/media/video/youtube.py b/src/contentcreatormanager/media/video/youtube.py index 5a5e0db..57677bb 100644 --- a/src/contentcreatormanager/media/video/youtube.py +++ b/src/contentcreatormanager/media/video/youtube.py @@ -45,11 +45,11 @@ def __init__(self, channel, ID : str = None, favorite_count : str ='0', super().__init__(platform=channel, ID=ID,file_name=file_name) self.logger = self.settings.YouTube_logger - + self.logger.info("Initializing Video Object as a YouTube Video Object") - + self.channel = channel - + self.published_at = published_at self.channel_id = channel_id self.title = title @@ -76,13 +76,13 @@ def __init__(self, channel, ID : str = None, favorite_count : str ='0', self.dislike_count = dislike_count self.comment_count = comment_count self.favorite_count = favorite_count - - if file_name == '': + + if not file_name: file_name = self.title vid_dir = os.path.join(os.getcwd(), 'videos') self.file = os.path.join(vid_dir, self.get_valid_video_file_name(desired_file_name=file_name)) - + if new_video: m="new_video not attempting to initialize pytube_obj variable" self.logger.info(m) @@ -96,8 +96,8 @@ def __init__(self, channel, ID : str = None, favorite_count : str ='0', self.logger.info(m) self.update_local() self.logger.info("update ran") - - + + self.logger.info("YouTube Video Object initialized") def __initialize_upload(self): @@ -230,8 +230,7 @@ def __url(self): """ Private Method to get YouTube URL """ - url = f"{YouTubeVideo.BASE_URL}{self.id}" - return url + return f"{YouTubeVideo.BASE_URL}{self.id}" def __get_pytube(self, use_oauth=True): """ @@ -293,9 +292,8 @@ def is_downloaded(self, file_check_only : bool = False): if self.is_uploaded(): self.update_local() else: - self.update_local() - result = media_vid.Video.is_downloaded(self) - return result + self.update_local() + return media_vid.Video.is_downloaded(self) def delete_web(self, do_not_download_before_delete : bool = False): """ @@ -306,7 +304,7 @@ def delete_web(self, do_not_download_before_delete : bool = False): """ m=f"Preparing to delete video with ID {self.id} from YouTube" self.logger.info(m) - + if not self.is_downloaded() and not do_not_download_before_delete: m="File for video not found. Downloading before removal" self.logger.warning(m) @@ -314,26 +312,26 @@ def delete_web(self, do_not_download_before_delete : bool = False): if result == 'content-length-error': self.logger.error("Download failed with pytube issue not removing") return 'content-length-error' - + self.logger.info("Making videos.delete api call") request = self.channel.service.videos().delete( id=self.id ) result = request.execute() - + tries_left = YouTubeVideo.MAX_RETRIES while self.is_uploaded() and tries_left > 0: - m=f"Video found on YouTube. Sleeping a minute and checking again." + m = "Video found on YouTube. Sleeping a minute and checking again." self.logger.warning(m) time.sleep(60) tries_left -= 1 - + if self.uploaded: m=f"Video still found on YouTube. Results of the call:\n{result}" self.logger.error(m) else: self.logger.info("Delete successful") - + return result def update_web(self, force_update : bool = False): @@ -351,37 +349,34 @@ def update_web(self, force_update : bool = False): m="Video not uploaded. Can not update its web details" self.logger.error(m) return - - update_snippet = {} - update_snippet['categoryId']=self.category_id - update_snippet['defaultLanguage']=self.default_language - update_snippet['description']=self.description - update_snippet['tags']=self.tags - update_snippet['title']=self.title - update_status = {} - update_status['embeddable']=self.embeddable - update_status['license']=self.license - update_status['privacyStatus']=self.privacy_status - update_status['publicStatsViewable']=self.public_stats_viewable - update_status['selfDeclaredMadeForKids']=self.self_declared_made_for_kids - + + update_snippet = { + 'categoryId': self.category_id, + 'defaultLanguage': self.default_language, + 'description': self.description, + 'tags': self.tags, + 'title': self.title, + } + update_status = { + 'embeddable': self.embeddable, + 'license': self.license, + 'privacyStatus': self.privacy_status, + 'publicStatsViewable': self.public_stats_viewable, + 'selfDeclaredMadeForKids': self.self_declared_made_for_kids, + } if not force_update: current_web_status = self.platform.api_videos_list(ids=self.id, snippet=True, contentDetails=True, statistics=True, status=True) - + current_web_snippet = current_web_status['snippet'] current_web_status = current_web_status['status'] - - need_to_update=False - + cond1 = update_snippet == current_web_snippet cond2 = update_status == current_web_status - if not (cond1 and cond2): - need_to_update = True - + need_to_update = not cond1 or not cond2 if not need_to_update: self.logger.info("No need to update returning None") return None @@ -408,22 +403,19 @@ def update_local(self, update_file_name : bool = True): m="Can not update local details from YouTube" self.logger.error(m) return - + self.logger.info(f"Updating Video with id {self.id} from the web") - + video = self.platform.api_videos_list(ids=self.id, snippet=True, contentDetails=True, statistics=True, status=True)['items'][0] - + if video is None: - self.logger.error(f"Trying to update local but can not find video") + self.logger.error("Trying to update local but can not find video") return None - - if 'tags' not in video['snippet']: - tags = [] - else: - tags = video['snippet']['tags'] + + tags = [] if 'tags' not in video['snippet'] else video['snippet']['tags'] if 'description' not in video['snippet']: description = "" else: @@ -438,7 +430,7 @@ def update_local(self, update_file_name : bool = True): else: d=video['snippet']['defaultAudioLanguage'] default_audio_language = d - + self.published_at = video['snippet']['publishedAt'] self.channel_id = video['snippet']['channelId'] self.title = video['snippet']['title'] @@ -465,12 +457,12 @@ def update_local(self, update_file_name : bool = True): self.comment_count = video['statistics']['commentCount'] self.favorite_count = video['statistics']['favoriteCount'] - + if update_file_name: f=self.get_valid_video_file_name(desired_file_name=self.title) file_name = f self.file = os.path.join(os.getcwd(), file_name) - + self.logger.info("Update from web complete") return video @@ -528,9 +520,7 @@ def download(self, overwrite=False): if not self.is_uploaded(): self.logger.error("Video not uploaded. Can not download it") return - result = self.__pytube_download(overwrite=overwrite) - - return result + return self.__pytube_download(overwrite=overwrite) def is_uploaded(self): """ @@ -545,12 +535,12 @@ def is_uploaded(self): response = requests.get(url) if response.status_code == 200: - if not "Video unavailable" in response.text: + if "Video unavailable" not in response.text: self.uploaded = True return True - + result = self.platform.api_videos_list(contentDetails=True,ids=self.id) - + if result['pageInfo']['totalResults'] == 0: self.uploaded = False return False diff --git a/src/contentcreatormanager/platform/facebook.py b/src/contentcreatormanager/platform/facebook.py index cc94ecd..82c92c3 100644 --- a/src/contentcreatormanager/platform/facebook.py +++ b/src/contentcreatormanager/platform/facebook.py @@ -56,27 +56,26 @@ def post(self, msg): Method to create and send a Facebook post. """ post = fb_post.FacebookPost(self, msg) - + 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) - + return post def api_post_feed(self, ID : str, message : str, page_access_token : str): diff --git a/src/contentcreatormanager/platform/lbry.py b/src/contentcreatormanager/platform/lbry.py index 089b68c..1d209d3 100644 --- a/src/contentcreatormanager/platform/lbry.py +++ b/src/contentcreatormanager/platform/lbry.py @@ -24,23 +24,20 @@ def claim_list(claim_type : list = [], claim_id : list = [], page_size=page_size, resolve=resolve, ) - - 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() class LBRY(plat.Platform): """ @@ -106,9 +103,7 @@ def __get_channel(self): Private method to make api call to get channel info based on claim_id (which is the id property) and return the results """ - result = self.api_channel_list(claim_id=[self.id]) - - return result + return self.api_channel_list(claim_id=[self.id]) def __add_channel_videos(self): """ @@ -120,18 +115,16 @@ def __add_channel_videos(self): channel_id=[self.id], order_by='name', resolve=False, page_size=LBRY.PAGE_RESULT_LENGTH) - + 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']] if page_amount > 1: for x in range(page_amount-1): self.logger.info(f"getting page {x+2} of data and adding it") @@ -141,11 +134,9 @@ def __add_channel_videos(self): resolve=False, page_size=LBRY.PAGE_RESULT_LENGTH) pages.append(current_result['result']['items']) - - page = 0 + x = 0 for p in pages: - page += 1 for i in p: x += 1 if i['value'].get('stream_type') == 'video': @@ -154,9 +145,9 @@ def __add_channel_videos(self): else: m=f"claim {i['name']} is not a video. Not adding it" self.logger.info(m) - + num_claims_before = len(self.media_objects) - + for c in claims: v = lbry_vid.LBRYVideo(ID=c['claim_id'], lbry_channel=self, request=c) @@ -164,7 +155,7 @@ def __add_channel_videos(self): thumb_dir = os.path.join(os.getcwd(), 'thumbs') v.thumbnail = os.path.join(thumb_dir, v.get_valid_thumbnail_file_name()) self.add_media(v) - + num_vids_added = len(self.media_objects) - num_claims_before m=f"{num_vids_added} LBRY Video Objects added to media_objects" self.logger.info(m) @@ -192,7 +183,7 @@ def add_video_with_name(self, name : str, file_name : str, m="Either update from web or upload to it not both :P" self.logger.error(m) return None - + vid = lbry_vid.LBRYVideo(settings=self.settings, lbry_channel=self, file_name=file_name) @@ -201,11 +192,11 @@ def add_video_with_name(self, name : str, file_name : str, vid.title = title vid.description = description vid.bid = bid - + if update_from_web: vid.update_local(use_name=True) elif upload: - if title == '' or description == '': + if not title or not description: m="Title and Description Required for new upload." self.logger.error(m) else: @@ -239,20 +230,20 @@ def api_get(self, uri : str, parameters = dict( uri=uri ) - - 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) - + return result def api_channel_list(self, claim_id : list = [], page : int = 0, @@ -270,21 +261,21 @@ def api_channel_list(self, claim_id : list = [], page : int = 0, resolve=resolve, page_size=page_size ) - - 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) - + return result def api_channel_create(self, name : str, bid : float, title : str, @@ -412,30 +403,30 @@ def api_file_delete(self, delete_from_download_dir : bool = False, delete_from_download_dir=delete_from_download_dir, delete_all=delete_all ) - - 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) - + return result def api_file_save(self, download_directory : str, @@ -451,17 +442,17 @@ def api_file_save(self, download_directory : str, download_directory=download_directory, claim_id=claim_id ) - - 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) - + return result def api_stream_abandon(self, claim_id : str): @@ -551,17 +542,17 @@ def api_stream_update(self, claim_id : str, bid : float, title : str, license=lic, license_url=license_url ) - - 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) - + return result def api_claim_list(self, claim_type : list = [], claim_id : list = [], @@ -582,24 +573,24 @@ def api_claim_list(self, claim_type : list = [], claim_id : list = [], page_size=page_size, resolve=resolve, ) - - 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() - + m=f"claim_list call with params: {parameters} made to the LBRY API" self.logger.info(m) - + return result def api_upload_thumb(self, file : str): diff --git a/src/contentcreatormanager/platform/platform.py b/src/contentcreatormanager/platform/platform.py index 6cddf3c..676a117 100644 --- a/src/contentcreatormanager/platform/platform.py +++ b/src/contentcreatormanager/platform/platform.py @@ -39,13 +39,11 @@ def read_json(self, file): a dict with the json data in it """ os.chdir(self.settings.original_dir) - - f = open(file) - data = json.load(f) - f.close() - + + with open(file) as f: + data = json.load(f) os.chdir(self.settings.folder_location) - + return data def add_video(self, video : media_vid.Video): @@ -58,19 +56,15 @@ def add_media(self, media : media.Media): """ Method to add a Media object to the media_objects list property """ - duplicate = False - for media_obj in self.media_objects: - if media.id == media_obj.id: - duplicate = True - + duplicate = any(media.id == media_obj.id for media_obj in self.media_objects) if duplicate: m="Trying to add a Media Object with a duplicate ID not adding" self.logger.error(m) return - + self.media_objects.append(media) self.media_object_titles.append(media.title) - + m=f"Media Object with id {media.id} added to media_objects" self.logger.info(m) diff --git a/src/contentcreatormanager/platform/reddit.py b/src/contentcreatormanager/platform/reddit.py index e8cb3b9..225cf47 100644 --- a/src/contentcreatormanager/platform/reddit.py +++ b/src/contentcreatormanager/platform/reddit.py @@ -78,31 +78,44 @@ def api_submit_text(self,subreddit:str,title:str,selftext:str='', Example Return URL (the url property): https://www.reddit.com/r/test/comments/t6l0o2/ccc_test_post/ """ self.logger.info("Making Reddit API call to post text to a subreddit") - + subreddit = self.praw.subreddit(subreddit) - - - if not (flair_id == '' or flair_id is None): - if not(flair_text == '' or flair_text is None): - result = subreddit.submit(title=title, selftext=selftext, - flair_id=flair_id, - flair_text=flair_text, - send_replies=send_replies, - nsfw=nsfw) - else: - result = subreddit.submit(title=title, selftext=selftext, - flair_id=flair_id, - send_replies=send_replies, - nsfw=nsfw) - elif not(flair_text == '' or flair_text is None): - result = subreddit.submit(title=title, selftext=selftext, - flair_text=flair_text, - send_replies=send_replies, nsfw=nsfw) + + + if flair_id and flair_id is not None: + return ( + subreddit.submit( + title=title, + selftext=selftext, + flair_id=flair_id, + flair_text=flair_text, + send_replies=send_replies, + nsfw=nsfw, + ) + if flair_text and flair_text is not None + else subreddit.submit( + title=title, + selftext=selftext, + flair_id=flair_id, + send_replies=send_replies, + nsfw=nsfw, + ) + ) + elif not (not flair_text or flair_text is None): + return subreddit.submit( + title=title, + selftext=selftext, + flair_text=flair_text, + send_replies=send_replies, + nsfw=nsfw, + ) else: - result = subreddit.submit(title=title, selftext=selftext, - send_replies=send_replies, nsfw=nsfw) - - return result + return subreddit.submit( + title=title, + selftext=selftext, + send_replies=send_replies, + nsfw=nsfw, + ) def api_submit_url(self, subreddit : str, title : str, url : str = '', flair_id : str = '', flair_text : str = '', @@ -118,23 +131,38 @@ def api_submit_url(self, subreddit : str, title : str, url : str = '', Example Return URL (the url property): https://odysee.com/@TechGirlTiff:5/ContentCreatorManager_Dev_Project_Update_00004:4 (note this returns the URL the post links to but the link to the comments could be constructed https://www.reddit.com/r/test/comments/t6l1ou/ccc_test_url_post/) """ self.logger.info("Making Reddit API call to post a URL to a subreddit") - + subreddit = self.praw.subreddit(subreddit) - - if not (flair_id == '' or flair_id is None): - if not(flair_text == '' or flair_text is None): - result=subreddit.submit(title=title, url=url,flair_id=flair_id, - flair_text=flair_text, - send_replies=send_replies, nsfw=nsfw) - else: - result=subreddit.submit(title=title, url=url,flair_id=flair_id, - send_replies=send_replies, nsfw=nsfw) - elif not(flair_text == '' or flair_text is None): - result=subreddit.submit(title=title, url=url,flair_text=flair_text, - send_replies=send_replies, nsfw=nsfw) + + if flair_id and flair_id is not None: + return ( + subreddit.submit( + title=title, + url=url, + flair_id=flair_id, + flair_text=flair_text, + send_replies=send_replies, + nsfw=nsfw, + ) + if flair_text and flair_text is not None + else subreddit.submit( + title=title, + url=url, + flair_id=flair_id, + send_replies=send_replies, + nsfw=nsfw, + ) + ) + elif not (not flair_text or flair_text is None): + return subreddit.submit( + title=title, + url=url, + flair_text=flair_text, + send_replies=send_replies, + nsfw=nsfw, + ) else: - result = subreddit.submit(title=title, url=url, - send_replies=send_replies, nsfw=nsfw) - - return result + return subreddit.submit( + title=title, url=url, send_replies=send_replies, nsfw=nsfw + ) \ No newline at end of file diff --git a/src/contentcreatormanager/platform/rumble.py b/src/contentcreatormanager/platform/rumble.py index d45bdb2..c5aa02b 100644 --- a/src/contentcreatormanager/platform/rumble.py +++ b/src/contentcreatormanager/platform/rumble.py @@ -91,10 +91,8 @@ def api_upload(self, access_token : str, title : str, description : str, 'video': (os.path.basename(video_file),open(video_file,'rb')), 'guid' : (None, guid) } - - response = requests.post(Rumble.UPLOAD_API_URL, files=files) - - return response + + return requests.post(Rumble.UPLOAD_API_URL, files=files) def api_media_item(self, fid : str, access_token : str): """ @@ -102,13 +100,10 @@ def api_media_item(self, fid : str, access_token : str): """ m="Media.Item API call implementation not working for Rumble" self.logger.warning(m) - + files = { 'fid': (None, fid), 'access_token' : (None, access_token) } - - response = requests.post("https://rumble.com/api/v0/Media.Item", - files=files) - - return response \ No newline at end of file + + return requests.post("https://rumble.com/api/v0/Media.Item", files=files) \ No newline at end of file diff --git a/src/contentcreatormanager/platform/twitter.py b/src/contentcreatormanager/platform/twitter.py index fa3782d..207d7a5 100644 --- a/src/contentcreatormanager/platform/twitter.py +++ b/src/contentcreatormanager/platform/twitter.py @@ -99,15 +99,14 @@ def api_update_status(self, status_text : str, attachment_url:str='', (This is if you provide an invalid attachment_url as this must be a Tweet permalink or Direct Message deep link) """ self.logger.info("Making update_status Twitter API Call") - - if attachment_url == '' or attachment_url is None: - api=self.api - ps=possibly_sensitive - return api.update_status(status=status_text,media_ids=media_ids, - possibly_sensitive=ps) - else: - ps=possibly_sensitive - return self.api.update_status(status=status_text, - media_ids=media_ids, - possibly_sensitive=ps, - attachment_url=attachment_url) \ No newline at end of file + + ps=possibly_sensitive + if attachment_url and attachment_url is not None: + return self.api.update_status( + status=status_text, + media_ids=media_ids, + ps=ps, + attachment_url=attachment_url, + ) + api=self.api + return api.update_status(status=status_text, media_ids=media_ids, ps=ps) \ No newline at end of file diff --git a/src/contentcreatormanager/platform/youtube.py b/src/contentcreatormanager/platform/youtube.py index ee4d74a..17b75b0 100644 --- a/src/contentcreatormanager/platform/youtube.py +++ b/src/contentcreatormanager/platform/youtube.py @@ -237,9 +237,8 @@ def __get_channel(self): self.logger.error(f"Error:\n{e}") return result self.logger.info("Chanels.list API Call made without Exception") - - res=result['items'][0]['contentDetails']['relatedPlaylists']['uploads'] - return res + + return result['items'][0]['contentDetails']['relatedPlaylists']['uploads'] def __set_videos(self): """ @@ -259,7 +258,7 @@ def __get_playlist_video_ids(self): """ result = None num_pages = 1 - + m="Making intial PlaylistItems.list API call" self.logger.info(m) try: @@ -270,14 +269,14 @@ def __get_playlist_video_ids(self): self.logger.error(f"Error During API call:\n{e}") return None self.logger.info("PlaylistIems.list API Call made without exception") - + self.logger.info("Adding first page of data to pages") pages = [result['items']] - + csv_length = result['pageInfo']['totalResults'] - + next_page_token = None - + if 'nextPageToken' in result: m="Setting next page token as there are multiple pages of data" self.logger.info(m) @@ -286,7 +285,8 @@ def __get_playlist_video_ids(self): two=result['pageInfo']['resultsPerPage'] num_pages = math.ceil(one/two) csv_length=math.ceil(result['pageInfo']['totalResults']/num_pages) - + + m="PlaylistIems.list API Call made without exception" while next_page_token is not None: self.logger.info("Making a playlistitems.list call") try: @@ -297,27 +297,24 @@ def __get_playlist_video_ids(self): except HttpError as e: self.logger.error(f"Error:\n{e}") return None - m="PlaylistIems.list API Call made without exception" self.logger.info(m) - + self.logger.info("Adding page of data to pages") pages.append(result['items']) - + next_page_token = None - + if 'nextPageToken' in result: - m="There is another page of data setting the token" - self.logger.info(m) + self.logger.info("There is another page of data setting the token") next_page_token = result['nextPageToken'] - + video_ids = self.__get_items_from_pages(pages, True) - - return_data = { - "video_ids":video_ids, - "num_pages":num_pages, - "csv_length":csv_length + + return { + "video_ids": video_ids, + "num_pages": num_pages, + "csv_length": csv_length, } - return return_data def __get_items_from_pages(self, pages, just_ids : bool = False): """ @@ -370,11 +367,7 @@ def __get_video_data_from_csvs(self, csvs : list): Private Method to grab data from multiple csv strings provided in the form of a list """ - 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] def __get_video_data_from_csv(self, csv : str): """ @@ -413,9 +406,7 @@ def add_video_with_request(self,request): First object data will be set using provided request (results from an API call) """ - tags = [] - if not ('tags' not in request['snippet']): - tags = request['snippet']['tags'] + tags = [] if 'tags' not in request['snippet'] else request['snippet']['tags'] description = "" if not ('description' not in request['snippet']): description = request['snippet']['description'] @@ -426,7 +417,7 @@ def add_video_with_request(self,request): default_audio_language = 'en-US' if not ('defaultAudioLanguage' not in request['snippet']): default_audio_language = request['snippet']['defaultAudioLanguage'] - + ytv = yt_vid.YouTubeVideo(channel=self, ID=request['id'], favorite_count=request['statistics']['favoriteCount'], comment_count=request['statistics']['commentCount'], @@ -553,7 +544,7 @@ def api_videos_insert_req(self, file : str, snippet_title : str, Returns a googleapiclient.http.HttpRequest object to be fed to api_videos_insert_exec """ self.logger.info("Making YouTube API Call to videos.insert which costs 1600 quota unit") - + parts = self.__get_parts(contentDetails=contentDetails,snippet=snippet, statistics=statistics, status=status, fileDetails=fileDetails, ID=ID, @@ -565,15 +556,15 @@ def api_videos_insert_req(self, file : str, snippet_title : str, topicDetails=topicDetails, auditDetails=False, brandingSettings=False, contentOwnerDetails=False) - - + + if len(parts) == 0: m="At least one part required api call will not be made" self.logger.error(m) return None - + part = ','.join(parts) - + snippet_dict={'title':snippet_title, 'description':snippet_description, 'tags':snippet_tags, 'categoryId':snippet_categoryId, 'defaultLanguage':snippet_defaultLanguage} @@ -582,20 +573,21 @@ def api_videos_insert_req(self, file : str, snippet_title : str, 'publicStatsViewable':status_publicStatsViewable, 'selfDeclaredMadeForKids':status_selfDeclaredMadeForKids } - + body = {'snippet':snippet_dict,'status':status_dict} - + m=f"API part: {part}, body: {body}, notifySubscribers: {notifySubscribers}, video: {file}" self.logger.info(m) - + v=self.service.videos() - request = v.insert(body=body, - media_body=googleapiclient.http.MediaFileUpload(file, - chunksize=-1, - resumable=True), - part=part, notifySubscribers=notifySubscribers) - - return request + return v.insert( + body=body, + media_body=googleapiclient.http.MediaFileUpload( + file, chunksize=-1, resumable=True + ), + part=part, + notifySubscribers=notifySubscribers, + ) def api_videos_insert_exec(self, request): """ @@ -629,11 +621,10 @@ def api_videos_insert_exec(self, request): self.logger.warning(m) return response except HttpError as e: - 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 except YouTube.RETRIABLE_EXCEPTIONS as e: error = f"A retriable error occurred: {e}" @@ -643,21 +634,21 @@ def api_videos_insert_exec(self, request): if retry > YouTube.MAX_RETRIES: self.logger.error('No longer attempting to retry.') return response - + max_sleep = 2 ** retry sleep_seconds = random.random() * max_sleep m=f"Sleeping {sleep_seconds} seconds and then retrying..." self.logger.info(m) time.sleep(sleep_seconds) - + self.logger.info("Videos.insert call to YouTube API complete") - + self.quota_usage += quota_cost - + m=f"API call made. Current Quota Usage: {self.quota_usage}" self.logger.info(m) - + return response def api_videos_update(self, snippet_categoryId : int, @@ -806,14 +797,14 @@ def api_playlistitems_list(self, contentDetails : bool = False, pageToken='EAAaBlBUOkNBTQ') Example Results with pageToken: {'kind': 'youtube#playlistItemListResponse', 'etag': '2ixEvQy_1aHNH3YpSIv_nplMJvs', 'nextPageToken': 'EAAaBlBUOkNBWQ', 'prevPageToken': 'EAEaBlBUOkNBTQ', 'items': [{'kind': 'youtube#playlistItem', 'etag': 'QgGQdMYagwQGQm7i2hKZJ2X6tv4', 'id': 'VVVpZHJIdkZYQnZ5ZXNoMWhiT1IyclR3LmhBTXBfQlFEZjAw', 'contentDetails': {'videoId': 'hAMp_BQDf00', 'videoPublishedAt': '2021-10-02T12:00:32Z'}}, {'kind': 'youtube#playlistItem', 'etag': 'R4AzQocoTVqgoUIHkVGWMx7OtAA', 'id': 'VVVpZHJIdkZYQnZ5ZXNoMWhiT1IyclR3LkhZTTZRT1dKT0Q4', 'contentDetails': {'videoId': 'HYM6QOWJOD8', 'videoPublishedAt': '2021-10-01T18:00:05Z'}}, {'kind': 'youtube#playlistItem', 'etag': '42I4J4EAopmbwZ3p9VtanWygqlM', 'id': 'VVVpZHJIdkZYQnZ5ZXNoMWhiT1IyclR3LkkyVTB2SUZzc2lz', 'contentDetails': {'videoId': 'I2U0vIFssis', 'videoPublishedAt': '2021-10-01T12:00:10Z'}}], 'pageInfo': {'totalResults': 158, 'resultsPerPage': 3}} """ - 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 - + parts = self.__get_parts(contentDetails=contentDetails,snippet=snippet, statistics=False, status=status, fileDetails=False, ID=ID, @@ -824,28 +815,16 @@ def api_playlistitems_list(self, contentDetails : bool = False, topicDetails=False, auditDetails=False, brandingSettings=False, contentOwnerDetails=False) - + if len(parts) == 0: m="At least one part required api call will not be made" self.logger.error(m) return None - + part = ','.join(parts) - + pis=self.service.playlistItems() - if playlistId == '': - if videoId != '' and pageToken != '': - request = pis.list(part=part,maxResults=maxResults,id=ids, - videoId=videoId, pageToken=pageToken) - elif pageToken != '': - request = pis.list(part=part,maxResults=maxResults,id=ids, - pageToken=pageToken) - elif videoId != '': - request = pis.list(part=part, maxResults=maxResults, id=ids, - videoId=videoId) - else: - request = pis.list(part=part, maxResults=maxResults, id=ids) - elif ids == '': + if playlistId: if videoId != '' and pageToken != '': request = pis.list(part=part, maxResults=maxResults, playlistId=playlistId, videoId=videoId, @@ -859,16 +838,27 @@ def api_playlistitems_list(self, contentDetails : bool = False, else: request = pis.list(part=part, maxResults=maxResults, playlistId=playlistId) - - self.logger.info(f"API call being made") - + + elif videoId != '' and pageToken != '': + request = pis.list(part=part,maxResults=maxResults,id=ids, + videoId=videoId, pageToken=pageToken) + elif pageToken != '': + request = pis.list(part=part,maxResults=maxResults,id=ids, + pageToken=pageToken) + elif videoId != '': + request = pis.list(part=part, maxResults=maxResults, id=ids, + videoId=videoId) + else: + request = pis.list(part=part, maxResults=maxResults, id=ids) + self.logger.info("API call being made") + result = request.execute() - + self.quota_usage += quota_cost - + m=f"API call made. Current Quota Usage: {self.quota_usage}" self.logger.info(m) - + return result def api_playlistitems_insert(self): diff --git a/src/first_gui_test.py b/src/first_gui_test.py index 515925a..42c538c 100644 --- a/src/first_gui_test.py +++ b/src/first_gui_test.py @@ -282,25 +282,22 @@ def __lbry_init_plat(self, event): self.lbry_vids_not_downloaded = [] if self.lbry_plat is None: channels = lbry_plat.claim_list(claim_type=['channel']) - 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() - + return 'break' def __lbry_api_setup(self, event): @@ -468,16 +465,14 @@ def __populate_yt_upload_lb_from_lbry(self): yvid.thumbnail = obj.download_thumb() os.chdir(self.settings.folder_location) else: - 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 self.yt_upload_list = list3 return @@ -512,18 +507,16 @@ def __populate_lbry_upload_lb_from_yt(self): lvid.thumbnail = obj.download_thumb() os.chdir(self.settings.folder_location) else: - 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 self.lbry_upload_list = list3 return @@ -531,9 +524,8 @@ def __populate_lbry_lb(self): """ Private Method to popuate the LBRY Channel List Boxes """ - count = 0 count_2 = 0 - for o in self.lbry_plat.media_objects: + for count, o in enumerate(self.lbry_plat.media_objects): self.settings.Base_logger.info(f"Adding {o.title} to yt lb position {count}") self.lbry_lb.insert(count, o.title) self.settings.Base_logger.info(f"checking if file {o.file} is downloaded") @@ -543,16 +535,14 @@ def __populate_lbry_lb(self): self.lbry_vids_not_downloaded.append(o) self.lbry_not_downloaded_lb.insert(count_2, o.title) count_2 += 1 - count += 1 - 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): self.settings.Base_logger.info(f"Adding {o.title} to yt lb position {count}") self.yt_lb.insert(count, o.title) self.settings.Base_logger.info(f"checking if file {o.file} is downloaded") @@ -562,7 +552,6 @@ def __populate_yt_lb(self): self.yt_vids_not_downloaded.append(o) self.yt_not_downloaded_lb.insert(count_2, o.title) count_2 += 1 - count += 1 def __create_yt_client_secrets(self): @@ -594,7 +583,7 @@ def __setup_folder(self, folder_location: str=''): """ Private Method to set up the Applications home base and return settings for it """ - if folder_location == '': + if not folder_location: folder = tk_fd.askdirectory(title='Choose Application Directory') else: folder = folder_location diff --git a/src/lbry_bulk_upload.py b/src/lbry_bulk_upload.py index a7fbd26..8de57e0 100644 --- a/src/lbry_bulk_upload.py +++ b/src/lbry_bulk_upload.py @@ -5,6 +5,7 @@ @author: tiff ''' + import contentcreatormanager.platform.lbry as lbry_plat import contentcreatormanager.config as config import contentcreatormanager.media.video.lbry as lbry_vid @@ -19,19 +20,16 @@ channels = lbry_plat.claim_list(claim_type=['channel']) print(channels['result']['items'][0]['name']) -count = 1 choices = {} -for channel in channels['result']['items']: +for count, channel in enumerate(channels['result']['items'], start=1): print(f"{count}. {channel['name']}") choices[f'{count}'] = channel - count += 1 - choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") -while not (choice in choices): +while choice not in choices: print(f"You entered {choice} which is not one of the options") choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") - + channel_claim_id = choices[choice]['claim_id'] lbry = lbry_plat.LBRY(settings=settings, ID=channel_claim_id, init_videos=False) @@ -52,31 +50,24 @@ while adding_tags: tag = input("Enter Tag:") another_tag = input("Would you like to add another tag?(y/n):") - if not ('y' in another_tag or 'Y' in another_tag): + if 'y' not in another_tag and 'Y' not in another_tag: adding_tags = False tags.append(tag) if not adding_tags: print(f"You are about to quit adding tags. Here they are so far:\n{tags}") sure = input("Are you sure you are done?(y/n):") - if not ('y' in sure or 'Y' in sure): + if 'y' not in sure and 'Y' not in sure: adding_tags = True files = os.listdir('.') -mp4_files = [] - -for f in files: - if f[-4:] == '.mp4': - mp4_files.append(f) - +mp4_files = [f for f in files if f[-4:] == '.mp4'] for v in mp4_files: lbry_video = lbry_vid.LBRYVideo(lbry_channel=lbry,title=v[:-4],tags=tags,file_name=v,name=v[:-4],bid=bid,description=description,new_video=True,lic=lic,license_url=license_url) - + lbry.add_video(lbry_video) - -count = 1 -for v in lbry.media_objects: +for count, v in enumerate(lbry.media_objects, start=1): print(f"\nVideo {count}") print(f"file: {v.file}") print(f"name: {v.name}") @@ -86,16 +77,14 @@ print(f"license: {v.license}") print(f"license url: {v.license_url}") print(f"bid: {v.bid}\n") - count += 1 - upload = False should_upload = input("Would you like to make the uploads listed above(y/n)?") -if not ('n' in should_upload or 'N' in should_upload): +if 'n' not in should_upload and 'N' not in should_upload: if 'y' in should_upload or 'Y' in should_upload: upload = True - + if upload: print("Starting upload") for v in lbry.media_objects: diff --git a/src/lbry_set_thumbs_from_youtube.py b/src/lbry_set_thumbs_from_youtube.py index ce9aa7d..9582b4d 100644 --- a/src/lbry_set_thumbs_from_youtube.py +++ b/src/lbry_set_thumbs_from_youtube.py @@ -4,6 +4,7 @@ @author: tiff ''' + import contentcreatormanager.platform.lbry as lbry_plat import contentcreatormanager.config as config import contentcreatormanager.media.video.lbry as lbry_vid @@ -19,19 +20,16 @@ channels = lbry_plat.claim_list(claim_type=['channel']) print(channels['result']['items'][0]['name']) -count = 1 choices = {} -for channel in channels['result']['items']: +for count, channel in enumerate(channels['result']['items'], start=1): print(f"{count}. {channel['name']}") choices[f'{count}'] = channel - count += 1 - choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") -while not (choice in choices): +while choice not in choices: print(f"You entered {choice} which is not one of the options") choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") - + channel_claim_id = choices[choice]['claim_id'] lbry = lbry_plat.LBRY(settings=settings, ID=channel_claim_id, init_videos=True) @@ -41,12 +39,13 @@ on_both = [] for yvid in youtube.media_objects: - for lvid in lbry.media_objects: - if lvid.title == yvid.title: - on_both.append({'yt':yvid,'lbry':lvid}) - + on_both.extend( + {'yt': yvid, 'lbry': lvid} + for lvid in lbry.media_objects + if lvid.title == yvid.title + ) for vids in on_both: vids['lbry'].thumbnail_url = vids['yt'].get_thumb_url() vids['lbry'].logger.info(f"Setting Thumbnail url for {vids['lbry'].title} to {vids['lbry'].thumbnail_url}") - + lbry.update_all_media_web() \ No newline at end of file diff --git a/src/lbry_thumbnail_generate_and_upload.py b/src/lbry_thumbnail_generate_and_upload.py index a9d63eb..25064a1 100644 --- a/src/lbry_thumbnail_generate_and_upload.py +++ b/src/lbry_thumbnail_generate_and_upload.py @@ -3,6 +3,7 @@ @author: tiff ''' + import contentcreatormanager.platform.lbry as lbry_plat import contentcreatormanager.config as config import os.path @@ -16,19 +17,16 @@ channels = lbry_plat.claim_list(claim_type=['channel']) print(channels['result']['items'][0]['name']) -count = 1 choices = {} -for channel in channels['result']['items']: +for count, channel in enumerate(channels['result']['items'], start=1): print(f"{count}. {channel['name']}") choices[f'{count}'] = channel - count += 1 - choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") -while not (choice in choices): +while choice not in choices: print(f"You entered {choice} which is not one of the options") choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") - + channel_claim_id = choices[choice]['claim_id'] lbry = lbry_plat.LBRY(settings=settings, ID=channel_claim_id, init_videos=True) diff --git a/src/second_gui_test.py b/src/second_gui_test.py index a7ed731..e7f4472 100644 --- a/src/second_gui_test.py +++ b/src/second_gui_test.py @@ -160,8 +160,10 @@ def load_lbry_data(self): picked = False for ch in channels['result']['items']: if not picked: - option = tk_mb.askyesno(title='LBRY Channel Confirmation',message=f'Do you want to use this channel:{ch["name"]}') - if option: + if option := tk_mb.askyesno( + title='LBRY Channel Confirmation', + message=f'Do you want to use this channel:{ch["name"]}', + ): window = tk.Toplevel() window.geometry("400x90") window.wm_title("Loading LBRY Data") @@ -179,19 +181,19 @@ def load_lbry_data(self): window.update_idletasks() window.grab_set() self.lbry_plat = lbry_plat.LBRY(settings=self.settings, ID=channels['result']['items'][0]['claim_id'], init_videos=True) - + for vid in self.lbry_plat.media_objects: if not os.path.isfile(vid.file): self.lbry_vid_not_dl.append(vid) self.lbry_vid_not_dl_titles.append(vid.title) - + self.lbry_vid_var.set(self.lbry_plat.media_object_titles) self.lbry_vid_not_var.set(self.lbry_vid_not_dl_titles) window.destroy() def get_vids_yt_not_lbry(self): self.logger.info("Getting videos on YouTube not on LBRY") - + list1 = self.yt_plat.media_objects list2 = self.lbry_plat.media_objects thumb_dir = os.path.join(os.getcwd(), 'thumbs') @@ -215,14 +217,14 @@ def get_vids_yt_not_lbry(self): lvid.thumbnail = obj.download_thumb() os.chdir(self.settings.folder_location) else: - self.logger.info(f"Thumbnail already present no need to download") + self.logger.info("Thumbnail already present no need to download") lvid.thumbnail = obj.thumbnail self.logger.info(f"Setting bid for new LBRY Vid to {self.default_bid}") lvid.bid = self.default_bid self.logger.info(f"Adding {lvid.title} to list of vids not on LBRY that are on YouTube") self.lbry_upload_vids.append(lvid) self.lbry_upload_titles.append(lvid.title) - + self.lbry_up_var.set(self.lbry_upload_titles) def lbry_remove_upload_list(self): @@ -346,7 +348,7 @@ def lbry_select_video(self): def get_vids_lbry_not_yt(self): self.logger.info("Getting videos on LBRY that are not on YouTube") - + list1 = self.lbry_plat.media_objects list2 = self.yt_plat.media_objects thumb_dir = os.path.join(os.getcwd(), 'thumbs') @@ -383,12 +385,12 @@ def get_vids_lbry_not_yt(self): yvid.thumbnail = obj.download_thumb() os.chdir(self.settings.folder_location) else: - self.logger.info(f"Thumbnail already present no need to download") + self.logger.info("Thumbnail already present no need to download") yvid.thumbnail = obj.thumbnail self.logger.info(f"Adding {yvid.title} to list of vids not on YouTube that are on LBRY") self.yt_upload_vids.append(yvid) self.yt_upload_titles.append(yvid.title) - + self.yt_up_var.set(self.yt_upload_titles) def yt_remove_upload_list(self): diff --git a/src/youtube_lbry_sync.py b/src/youtube_lbry_sync.py index c656a99..9c1de08 100644 --- a/src/youtube_lbry_sync.py +++ b/src/youtube_lbry_sync.py @@ -4,6 +4,7 @@ @author: tiff ''' + import contentcreatormanager.platform.lbry as lbry_plat import contentcreatormanager.config as config import contentcreatormanager.media.video.lbry as lbry_vid @@ -20,90 +21,67 @@ channels = lbry_plat.claim_list(claim_type=['channel']) print(channels['result']['items'][0]['name']) -count = 1 choices = {} -for channel in channels['result']['items']: +for count, channel in enumerate(channels['result']['items'], start=1): print(f"{count}. {channel['name']}") choices[f'{count}'] = channel - count += 1 - choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") -while not (choice in choices): +while choice not in choices: print(f"You entered {choice} which is not one of the options") choice = input("Pick the channel you want to upload to (Just enter the number next to it above):") - + channel_claim_id = choices[choice]['claim_id'] lbry = lbry_plat.LBRY(settings=settings, ID=channel_claim_id, init_videos=True) default_bid = input("Please enter your default bid for uploading to LBRY (Just hit enter for minimum):") -if '' != default_bid: +if default_bid != '': default_bid = float(default_bid) youtube = yt_plat.YouTube(settings=settings, init_videos=True) youtube_not_lbry = [] lbry_not_youtube = [] -youtube_to_dl = [] -lbry_to_dl = [] - priv = input("Should private videos be synced(Y/N)?") unlist = input("Should unlisted videos be synced(Y/N)?") for yvid in youtube.media_objects: - in_lbry = False - for lvid in lbry.media_objects: - #settings.Base_logger.info(f"Checking {lvid.title} against {yvid.title}") - if lvid.title == yvid.title: - #settings.Base_logger.info("They are the same") - in_lbry = True - if not in_lbry: + in_lbry = any(lvid.title == yvid.title for lvid in lbry.media_objects) #settings.Base_logger.info(f"Adding {yvid.title} since it is not on LBRY") - if yvid.privacy_status == 'private' and ('y' in priv or 'Y' in priv): + if yvid.privacy_status == 'private' and ('y' in priv or 'Y' in priv): + if not in_lbry: youtube_not_lbry.append(yvid) - elif yvid.privacy_status == 'unlisted' and ('y' in unlist or 'Y' in unlist): + elif yvid.privacy_status == 'unlisted' and ('y' in unlist or 'Y' in unlist): + if not in_lbry: youtube_not_lbry.append(yvid) - elif yvid.privacy_status == 'public': + elif yvid.privacy_status == 'public': + if not in_lbry: youtube_not_lbry.append(yvid) - + for lvid in lbry.media_objects: - in_yt = False - for yvid in youtube.media_objects: - #settings.Base_logger.info(f"Checking {lvid.title} against {yvid.title}") - if yvid.title == lvid.title: - #settings.Base_logger.info("They are the same") - in_yt = True + in_yt = any(yvid.title == lvid.title for yvid in youtube.media_objects) if not in_yt: #settings.Base_logger.info(f"Adding {yvid.title} since it is not on LBRY") lbry_not_youtube.append(lvid) - -for v in youtube_not_lbry: - if not v.is_downloaded(): - youtube_to_dl.append(v) - -for v in lbry_not_youtube: - if not v.is_downloaded(): - lbry_to_dl.append(v) +youtube_to_dl = [v for v in youtube_not_lbry if not v.is_downloaded()] +lbry_to_dl = [v for v in lbry_not_youtube if not v.is_downloaded()] for v in lbry_to_dl: v.download() - + for v in youtube_to_dl: v.download() -count = 0 - -for v in youtube_not_lbry: +for count, v in enumerate(youtube_not_lbry): lvid = lbry_vid.LBRYVideo(lbry_channel=lbry, name=v.title, tags=v.tags, title=v.title, file_name=os.path.basename(v.file), description=v.description, new_video=True) - if '' != default_bid: + if default_bid != '': lvid.bid = default_bid lvid.thumbnail_url = v.get_thumb_url() lbry.add_media(lvid) if count < 2: input(f"About to upload {lvid.file} hit Enter to upload") - count += 1 lvid.upload()