Exemple #1
0
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None
    try:
        if arch in ('armv6l', 'armv7l'):
            run_omxplayer = omxplayer(file, info=True, _err_to_out=True)
            for line in run_omxplayer.split('\n'):
                if 'Duration' in line:
                    match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
                    if match:
                        time_input = match.group()
                        time_split = time_input.split(':')
                        hours = int(time_split[0])
                        minutes = int(time_split[1])
                        seconds = float(time_split[2])
                        time = timedelta(hours=hours,
                                         minutes=minutes,
                                         seconds=seconds)
                    break
        else:
            run_mplayer = mplayer('-identify', '-frames', '0', '-nosound',
                                  file)
            for line in run_mplayer.split('\n'):
                if 'ID_LENGTH=' in line:
                    time = timedelta(
                        seconds=int(round(float(line.split('=')[1]))))
                    break
    except:
        pass

    return time
Exemple #2
0
def view_video(uri):

    ## For Raspberry Pi
    if arch == 'armv6l':
        logging.debug('Displaying video %s. Detected Raspberry Pi. Using omxplayer.' % uri)

        if asset_is_accessible(uri):
            run = omxplayer(uri, o=settings['audio_output'])
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))

        # Clean up after omxplayer
        omxplayer_logfile = path.join(getenv('HOME'), 'omxplayer.log')
        if path.isfile(omxplayer_logfile):
            remove(omxplayer_logfile)

    ## For x86
    elif arch in ['x86_64', 'x86_32']:
        logging.debug('Displaying video %s. Detected x86. Using mplayer.' % uri)

        if asset_is_accessible(uri):
            run = mplayer(uri, fs=True, nosound=True)
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))
Exemple #3
0
def get_video_duration(file):
    """
    Returns the duration of a video file in timedelta.
    """
    time = None
    try:
        if arch in ('armv6l', 'armv7l'):
            run_omxplayer = omxplayer(file, info=True, _err_to_out=True)
            for line in run_omxplayer.split('\n'):
                if 'Duration' in line:
                    match = re.search(r'[0-9]+:[0-9]+:[0-9]+\.[0-9]+', line)
                    if match:
                        time_input = match.group()
                        time_split = time_input.split(':')
                        hours = int(time_split[0])
                        minutes = int(time_split[1])
                        seconds = float(time_split[2])
                        time = timedelta(hours=hours, minutes=minutes, seconds=seconds)
                    break
        else:
            run_mplayer = mplayer('-identify', '-frames', '0', '-nosound', file)
            for line in run_mplayer.split('\n'):
                if 'ID_LENGTH=' in line:
                    time = timedelta(seconds=int(round(float(line.split('=')[1]))))
                    break
    except:
        pass

    return time
Exemple #4
0
def url_fails(url):
    """
    If it is streaming
    """
    if urlparse(url).scheme in ('rtsp', 'rtmp'):
        if arch in ('armv6l', 'armv7l'):
            run_omxplayer = omxplayer(url, info=True, _err_to_out=True, _ok_code=[0, 1])
            for line in run_omxplayer.split('\n'):
                if 'Input #0' in line:
                    return False
            return True
        else:
            run_mplayer = mplayer('-identify', '-frames', '0', '-nosound', url)
            for line in run_mplayer.split('\n'):
                if 'Clip info:' in line:
                    return False
            return True

    """
    Try HEAD and GET for URL availability check.
    """

    # Use Certifi module and set to True as default so users stop seeing InsecureRequestWarning in logs
    if settings['verify_ssl']:
        verify = certifi.where()
    else:
        verify = True

    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux armv7l) AppleWebKit/538.15 (KHTML, like Gecko) Version/8.0 Safari/538.15'
    }
    try:
        if not validate_url(url):
            return False

        if requests.head(
            url,
            allow_redirects=True,
            headers=headers,
            timeout=10,
            verify=verify
        ).status_code in HTTP_OK:
            return False

        if requests.get(
            url,
            allow_redirects=True,
            headers=headers,
            timeout=10,
            verify=verify
        ).status_code in HTTP_OK:
            return False

    except (requests.ConnectionError, requests.exceptions.Timeout):
        pass

    return True
