Beispiel #1
0
def daemonize(args, callback):
    with DaemonContext():
        from touchandgo.logger import log_set_up
        log_set_up(True)
        log = logging.getLogger('touchandgo.daemon')
        log.info("running daemon")
        create_process = False
        lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
                    args.sea_ep[1], args.port)
        if lock.is_locked():
            log.debug("lock active")
            lock_pid = lock.get_pid()
            if not lock.is_same_file(args.name, args.sea_ep[0],
                                     args.sea_ep[1]) \
                    or not is_process_running(lock_pid):
                try:
                    log.debug("killing process %s" % lock_pid)
                    os.kill(lock_pid, signal.SIGQUIT)
                except OSError:
                    pass
                except TypeError:
                    pass
                lock.break_lock()
                create_process = True
        else:
            create_process = True

        if create_process:
            log.debug("creating proccess")
            lock.acquire()
            callback()
            lock.release()
        else:
            log.debug("same daemon process")
Beispiel #2
0
def daemonize(args, callback):
    with DaemonContext():
        from touchandgo.logger import log_set_up
        log_set_up(True)
        log = logging.getLogger('touchandgo.daemon')
        log.info("running daemon")
        create_process = False
        lock = Lock(LOCKFILE, os.getpid(), args.name, args.sea_ep[0],
                    args.sea_ep[1], args.port)
        if lock.is_locked():
            log.debug("lock active")
            lock_pid = lock.get_pid()
            if not lock.is_same_file(args.name, args.sea_ep[0],
                                     args.sea_ep[1]) \
                    or not is_process_running(lock_pid):
                try:
                    log.debug("killing process %s" % lock_pid)
                    os.kill(lock_pid, signal.SIGQUIT)
                except OSError:
                    pass
                except TypeError:
                    pass
                lock.break_lock()
                create_process = True
        else:
            create_process = True

        if create_process:
            log.debug("creating proccess")
            lock.acquire()
            callback()
            lock.release()
        else:
            log.debug("same daemon process")
Beispiel #3
0
def main():
    parser = argparse.ArgumentParser(
        description="Command line tool to watch torrents")
    parser.add_argument("name", help="The name of the series or movie")

    parser.add_argument("season_number", default=None, nargs="?", type=int,
                        help="Season number")
    parser.add_argument("episode_number", default=None, nargs="?", type=int,
                        help="Episode number")
    parser.add_argument("--sub", nargs='?', default=None,
                        help="Subtitle language")
    parser.add_argument("--serve", action="store_true",
                        help="Do not run VLC")
    parser.add_argument("--quality", nargs='?', default=None,
                        help="quality of the video [normal|hd|fullhd]")
    parser.add_argument("--daemon", action="store_true",
                        help="Daemonize the process"),
    parser.add_argument("--port", "-p", default="8888",
                        help="The port where the stream will be served")
    parser.add_argument("--verbose", action="store_true", default=None,
                        help="Show _all_ the logs")
    parser.add_argument("--player", default='vlc',
                        help="Player to use. vlc|omxplayer|chromecast")
    parser.add_argument("--search", default=None,
                        help="search lib to use (only option right now is 'kat' for kickass torrents)")
    parser.add_argument("--nocache", action="store_false", default=True,
                        help="Search for the torrent again"),

    args = parser.parse_args()

    log_set_up(args.verbose)
    log.info("Starting touchandgo")
    log.debug("Running Python %s on %r", sys.version_info, sys.platform)
    log.debug("Libtorrent version: %s", libtorrent_version)

    try:
        if args.sub is not None:
            Language(args.sub)

        touchandgo = SearchAndStream(args.name, season=args.season_number,
                                     episode=args.episode_number,
                                     sub_lang=args.sub, serve=args.serve,
                                     quality=args.quality, port=args.port,
                                     player=args.player, search=args.search,
                                     use_cache=args.nocache)
        if args.daemon:
            def callback():
                touchandgo.serve = True
                touchandgo.watch()
            daemonize(args, callback)
        else:
            term = Terminal()
            with term.fullscreen():
                touchandgo.watch()
    except ValueError as e:
        print(e)
