dontpanic.py 1.93 KB
Newer Older
prx's avatar
prx committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
#!/usr/bin/env python
# -*- coding: utf-8 -*-


"""
Auteur :      thuban <thuban@yeuxdelibad.net>
licence :     MIT

Description :
    Just watch your favorite show and keep track of them.
"""

import getpass
import sys
import os
from argparse import ArgumentParser

from dontpanic.ui import *
logger = logging.getLogger(__name__)



if __name__ == '__main__':
    parser = ArgumentParser(prog=progname, description=_("Dontpanic is a python app to look for any movie or"
                                                         " serie and watch them in streaming. It looks like popcorntime"
                                                         ", but doesn't depend of a centralized api."))

    parser.add_argument("-v", "--verbose", action="count", default=0, help=_("Increase output verbosity"))
    parser.add_argument("--version", action="version", version=progversion, help=_("Print version"))
    parser.add_argument("magnet", nargs='?', action="store", default="", help=_("Stream a magnet link"))

    args = parser.parse_args()
    setup_logging(args.verbose)

    os.chdir(os.path.dirname(os.path.abspath(__file__)))
    prepconfig()

    port = lock()

    # In case if the login contains weird characters
    if sys.platform == 'win32' and sys.version_info < (3, 0):
        me = getpass.getuser().decode('utf-8', errors='ignore')
    else:
        me = getpass.getuser()

    # a magnet link is passed as argument
    mgt = ""
    if args.magnet.startswith("magnet:"):
        mgt = quoteurl(args.magnet)

    if not port:   # already running
        with open(lock_file, 'r') as l:
            port = l.read().strip()
        if mgt != "":
            webbrowser.open("http://localhost:{}/stream/dontpanic/{}/0".format(port, mgt))
        else:
            webbrowser.open("http://localhost:{}".format(port))
    else:
        myapp = DontPanic('localhost', port, me, magnet=mgt)
        myapp.run()

# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4