def stuff( mes1_list=[ ['dhnwjakdwa', 'this is a video'], ['dhwwhjakwa', 'F**K'], ]): mes_list = [] mes_list2 = [] for mes1 in mes1_list: print(mes1) obj = mock_comm(mes1[0], mes1[1]) mes_list.append(obj) mes_list2.append(obj) def mes_name_sort(mes_obj_list): mfd = {} for mes in mes_obj_list: try: mfd[str(mes.author)] += 1 except KeyError: mfd[str(mes.author)] = 1 mfdl = list(mfd) f_l = [] for i in mfdl: f_l.append(mfd[i]) sorted_names = [] what = [] for i in f_l: what.append(i) mol_s = [] for i in what: #print(f_l_n) maxx = max(f_l) maxx_l = f_l.index(maxx) sorted_names.append(mfdl[maxx_l]) mol_s.append(mes_obj_list[maxx_l]) del mes_obj_list[maxx_l] del f_l[maxx_l] del mfdl[maxx_l] return sorted_names sn = mes_name_sort(mes_list) #print(mes_list2) #print(mes_list2) print('getting charcaters') characters = anim.get_characters(sn) print('got characters, getting scene') anim.comments_to_scene(mes_list2, characters, output_filename='hello.mp4') print('got scene') compress_video('hello.mp4', 'video.mp4', 5500)
async def acecourt(self, ctx: context, num_comments: int): basemessage = ctx.message.reference.resolved if ctx.message.reference else ctx.message unames = [] origcomments = [] imgs = [] if not basemessage.id == ctx.message.id: num_comments -= 1 uname, comment, img, attachment = process_comment(basemessage) if img: await attachment.save(attachment.filename) unames.append(uname) origcomments.append(comment) imgs.append(img) history = ctx.channel.history(limit=num_comments, oldest_first=False, before=basemessage) async for message in history: uname, comment, img, attachment = process_comment(message) if img: await attachment.save(attachment.filename) unames.append(uname) origcomments.append(comment) imgs.append(img) cnt = Counter(unames) most_common_pair = cnt.most_common(len(cnt)) most_common = [] for a, b in most_common_pair: most_common.append(a) characters = anim.get_characters(most_common=most_common) comments = [] for uname, comment, img in zip(unames, origcomments, imgs): comments.append(DiscordComment(uname, comment, img=img)) comments.reverse() anim.comments_to_scene(comments, characters, output_filename="ace.mp4") fileSize = os.path.getsize("ace.mp4") if fileSize < ctx.channel.guild.filesize_limit: await ctx.send(content="", file=discord.File("ace.mp4")) else: await ctx.send("The resulting filesize is too big to send.") for img in imgs: cleanupfiles(img)
async def on_message(mention: discord.Message): if mention.author == client.user: return if mention.guild == None: await mention.channel.send( content= 'I can\'t process any messages via PM. If you have any problem please go to the support server. https://discord.gg/pcS4MPbRDU' ) return match = re.match(r'!render (\d+)', mention.content) if match: number = int(match.group(1)) messages = [] async for message in mention.channel.history(limit=number, oldest_first=False, before=mention): messages.insert(0, Message(message)) thread = [] users_to_names = {} counter = Counter() for message in messages: thread.append(Comment(message)) users_to_names[message.user.id] = message.user.name counter.update({message.user.id: 1}) if (len(users_to_names) >= 2): most_common = [users_to_names[t[0]] for t in counter.most_common()] characters = anim.get_characters(most_common) output_filename = str(mention.id) + '.mp4' anim.comments_to_scene(thread, characters, output_filename=output_filename) await mention.channel.send(file=discord.File(output_filename)) os.remove(output_filename) else: await mention.channel.send( content='There should be at least two people in the conversation' )
def createVideo(self): thread = [] users_to_names = {} counter = Counter() self.chatList[self.chatId] = None for message in self.messages: thread.append(Comment(message)) users_to_names[message.user.id] = message.user.name counter.update({message.user.id: 1}) if (len(users_to_names) >= 2): most_common = [users_to_names[t[0]] for t in counter.most_common()] characters = anim.get_characters(most_common) output_filename = str(self.chatId) + '.mp4' anim.comments_to_scene(thread, characters, output_filename=output_filename) with open(output_filename, 'rb') as video: self.update.message.reply_video(video, timeout=120) self.clean(output_filename, thread) else: self.update.message.reply_text( "There should be at least two people in the conversation") self.clean(output_filename, thread)
print( f"doing {comment.id} (https://www.reddit.com{comment.permalink})" ) # handle metadata print(f"handling metadata...") db.insert({"id": comment.id}) comments = list(reversed(get_comment_chain(comment)))[:-1] authors = [comment.author.name for comment in comments] most_common = [t[0] for t in Counter(authors).most_common()] submission = get_submission(comment) # generate video output_filename = f"{comment.id}.mp4" print(f"generating video {output_filename}...") characters = anim.get_characters(most_common) anim.comments_to_scene( comments, characters, output_filename=output_filename ) # upload video print(f"uploading video...") response = _spaw.videoUpload(output_filename) print(response) comment.reply( f"[Here's the video!](https://streamable.com/{response['shortcode']})" ) print(f"done {comment.id}") except Exception as e: print(e)
def process_tweets(): global mention_queue global lastTime while True: try: tweet = mention_queue.get() thread = [] users_to_names = { } # This will serve to link @display_names with usernames counter = Counter() current_tweet = tweet songs = ['PWR', 'JFA', 'TAT', 'rnd'] if 'music=' in tweet.content: music_tweet = tweet.content.split('music=', 1)[1][:3] else: music_tweet = 'PWR' if music_tweet == 'rnd': music_tweet = random.choices(songs, [1, 1, 1, 0], k=1)[0] if music_tweet not in songs: # If the music is written badly in the mention tweet, the bot will remind how to write it properly try: api.status_post( '@' + tweet.account.username + ' The music argument format is incorrect. The posibilities are: \nPWR: Phoenix Wright Ace Attorney \nJFA: Justice for All \nTAT: Trials and Tribulations \nrnd: Random', in_reply_to_id=tweet) except Exception as musicerror: print(musicerror) else: while (current_tweet is not None) and current_tweet.in_reply_to_id: try: context_data = api.status_context(current_tweet.id) current_tweet = api.status(context_data['ancestors'][ len(context_data['ancestors']) - 1]) sanitize_tweet(current_tweet) users_to_names[ current_tweet.account. username] = current_tweet.account.display_name counter.update({current_tweet.account.username: 1}) thread.insert(0, Comment(current_tweet)) except MastodonAPIError as e: try: api.status_post( '@' + tweet.account.username + ' I\'m sorry. I wasn\'t able to retrieve the full thread. Deleted tweets or private accounts may exist', in_reply_to_id=tweet) except Exception as second_error: print('Exception:' + second_error) current_tweet = None if (len(users_to_names) >= 2): most_common = [ users_to_names[t[0]] for t in counter.most_common() ] characters = anim.get_characters(most_common) output_filename = str(tweet.id) + '.mp4' anim.comments_to_scene(thread, characters, name_music=music_tweet, output_filename=output_filename) # Give some time to the other thread time.sleep(1) try: uploaded_media = api.media_post(output_filename, mime_type='video/mp4') api.status_post('@' + tweet.account.username + ' ', in_reply_to_id=tweet, media_ids=[uploaded_media]) except MastodonRatelimitError as e: print("I'm Rated-limited :(") mention_queue.put(tweet) except MastodonAPIError as e: try: print(e) except Exception as parsexc: print('Exception:' + parsexc) try: api.status_post('@' + tweet.account.username + ' ' + str(e), in_reply_to_id=tweet) except Exception as second_error: print('Exception:' + second_error) print(e) os.remove(output_filename) else: try: api.status_post( '@' + tweet.account.username + " There should be at least two people in the conversation", in_reply_to_id=tweet) except Exception as e: print('Exception:' + e) time.sleep(1) except Exception as e: print(e)
class MockRedditAuthor: def __init__(self, name): self.name = name class MockRedditComment: def __init__(self, username: str, text: str, score: int = 0): self.author = MockRedditAuthor(username) self.body = text self.score = score most_common = [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n' ] # usernames in order of freq characters = anim.get_characters( most_common) # returns a dict where key = character, val = username comments = [ MockRedditComment('a', 'Hello as I am the most common I will be Phoenix'), MockRedditComment('b', 'wassup I\'m edgyboy'), MockRedditComment('c', 'I\'m someone random and I\'m angry'), MockRedditComment('c', 'Bonjour, je m\'appelle Louis'), MockRedditComment('c', ':('), MockRedditComment('d', 'Ti odio, mi sento male'), MockRedditComment('e', 'Ich hasse dich, ich fühle mich schlecht'), MockRedditComment('f', 'Te odio, no me encuentro bien'), MockRedditComment('g', 'Estoy triste'), MockRedditComment('h', 'sono triste'), MockRedditComment('i', 'im so happy'), MockRedditComment('j', 'im so happy'), MockRedditComment('k', 'im so happy'), MockRedditComment('l', 'im so happy'),