Beispiel #4
0
def main():
    parser = argparse.ArgumentParser(
        description="Command line tool to watch torrents")
    parser.add_argument("name", help="The name of the series or movie")

    parser.add_argument("season_number", default=None, nargs="?", type=int,
                        help="Season number")
    parser.add_argument("episode_number", default=None, nargs="?", type=int,
                        help="Episode number")
    parser.add_argument("--sub", nargs='?', default=None,
                        help="Subtitle language")
    parser.add_argument("--serve", action="store_true",
                        help="Do not run VLC")
    parser.add_argument("--quality", nargs='?', default=None,
                        help="quality of the video [normal|hd|fullhd]")
    parser.add_argument("--daemon", action="store_true",
                        help="Daemonize the process"),
    parser.add_argument("--port", "-p", default="8888",
                        help="The port where the stream will be served")
    parser.add_argument("--verbose", action="store_true", default=None,
                        help="Show _all_ the logs")
    parser.add_argument("--player", default='vlc',
                        help="Player to use. vlc|omxplayer|chromecast")
    parser.add_argument("--search", default=None,
                        help="search lib to use (only option right now is 'kat' for kickass torrents)")
    parser.add_argument("--nocache", action="store_false", default=True,
                        help="Search for the torrent again"),

    args = parser.parse_args()

    log_set_up(args.verbose)
    log.info("Starting touchandgo")
    log.debug("Running Python %s on %r", sys.version_info, sys.platform)
    log.debug("Libtorrent version: %s", libtorrent_version)

    try:
        if args.sub is not None:
            Language(args.sub)

        touchandgo = SearchAndStream(args.name, season=args.season_number,
                                     episode=args.episode_number,
                                     sub_lang=args.sub, serve=args.serve,
                                     quality=args.quality, port=args.port,
                                     player=args.player, search=args.search,
                                     use_cache=args.nocache)
        if args.daemon:
            def callback():
                touchandgo.serve = True
                touchandgo.watch()
            daemonize(args, callback)
        else:
            touchandgo.watch()
    except ValueError, e:
        print e
Beispiel #5
0
def main():
    log_set_up()
    parser = argparse.ArgumentParser()

    parser.add_argument("magnet", nargs="?", default=None)
    parser.add_argument("--sub", nargs="?", default=None)
    parser.add_argument("--serve", action="store_true")
    parser.add_argument("--port", "-p", default="8888")

    args = parser.parse_args()

    manager = DownloadManager(args.magnet, port=args.port, serve=args.serve, sub_lang=args.sub)
    manager.start()
Beispiel #6
0
def main():
    parser = argparse.ArgumentParser(
        description="Command line tool to watch torrents")
    parser.add_argument("name", help="The name of the series or movie")

    parser.add_argument("season_number", default=None, nargs="?", type=int,
                        help="Season number")
    parser.add_argument("episode_number", default=None, nargs="?", type=int,
                        help="Episode number")
    parser.add_argument("--sub", nargs='?', default=None,
                        help="Subtitle language")
    parser.add_argument("--serve", action="store_true",
                        help="Do not run VLC")
    parser.add_argument("--quality", nargs='?', default=None,
                        help="quality of the video [normal|hd|fullhd]")
    parser.add_argument("--daemon", action="store_true",
                        help="Daemonize the process"),
    parser.add_argument("--port", "-p", default="8888",
                        help="The port where the stream will be served")
    parser.add_argument("--season", action="store_true",
                        help="Stream next episode when this episode finishes")
    parser.add_argument("--verbose", action="store_true", default=None,
                        help="Show _all_ the logs")
    parser.add_argument("--player", default='vlc',
                        help="Player to use. vlc|omxplayer")

    args = parser.parse_args()

    log_set_up(args.verbose)
    log.info("Starting touchandgo")
    log.debug("Running Python %s on %r", sys.version_info, sys.platform)
    log.debug("Libtorrent version: %s", libtorrent_version)

    touchandgo = SearchAndStream(args.name, season=args.season_number,
                                 episode=args.episode_number,
                                 sub_lang=args.sub, serve=args.serve,
                                 quality=args.quality, port=args.port,
                                 player=args.player)
    if args.daemon:
        def callback():
            touchandgo.serve = True
            touchandgo.watch()
        daemonize(args, callback)
    else:
        play_next_episode = True
        while play_next_episode:
            touchandgo.watch()
            touchandgo.episode += 1
            play_next_episode = args.season
