agermanidis / SnapchatBot

[deprecated] Python library for building bots that live on Snapchat
MIT License
518 stars 105 forks source link

Error sending a snap from a file. #16

Closed N07070 closed 9 years ago

N07070 commented 9 years ago
Traceback (most recent call last):
  File "storyfbbot-dev.py", line 40, in <module>
    bot.listen()
  File "/home/n07070/Code/SnapchatBot/snapchat_bots/bot.py", line 71, in listen
    self.on_friend_delete(friend)
  File "storyfbbot-dev.py", line 17, in on_friend_delete
    self.send_snap(friend, Snap.from_file('resources/adieu.png'))
  File "/home/n07070/Code/SnapchatBot/snapchat_bots/snap.py", line 15, in from_file
    if duration is None: duration = get_video_duration(path)
  File "/home/n07070/Code/SnapchatBot/snapchat_bots/utils.py", line 48, in get_video_duration
    duration_string = re.findall(r'Duration: ([0-9:]*)', matches[0])[0]
IndexError: list index out of range
krissrex commented 9 years ago

Looks like this does not find anything:

re.findall

Could you test by using a print statement instead of _durationstring = to print the following? :

re.findall(r'Duration: ([0-9:]*)', matches[0])
agermanidis commented 9 years ago

The main issue seems to be that it's dealing with an image as a video, that's why it tries to get the duration of the video w/ ffprobe and fails. It's strange, as I tried creating a Snap from a png file and it correctly handled it on my machine, but I'll look into it further.

N07070 commented 9 years ago

@krissrex I cannot reproduce the error, but now, it outputs this error ( it sends the image as a video. )

ffmpeg version 0.8.16-6:0.8.16-1, Copyright (c) 2000-2014 the Libav developers
  built on Sep 17 2014 13:32:57 with gcc 4.7.2
The ffmpeg program is only provided for script compatibility and will be removed
in a future release. It has been deprecated in the Libav project to allow for
incompatible command line syntax improvements in its replacement called avconv
(see Changelog for details). Please use avconv instead.
Input #0, image2, from 'resources/auto_welcome.png':
  Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
    Stream #0.0: Video: png, bgra, 290x600, 25 tbr, 25 tbn, 25 tbc
Incompatible pixel format 'bgra' for codec 'libx264', auto-selecting format 'yuv420p'
[buffer @ 0x8f8f640] w:290 h:600 pixfmt:bgra
[avsink @ 0x8f8f800] auto-inserting filter 'auto-inserted scaler 0' between the filter 'src' and the filter 'out'
[scale @ 0x8f96300] w:290 h:600 fmt:bgra -> w:290 h:600 fmt:yuv420p flags:0x4
[libx264 @ 0x8f8ea60] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
[libx264 @ 0x8f8ea60] profile Main, level 2.1
[libx264 @ 0x8f8ea60] 264 - core 123 r2189 35cf912 - H.264/MPEG-4 AVC codec - Copyleft 2003-2012 - http://www.videolan.org/x264.html - options: cabac=1 ref=3 deblock=1:0:0 analyse=0x1:0x111 me=hex subme=7 psy=1 psy_rd=1.00:0.00 mixed_ref=0 me_range=16 chroma_me=1 trellis=1 8x8dct=0 cqm=0 deadzone=21,11 fast_pskip=1 chroma_qp_offset=-2 threads=1 sliced_threads=0 nr=0 decimate=1 interlaced=0 bluray_compat=0 constrained_intra=0 bframes=3 b_pyramid=0 b_adapt=1 b_bias=0 direct=1 weightb=0 open_gop=1 weightp=2 keyint=250 keyint_min=25 scenecut=40 intra_refresh=0 rc_lookahead=40 rc=crf mbtree=1 crf=23.0 qcomp=0.60 qpmin=0 qpmax=69 qpstep=4 ip_ratio=1.25 aq=1:1.00
Output #0, mp4, to '/tmp/tmpoeqKZr.snap.mp4':
  Metadata:
    encoder         : Lavf53.21.1
    Stream #0.0: Video: libx264, yuv420p, 290x600, q=-1--1, 25 tbn, 25 tbc