Exemple #5
0
    def make_movie(self, imagepath, filename, mp4fps):

        #write x264 mp4
        tmpmov = "%s/movie.y4m" % imagepath

        sh.mplayer("mf://%s/*.png" % imagepath, "-mf", "fps=%d" % mp4fps,
                   "-vo", "yuv4mpeg:file=%s" % tmpmov, "-ao", "null",
                   "-nosound", "-noframedrop", "-benchmark", "-nolirc")

        sh.x264(
            "--output=%s" % filename,
            "%s" % tmpmov,
        )

        try:
            os.unlink(tmpmov)
            shutil.rmtree(self._tempdir)
        except OSError:
            pass
Exemple #6
0
def view_video(uri):
    logging.debug('Displaying video %s', uri)

    if arch == 'armv6l':
        run = sh.omxplayer(uri, o=settings['audio_output'], _bg=True)
    else:
        run = sh.mplayer(uri, '-nosound', _bg=True)

    browser_clear(force=True)
    run.wait()
Exemple #7
0
    def make_movie(self,imagepath,filename,mp4fps):

        #write x264 mp4
        tmpmov = "%s/movie.y4m" % imagepath

        sh.mplayer("mf://%s/*.png" % imagepath,
                   "-mf", "fps=%d" % mp4fps,
                   "-vo", "yuv4mpeg:file=%s" % tmpmov,
                   "-ao", "null",
                   "-nosound", "-noframedrop", "-benchmark", "-nolirc"
        )

        sh.x264("--output=%s" % filename,
                "%s" % tmpmov,
        )


        try:
            os.unlink(tmpmov)
            shutil.rmtree(self._tempdir)
        except OSError:
            pass
def make_movie(wide,zoom,bag,imagepath,filename,rfps,mp4fps):
    #composite png frames
    courtship_compositor.composite_fmfs(wide,zoom,bag,imagepath,rfps)

    #write x264 mp4
    tmpmov = "%s/movie.y4m" % imagepath

    sh.mplayer("mf://%s/*.png" % imagepath,
               "-mf", "fps=%d" % mp4fps,
               "-vo", "yuv4mpeg:file=%s" % tmpmov,
               "-ao", "null",
               "-nosound", "-noframedrop", "-benchmark", "-nolirc"
    )

    sh.x264("--output=%s" % filename,
            "%s" % tmpmov,
    )

    try:
        os.unlink(tmpmov)
    except OSError:
        pass
Exemple #9
0
def main(url):
    opts, args = parse_args()

    if "youtube.com" not in url:
        sh.mplayer("/usr/share/sounds/freedesktop/stereo/message.oga")
        return "%r is not a valid youtube url." % url

    notify("Grabbing %r" % url)
    prefix = os.path.expanduser("~/Music/youtube")

    if not os.path.exists(prefix):
        os.makedirs(prefix)

    location = "%s/%%(stitle)s.%%(ext)s" % prefix
    output = sh.youtube_dl(
        url,
        extract_audio=True,
        audio_format="mp3",
        output=location,
    )
    # Just report on the last line of text..
    output = unicode(output).strip().split('\n')[-1]
    sh.mplayer("/usr/share/sounds/freedesktop/stereo/complete.oga")
    return output
Exemple #10
0
def view_video(uri):

    ## For Raspberry Pi
    if arch == 'armv6l':
        logging.debug('Displaying video %s. Detected Raspberry Pi. Using omxplayer.' % uri)

        if asset_is_accessible(uri):
            run = omxplayer(uri, o=settings['audio_output'], _bg=True)
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        # Wait until omxplayer is starting before clearing the browser. This minimises delay between
        # web and image content. Omxplayer will run on top of the browser so the delay in clearing
        # won't be visible. This minimises delay between web and video.
        browser_clear()
        run.wait()

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))

        # Clean up after omxplayer
        omxplayer_logfile = path.join(getenv('HOME'), 'omxplayer.log')
        if path.isfile(omxplayer_logfile):
            remove(omxplayer_logfile)

    ## For x86
    elif arch in ['x86_64', 'x86_32']:
        logging.debug('Displaying video %s. Detected x86. Using mplayer.' % uri)

        if asset_is_accessible(uri):
            run = mplayer(uri, fs=True, nosound=True, _bg=True)
        else:
            logging.debug('Content is unaccessible. Skipping...')
            return

        browser_clear()
        run.wait()

        if run.exit_code != 0:
            logging.debug("Unclean exit: " + str(run))