Beispiel #7
0
def main():
    log_set_up()
    parser = argparse.ArgumentParser()

    parser.add_argument("magnet", nargs='?', default=None)
    parser.add_argument("--sub", nargs='?', default=None)
    parser.add_argument("--serve", action="store_true")
    parser.add_argument("--port", "-p", default="8888")
    parser.add_argument("--index", default=None, type=int)

    args = parser.parse_args()

    manager = DownloadManager(args.magnet, port=args.port, serve=args.serve,
                              sub_lang=args.sub, index_file=args.index)
    manager.start()
Beispiel #8
0
def serve(py_exec=None):
    log_set_up(DEBUG)
    parser = argparse.ArgumentParser()
    parser.add_argument("--python", default="python2")
    args = parser.parse_args()

    py_exec = args.python

    app = Flask("touchandgo")
    template_path = join(dirname(__file__), "templates")
    app.jinja_loader = FileSystemLoader(template_path)

    def get_torrent(name, season=None, episode=None):
        interface = get_interface()
        settings = get_settings()
        path = abspath(__file__)
        dir_path = dirname(path)
        exec_ = join(dir_path, "..", "main.py")
        command = '%s %s \"%s\" ' % (py_exec, exec_, name)
        if season is not None:
            command += "%s %s " % (season, episode)
        lock = Lock(LOCK_FILE)
        if lock.is_same_file(name, season, episode) and \
                is_process_running(lock.get_pid()):
            data = lock._get_file_data()
            port = data[4]
        else:
            if settings.force_ts_proxy_port:
                port = settings.ts_proxy_port
            else:
                port = get_free_port()
            command += "--daemon --port %s " % port
            log.info(command)
            process = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
            sleep(1)

        redirect_url = "http://%s:%s" % (interface, port)
        serving = False
        while not serving:
            try:
                req = requests.get("%s/status" % redirect_url)
                serving = True
            except requests.ConnectionError, e:
                sleep(1)
        log.info("redirecting to %s" % redirect_url)
        return redirect(redirect_url)
Beispiel #9
0
def serve(py_exec=None):
    log_set_up(True)
    parser = argparse.ArgumentParser()
    parser.add_argument("--python", default="python")
    args = parser.parse_args()

    py_exec = args.python

    app = Flask("touchandgo")
    template_path = join(dirname(__file__), "templates")
    app.jinja_loader = FileSystemLoader(template_path)

    def get_torrent(name, season=None, episode=None):
        interface = get_interface()
        path = abspath(__file__)
        dir_path = dirname(path)
        exec_ = join(dir_path, "__init__.py")
        command = '%s %s \"%s\" ' % (py_exec, exec_, name)
        if season is not None:
            command += "%s %s " % (season, episode)
        lock = Lock(LOCKFILE)
        if lock.is_same_file(name, season, episode) and \
                is_process_running(lock.get_pid()):
            data = lock._get_file_data()
            port = data[4]
        else:
            port = get_free_port()
            command += "--daemon --port %s " % port
            log.debug(command)
            process = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
            sleep(1)

        redirect_url = "http://%s:%s" % (interface, port)
        serving = False
        while not serving:
            try:
                req = requests.get("%s/status" % redirect_url)
                serving = True
            except requests.ConnectionError, e:
                sleep(1)
        log.info("redirecting to %s" % redirect_url)
        return redirect(redirect_url)