Stream mapping:
  Stream #0.0 -> #0.0
Press ctrl-c to stop encoding
frame=    1 fps=  0 q=28.0 Lsize=      10kB time=10000000000.00 bitrate=   0.0kbits/s    
video:9kB audio:0kB global headers:0kB muxing overhead 8.308453%
frame I:1     Avg QP:26.82  size:  9006
[libx264 @ 0x8f8ea60] mb I  I16..4: 73.4%  0.0% 26.6%
[libx264 @ 0x8f8ea60] coded y,uvDC,uvAC intra: 18.3% 28.0% 27.3%
[libx264 @ 0x8f8ea60] i16 v,h,dc,p: 90%  5%  4%  0%
[libx264 @ 0x8f8ea60] i4 v,h,dc,ddl,ddr,vr,hd,vl,hu: 30% 24% 22%  2%  3%  4%  4%  5%  4%
[libx264 @ 0x8f8ea60] i8c dc,h,v,p: 77% 15%  5%  3%
[libx264 @ 0x8f8ea60] kb/s:1801.20
EthanBlackburn commented 9 years ago

have you tried using guess_type() on your image? And could you post the code for you bot

N07070 commented 9 years ago

I did not try to use the guess_type(). Here is the code of the bot :

#!/usr/bin/python
# -*- coding: utf-8 -*-
from argparse import ArgumentParser
from snapchat_bots import SnapchatBot, Snap
from snapchat_bots.utils import save_snap

class FbStoryBot(SnapchatBot):

    # Acceuillir l'utilisateur
    def on_friend_add(self, friend):
        self.log(str(friend)+" has added me !")
        self.send_snap(friend, Snap.from_file('resources/auto_welcome.png'))

    # Dire au revoir si il nous supprime
    def on_friend_delete(self, friend):
        self.log(str(friend)+" does not want me anymore...")
        self.send_snap(friend, Snap.from_file('resources/adieu.png'))
        self.log("Said goodbye.")
        self.delete_friend(friend)

    # Ajout d'une story
    def on_snap(self, sender, snap):
        # Ajout d'un log dans un fichier texte ?
        self.log("Recived a snap from "+str(sender))
        save_snap(snap)
        self.post_story(snap)
        self.log("Saved the snap in the directory.")

if __name__ == '__main__':
    # parser = ArgumentParser('Auto-Welcomer Bot')

    # parser.add_argument('-u', '--username', required=True, type=str, help="Username of the account to run the bot on")
    # parser.add_argument('-p', '--password', required=True, type=str, help="Password of the account to run the bot on")

    # args = parser.parse_args()

    bot = FbStoryBot('xxx', 'xxx')
    #Lister tout les utilisateurs puis le nombre d'utilisateurs.
    print("I have "+str(len(bot.get_friends()))+" friends !")
    bot.listen()
EthanBlackburn commented 9 years ago

I found it.

if media_type is MEDIA_TYPE_VIDEO or MEDIA_TYPE_VIDEO_WITHOUT_AUDIO

should be

if media_type is MEDIA_TYPE_VIDEO or media_type is MEDIA_TYPE_VIDEO_WITHOUT_AUDIO

agermanidis commented 9 years ago

I corrected this earlier:

https://github.com/agermanidis/SnapchatBot/commit/e21e52c66d32c6aa032acbd546307ab80a1794e1

N07070 commented 9 years ago

So how do I implement it ?

agermanidis commented 9 years ago

Have you tried running your code on the last commit? You shouldn't need to use guess_type, your issue might've been already fixed with https://github.com/agermanidis/SnapchatBot/commit/e21e52c66d32c6aa032acbd546307ab80a1794e1

N07070 commented 9 years ago

Okay, it's fixed ! :smile: