示例#1
0
    def getvideo(self):
        if not self.values:
            return 'Get what?'

        url = self.values[0]
        result = savevideo(url, VIDS + '%(title)s.%(ext)s')

        return 'Saved %s' % result
示例#2
0
    def getvideo(self):
        if not self.values:
            return 'Get what?'

        url = self.values[0]
        result = savevideo(url, self.cx.settings.media.videos + '/%(title)s.%(ext)s')

        return 'Saved %s' % result
示例#3
0
    def getvideo(self):
        if not self.values:
            return 'Get what?'

        url = self.values[0]
        result = savevideo(url, VIDS + '%(title)s.%(ext)s')

        return 'Saved %s' % result
示例#4
0
    def gif(self):

        # allow for varied input
        # try not to crash, yah?

        if not self.values or len(self.values) != 3:
            return 'Please enter start end filename|youtubeurl.'

        start, finis, target = tuple(self.values)
        timeformat = re.compile('^\d+,\d{2}\.\d{1,2}$')

        # This could all be sorted out better
        if start.find(',') == -1:
            start = '0,' + start

        if finis.find(',') == -1:
            finis = '0,' + finis

        if start.find('.') == -1:
            start = start + '.0'

        if finis.find('.') == -1:
            finis = finis + '.0'

        if not timeformat.match(start) or not timeformat.match(finis):
            self.chat('Times must be in the format 12,34.56 (^\d+,\d{2}\.\d{1,2}$)')
            return

        start_m, start_s = tuple(start.split(','))
        start = (int(start_m), float(start_s))
        finis_m, finis_s = tuple(finis.split(','))
        finis = (int(finis_m), float(finis_s))

        note = 'New gif @ %s'

        youtube = False
        if target.find('www.youtube.com') != -1:
            youtube = True
            target = savevideo(target, self.cx.settings.media.videos + '/%(title)s.%(ext)s')
            target = target.split('/').pop()

        vidpath = '%s/%s' % (self.cx.settings.media.videos, target)

        if not os.path.isfile(vidpath):
            return 'Video file not found'

        filename = '%s%s.gif' % (time.time(), target)
        gifpath = 'server%s%s' % (self.cx.settings.media.gifs, filename)

        try:
            VideoFileClip(vidpath).subclip(start,finis).resize(0.5).to_gif(gifpath)
        except Exception as e:
            return 'Error: %s' % str(e)

        # Because of the above mentioned hack to
        # moviepy, this has to be done to clear
        # the ffmpeg processes. Don't run mongo
        # on dedicated ffmpeg servers.
        p = subprocess.Popen(['ps', '-A'], stdout=subprocess.PIPE)
        out, err = p.communicate()
        for line in out.splitlines():
            if 'ffmpeg' in line:
                pid = int(line.split(None, 1)[0])
                os.kill(pid, signal.SIGKILL)

        # I've noticed some people comment lines
        # like this. But, c'mon, it's so freaking
        # what this does and why. Maybe in C it'd
        # need some notes, but python is halfway
        # to pseudocode as it is. I'm not explaining
        # this. Seriously.
        #
        # That said, there's a minor bug that if
        # you've used getvideo to pull a youtube
        # video, then gif it with a link to the
        # original, it will nix the previously
        # downloaded video. It's a little weird to
        # deal with that with the threading and all,
        # and I don't care that much.
        if youtube:
            os.remove(vidpath)

        return '%s%s%s' % (self.cx.settings.website.url, self.cx.settings.website.gifs, filename)