Exemple #11
0
    def run(self):
        """Thread target."""
        self.stopped = False
        current_url = None
        current_title = None

        q, state = Radio.state()
        db.update({"station_title": None}, q.type == "radio")

        while not self.stopped:
            # Restart mplayer whenever station changes
            q, state = Radio.state()
            title = state.get("station_title")

            q_station = db.search(q.name == state.get("station_playing"))
            url = q_station[0]["url"] if len(q_station) > 0 else None

            if current_url != url:
                self.logger.debug("Station changed")
                try:
                    self.stop()
                    self.player = None
                    self.stopped = False  # keep this loop running
                except Exception as e:
                    self.logger.debug("Player is already stopped {}".format(e))

                if url is not None:
                    self.logger.info("Playing {}".format(url))
                    self.player = mplayer(url,
                                          _bg=True,
                                          _out=self.interact,
                                          _ok_code=[0, 1])

                current_url = url

            elif current_title != title:
                current_title = title
                self.logger.info("Title is {}".format(current_title))

            sleep(1)
def playVideo():
    if(os.path.exists(downloadpath) == False):
        sh.mkdir('-p',downloadpath)
        progressvar.set("Creating Directory:\n{0}".format(downloadpath))
        root.update_idletasks()

    hidlpath = "{0}/{1}.{2}".format(downloadpath, hires.title.replace('/','_').encode("ascii","ignore"), hires.extension)
    lodlpath = "{0}/{1}.{2}".format(downloadpath, lores.title.replace('/','_').encode("ascii","ignore"), lores.extension)

    if(os.path.exists(hidlpath)):
        # play the hires video with mplayer
        sh.mplayer('-really-quiet',hidlpath, _bg=True)
    elif(os.path.exists(lodlpath)):
        # play the lores video with mplayer
        sh.mplayer('-really-quiet',lodlpath, _bg=True)
    elif(os.path.exists("{0}.temp".format(hidlpath))):
        # play if there is a hi res 'temp' file
        sh.mplayer('-really-quiet',"{0}.temp".format(hidlpath), _bg=True)
    elif(os.path.exists("{0}.temp".format(lodlpath))):
        # play if there is a hi res 'temp' file
        sh.mplayer('-really-quiet',"{0}.temp".format(lodlpath), _bg=True)
    else:
        progressvar.set("Video does not exist!")
        root.update_idletasks()
Exemple #13
0
def mplayer():
    sh.cd(IMG_PATH)
    while True:
        sh.rm('-f', glob.glob("[0-9]*.jpg"))
        sh.mplayer("tv:/%s" % DEVICE, "-vo", "jpeg:quality=100", '-vf', 'scale=320:240', '-fps', '2')
Exemple #14
0
 def create_proc(self, queryStatus):
     self.in_out_obj = MPlayerInteractiveObj(queryStatus)
     ##self.proc = sh.mplayer("-slave", target, "2>/dev/null", _bg = True, _in = self.in_out_obj, _out = self.in_out_obj)
     ##self.proc = sh.mplayer("-slave", "-nolirc", "-quiet","-really-quiet",  "-msglevel statusline=6", "-msglevel global=6", "-idle", "-input", "file=%s" % self.in_out_obj.get_fifo(), "2>/dev/null", _bg = True, _out = self.in_out_obj)
     self.proc = sh.mplayer("-slave", "-nolirc", "-quiet", "-idle", "-input", "file=%s" % self.in_out_obj.get_fifo(), "2>/dev/null", _bg = True, _out = self.in_out_obj)
     return self.proc