Beispiel #10
0
def daemonize(args, callback):
    with DaemonContext():
        from touchandgo.logger import log_set_up
        log_set_up(True)
        log = logging.getLogger('touchandgo.daemon')
        try:
            log.info("running daemon")
            create_process = False
            pid = os.getpid()
            log.debug("%s, %s, %s", LOCK_FILE, pid, args)
            lock = Lock(LOCK_FILE, pid, args.name, args.season_number,
                        args.episode_number, args.port)
            if lock.is_locked():
                log.debug("lock active")
                lock_pid = lock.get_pid()
                is_same = lock.is_same_file(args.name, args.season_number,
                                            args.episode_number)
                if (not is_same or not is_process_running(lock_pid)):
                    try:
                        log.debug("killing process %s" % lock_pid)
                        os.kill(lock_pid, signal.SIGQUIT)
                    except OSError:
                        pass
                    except TypeError:
                        pass
                    lock.break_lock()
                    create_process = True
            else:
                log.debug("Will create process")
                create_process = True

            if create_process:
                log.debug("creating proccess")
                lock.acquire()
                callback()
                lock.release()
            else:
                log.debug("same daemon process")
        except Exception as e:
            log.error(e)
Beispiel #11
0
def serve(py_exec=None):
    log_set_up(True)
    parser = argparse.ArgumentParser()
    parser.add_argument("--python", default="python")
    args = parser.parse_args()

    py_exec = args.python

    app = Flask("touchandgo")
    template_path = join(dirname(__file__), "templates")
    app.jinja_loader = FileSystemLoader(template_path)

    @app.route("/favicon.ico")
    def favicon(self):
        return ""

    @app.route("/<name>")
    @app.route("/<name>/<season>/<episode>")
    def redirect_to(name, season=None, episode=None):
        log.info("Requesting %s %s %s", name, season, episode)
        interface = get_interface()
        path = abspath(__file__)
        dir_path = dirname(path)
        exec_ = join(dir_path, "__init__.py")

        port = "8890"#get_free_port()

        command = '%s %s \"%s\" ' % (py_exec, exec_, name)
        if season is not None:
            command += "%s %s " % (season, episode)
        command += "--daemon --port %s " % port
        log.debug(command)
        process = Popen(command, shell=True, stdout=PIPE, stderr=STDOUT)
        sleep(1)
        while get_lock_diff() < 30:
            sleep(1)
        redirect_url = "http://%s:%s" % (interface, port)
        log.info("redirecting to %s" % redirect_url)
        return redirect(redirect_url)

    @app.route("/l/<name>/<season>/<episode>")
    @app.route("/l/<name>/<season>/<episode>/")
    def list_(name, season, episode):
        url = "http://%s:5000/%s/%s" % (get_interface(), name, season)
        episode = int(episode)

        template = app.jinja_env.get_template("m3u.j2")
        ret = template.render(episodes=range(episode, episode + 10),
                              series=name, season=episode, url=url)
        return Response(response=ret, status=200,
                        mimetype="application/x-mpegurl",
                        content_type="application/x-mpegurl")

    @app.route("/kill")
    def kill_():
        lock = Lock(LOCKFILE)
        kill(lock.get_pid(), signal.SIGQUIT)
        return "OK"

    @app.route("/")
    def main():
        series = []
        keys = []
        items = History.many(sorted="-date,-season,-episode")
        for item in items:
            key = (item.name, item.season is not None)
            if key not in keys:
                series.append(item)
                keys.append(key)

        return render_template("main.html", items=series)


    set_config_dir()
    app.debug = True
    app.run(host="0.0.0.0")