Ejemplo n.º 1
0
    def setUp(self):
        self.errorFont = pygame.font.Font(None, 24)
        util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'title.png')]
        util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'name.png')]
        util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'server.png')]
        self.nameTxt = UI.TextInput(500, None, 46, 300, 350)
        self.serverTxt = UI.TextInput(500, None, 46, 300, 390)

        self.nameTxt.setText("player%d" % random.randint(10000, 99999))
        self.serverTxt.setText("localhost")
        
        self.connButton = UI.Button(util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'connect.png')],
                                    util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'connect_over.png')],
                                    660, 430)
        self.connButton.setOnClick(self.doConnect)

        self.MAIN.eventManager.addHandler(self.nameTxt)
        self.MAIN.eventManager.addHandler(self.serverTxt)
        self.MAIN.eventManager.addHandler(self.connButton)
        
        self.MAIN.cam.addOverlay(self.nameTxt)
        self.MAIN.cam.addOverlay(self.serverTxt)
        self.MAIN.cam.addOverlay(self.connButton)
        self.MAIN.cam.addOverlay(self)
        
        if self.errorMessage != "":
            self.renderedErrorMsg = self.errorFont.render(self.errorMessage, True, (255,0,0))
        super(TitleScene, self).setUp()
Ejemplo n.º 2
0
    def setUp(self, onlineMode=True):
        # self.world = World.World(util.WORLDBOUNDS(), util.GRAVITY, True)
        self.world = World.World(util.GRAVITY, True)
        self.world.setCamera(self.MAIN.cam)
        if self.MAIN.client:
            self.world.setGameClient(self.MAIN.client)

        self.makeWorld()
        self.MAIN.cam.setStage(util.getFile(util.IMAGES, "STAGE", self.stage.stageFile))

        xbound = ((self.stage.MINX + 200), (self.stage.MAXX - 200))
        ybound = ((self.stage.MINY + 200), (self.stage.MAXY - 200))

        self.mainChar = Character.Character(self.world, True, self.MAIN.client.charId, 1, 1, xbound, ybound)
        self.mainChar.name = "person"
        if self.MAIN.client:
            self.mainChar.setPlayerId(self.MAIN.client.playerId)
        self.hud = hud.hud()
        self.mainChar.linkHud(self.hud)
        self.controller = Controller.Controller(self.mainChar)
        self.world.setMainCharacter(self.mainChar)

        self.MAIN.cam.addOverlay(self.hud)
        self.world.addActor(self.mainChar)

        if False:  # Set True, for debugging, dangerous
            self.MAIN.cam.addActor(self.stage.getSprites())

        self.MAIN.cam.setFocus(self.mainChar)
        self.MAIN.cam.setFocusPoint((util.CANVAS_WIDTH / 2, util.CANVAS_HEIGHT / 2))
        self.MAIN.cam.setBackground(
            util.getFile(util.IMAGES, "BG", "1.jpg"), self.stage.getWidth(), self.stage.getHeight()
        )

        self.MAIN.eventManager.addHandler(self.controller)

        self.world.addContactListener(self.mainChar.getCharContact())
        self.mainChar.spawn()
        if not self.pickupsRendered:
            np = []
            for pu in self.pickups:
                npu = (self.world,) + pu[1:]
                pus = Pickup.Pickup(*npu)
                self.world.addActor(pus)
                np.append(pus)
            self.pickups = np

        if not onlineMode:
            self.pu = Pickup.Pickup(self.world, 02, 0, 40.8616, 2.16167)
            self.world.addActor(self.pu)

        if onlineMode:
            self.getOtherPlayers()
            self.network = True
            Thread(target=self.networkLoop).start()

        super(GameScene, self).setUp()
Ejemplo n.º 3
0
 def draw(self, surface, offset=(0,0)):
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'title.png')], (0,0))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'name.png')], (100,350))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "TITLE", 'server.png')], (100,390))
     if self.loading:
         if time.time() > self.loadingAnim:
             self.dots += 1
             if self.dots > 3:
                 self.dots = 0
             txt = "Loading" + "."*self.dots
             self.renderedErrorMsg = self.errorFont.render(txt, True, (255,0,0))
             self.loadingAnim = time.time() + .25
     if self.renderedErrorMsg != None:
         surface.blit(self.renderedErrorMsg, (100, 300))
Ejemplo n.º 4
0
 def draw(self, surface, offset):
     pygame.draw.rect(surface,(0,0,0),self.border,1)
     pygame.draw.rect(surface,(255,255,255),self.fill,0)
     
     surface.blit(self.title, (self.x+2,self.y+3))
     pygame.draw.line(surface, (0,0,0), (self.x,self.y+16), (self.x+self.width-1,self.y+16))
     pygame.draw.line(surface, (0,0,0), (self.x,self.y+19), (self.x+self.width-1,self.y+19))
     
     cx,cy = self.createRect.left,self.createRect.top
     if self.highlight:
         surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'create_over.png')], (self.x+cx, self.y+cy))
     else:
         surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'create.png')], (self.x+cx, self.y+cy))
         
     self.roomNameTxt.draw(surface,offset)
Ejemplo n.º 5
0
    def setUp(self):
        self.chatData = []
        util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'title.png')]
        util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'chat_back.png')]
        util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'users_back.png')]
        util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'rooms_back.png')]
        
        self.roomList = UI.List(766,490, None, 20,0,45)
        
        self.userList = UI.List(768,768-46, None, 20,768,45)

        self.chatList = UI.List(766,232, None, 20, 0, 45+490+2)
        self.chatList.selectable(False)
        self.chatTxt = UI.TextInput(766, None, 20, 0, 768-19)
        self.chatTxt.setEnterFunc(self.onTextEnter)
        self.createButton = UI.Button(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'create.png')],
                                    util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'create_over.png')],
                                    477, 5)
        self.createButton.setOnClick(self.createClick)
        self.joinButton = UI.Button(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'join.png')],
                                    util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'join_over.png')],
                                    627, 5)
        self.joinButton.setOnClick(self.joinClick)
        self.MAIN.eventManager.addHandler(self.joinButton)
        self.MAIN.eventManager.addHandler(self.createButton)
        self.MAIN.eventManager.addHandler(self.roomList)
        self.MAIN.eventManager.addHandler(self.userList)
        self.MAIN.eventManager.addHandler(self.chatList)
        self.MAIN.eventManager.addHandler(self.chatTxt)
        

        self.MAIN.cam.addOverlay(self)
        self.MAIN.cam.addOverlay(self.joinButton)
        self.MAIN.cam.addOverlay(self.createButton)
        self.MAIN.cam.addOverlay(self.roomList)
        self.MAIN.cam.addOverlay(self.userList)
        self.MAIN.cam.addOverlay(self.chatList)
        self.MAIN.cam.addOverlay(self.chatTxt)

        self.updateRooms()
        self.updatePlayers()
        
        """
        self.MAIN.cam.addOverlay(self.chatTxt)
        self.MAIN.cam.addOverlay(self.createButton)
        self.MAIN.cam.addOverlay(self.joinButton)
        self.MAIN.cam.addOverlay(self)
        """
        super(LobbyScene, self).setUp()
Ejemplo n.º 6
0
    def setUp(self):
        self.chatData = []
        util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'chat_back.png')]
        util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'users_back.png')]

        fontFile = os.path.join(util.IMAGES['HUD'], "def.ttf")
        self.roomFont = pygame.font.Font(fontFile, 30)
        self.roomF_Rendered = self.roomFont.render(self.getRoomName(self.MAIN.client.roomId, self.MAIN.client.roomName), False, (0, 0, 0))
        
        self.userList = UI.List(768,768-46, None, 20,768,45)

        self.chatList = UI.List(766,464, None, 20, 0, 45+490+2-232)
        self.chatList.selectable(False)
        self.chatTxt = UI.TextInput(766, None, 20, 0, 768-19)
        self.chatTxt.setEnterFunc(self.onTextEnter)
        self.startButton = UI.Button(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'start.png')],
                                    util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'start_over.png')],
                                    477, 5)
        self.startButton.setOnClick(self.onStart)
        self.leaveButton = UI.Button(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'leave.png')],
                                    util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'leave_over.png')],
                                    627, 5)
        self.leaveButton.setOnClick(self.onLeave)
        
        self.MAIN.eventManager.addHandler(self.startButton)
        self.MAIN.eventManager.addHandler(self.leaveButton)
        self.MAIN.eventManager.addHandler(self.userList)
        self.MAIN.eventManager.addHandler(self.chatList)
        self.MAIN.eventManager.addHandler(self.chatTxt)
        

        self.MAIN.cam.addOverlay(self)
        self.MAIN.cam.addOverlay(self.startButton)
        self.MAIN.cam.addOverlay(self.leaveButton)
        self.MAIN.cam.addOverlay(self.userList)
        self.MAIN.cam.addOverlay(self.chatList)
        self.MAIN.cam.addOverlay(self.chatTxt)

        self.updatePlayers()
        super(RoomScene, self).setUp()
Ejemplo n.º 7
0
def feedme(feed="", type=""):
    h = HTMLParser.HTMLParser()
    colour = [
        "black", "white", "gray", "blue", "teal", "fuchsia", "indigo",
        "turquoise", "cyan", "greenyellow", "lime", "green", "olive", "gold",
        "yello", "lavender", "pink", "magenta", "purple", "maroon",
        "chocolate", "orange", "red", "brown"
    ]
    parameters = util.parseParameters()

    #util.logError(str(parameters))

    try:
        mode = int(parameters["mode"])
    except:
        mode = None

    try:
        offsite = ast.literal_eval(parameters['extras'])
        #util.logError(str(offsite))
        if "site_xml" in offsite:
            feed = offsite['site_xml']
            type = "url"
    except:
        #not set, dont worry about it
        pass

    if mode == None or mode == 0:
        # if we get here list the sites found in the json file
        menu = []
        bits = util.getFile(feed, type)
        counter = 0

        if str(len(bits['sites'])) == "1" and 'folder' not in bits['sites']:
            mode = 1
            parameters['extras'] = str({"site": 0})
        else:
            try:
                folder = ast.literal_eval(parameters['extras'])
                folder = folder['folder']
                for site in bits['sites']:
                    try:
                        if site['folder'].lower() == folder.lower():
                            extras = {}
                            try:
                                extras['site_xml'] = offsite['site_xml']
                            except:
                                pass
                            extras['site'] = counter
                            menu.append({
                                "title": site['name'],
                                "url": site['name'],
                                "mode": "1",
                                "poster": site['poster'],
                                "icon": site['poster'],
                                "fanart": site['fanart'],
                                "type": ADDON_TYPE,
                                "plot": "",
                                "isFolder": True,
                                "extras": extras
                            })

                    except:
                        # site not in a folder
                        pass
                    counter = counter + 1
            except:
                if "folders" in bits:
                    for site in bits['folders']:
                        extras = {}
                        try:
                            extras['site_xml'] = offsite['site_xml']
                        except:
                            pass
                        extras['site'] = counter
                        folder_extras = {}
                        folder_extras['folder'] = site['name']
                        if "url" in site:
                            folder_extras['site_xml'] = site['url']
                            del (folder_extras['folder'])
                        menu.append({
                            "title": site['name'],
                            "url": site['name'],
                            "mode": "0",
                            "poster": site['poster'],
                            "icon": site['poster'],
                            "fanart": site['fanart'],
                            "type": ADDON_TYPE,
                            "plot": "",
                            "isFolder": True,
                            "extras": folder_extras
                        })
                for site in bits['sites']:
                    if "folder" not in site:
                        extras = {}
                        try:
                            extras['site_xml'] = offsite['site_xml']
                        except:
                            pass
                        extras['site'] = counter
                        menu.append({
                            "title": site['name'],
                            "url": site['name'],
                            "mode": "1",
                            "poster": site['poster'],
                            "icon": site['poster'],
                            "fanart": site['fanart'],
                            "type": ADDON_TYPE,
                            "plot": "",
                            "isFolder": True,
                            "extras": extras
                        })
                    counter = counter + 1
            util.addMenuItems(menu)
    if mode == 1:
        # first level within a site, show Latest, Search and any Tags within the specified site
        menu = []
        extras = ast.literal_eval(parameters['extras'])

        try:
            extras['site_xml'] = offsite['site_xml']
        except:
            pass

        bits = util.getFile(feed, type)
        site = bits['sites'][extras['site']]

        if "search_url" not in site and "tags" not in site and len(
                site['items']) == 1:
            mode = 2
            for item in site['items']:
                parameters['url'] = site['items'][item][0]['site_url']
                break

        else:
            for item in site['items'].iterkeys():
                if item.lower() != "search":
                    try:
                        poster = parameters['poster']
                    except:
                        try:
                            poster = site['items'][item][0]['folder_poster']
                            if "http" not in poster and "https" not in poster:
                                poster = os.path.join(HOME, '', poster)
                        except:
                            poster = ""
                    try:
                        fanart = parameters['fanart']
                    except:
                        try:
                            fanart = site['items'][item][0]['folder_fanart']
                            if "http" not in fanart and "https" not in fanart:
                                fanart = os.path.join(HOME, '', fanart)
                        except:
                            fanart = ""
                    extras['level'] = item

                    menu.append({
                        "title":
                        item,
                        "url":
                        urllib.quote_plus(site['items'][item][0]['site_url']),
                        "mode":
                        "2",
                        "poster":
                        poster,
                        "icon":
                        poster,
                        "fanart":
                        fanart,
                        "type":
                        ADDON_TYPE,
                        "plot":
                        "",
                        "isFolder":
                        True,
                        "extras":
                        str(extras)
                    })

            try:
                counter = 0
                for tag in site['tags']:
                    try:
                        poster = parameters['poster']
                    except:
                        poster = ""

                    try:
                        fanart = parameters['fanart']
                    except:
                        fanart = ""
                    extras['tag'] = counter
                    menu.append({
                        "title": tag['name'],
                        "url": tag['url'],
                        "mode": "4",
                        "poster": poster,
                        "icon": poster,
                        "fanart": fanart,
                        "type": ADDON_TYPE,
                        "plot": "",
                        "isFolder": True,
                        "extras": str(extras)
                    })
                    counter = counter + 1
            except:
                pass
            if "search_url" in site:
                try:
                    poster = parameters['poster']
                except:
                    poster = ""

                try:
                    fanart = parameters['fanart']
                except:
                    fanart = ""
                menu.append({
                    "title": "Search",
                    "url": "",
                    "mode": "3",
                    "poster": poster,
                    "icon": poster,
                    "fanart": fanart,
                    "type": ADDON_TYPE,
                    "plot": "",
                    "isFolder": True,
                    "extras": str(extras)
                })
            util.addMenuItems(menu)
    if mode == 2:
        # load the first level of relevant video information
        menu = []
        extras = ast.literal_eval(parameters['extras'])

        try:
            extras['site_xml'] = offsite['site_xml']
        except:
            pass

        bits = util.getFile(feed, type)
        site = bits['sites'][extras['site']]

        if 'pos' in extras:
            pos = extras['pos']
        else:
            pos = 0

        if 'level' in extras:
            level = extras['level']
        else:
            for item in site['items']:
                level = item
                break

        if len(site['items'][level]) > pos + 1:
            # another level is needed
            extras['pos'] = pos + 1
            newMode = "2"
            isFolder = True
        else:
            # on a level where next move is to check for sources
            try:
                if site['items'][level][pos]['play_media'] == "multiple":
                    newMode = "113"
                    isFolder = True
                else:
                    newMode = "111"  # find source
                    isFolder = False
            except:
                # default to play first found
                newMode = "111"  # find source
                isFolder = False

        #util.alert(newMode)
        page = util.get(h.unescape(parameters['url']))
        next = page
        """if parameters['name']=="Next Page >":
            util.logError(str(next))"""

        try:
            if site['items'][level][pos]['global'] != "":
                regex = util.prepare(site['items'][level][pos]['global'])
                matches = re.findall(regex, page)
                if matches:
                    page = matches[0]
        except:
            pass

        regex = util.prepare(site['items'][level][pos]['pattern'])
        matches = re.findall(regex, page)
        if matches:
            counter = 0
            for match in matches:
                try:
                    title = h.unescape(
                        util.replaceParts(
                            site['items'][level][pos]['name'],
                            matches[counter]).replace('\n', '').replace(
                                '\t', '').replace("\\", "").lstrip())
                except:
                    title = ""
                #try:
                #    util.alert(site['items'][level][pos]['url'])
                url = urllib.quote_plus(
                    util.replaceParts(site['items'][level][pos]['url'],
                                      matches[counter]))
                #    util.alert(">>"+url)
                #except:
                #    url=""
                try:
                    poster = util.replaceParts(
                        site['items'][level][pos]['poster'],
                        matches[counter]).encode('utf-8')
                except:
                    poster = ""
                try:
                    fanart = util.replaceParts(
                        site['items'][level][pos]['fanart'],
                        matches[counter]).encode('utf-8')
                except:
                    fanart = ""
                try:
                    plot = util.replaceParts(site['items'][level][pos]['plot'],
                                             matches[counter]).encode('utf-8')
                except:
                    plot = ""

                if isFolder:
                    menu.append({
                        "title": title,
                        "url": url,
                        "mode": newMode,
                        "poster": poster,
                        "icon": poster,
                        "fanart": fanart,
                        "type": ADDON_TYPE,
                        "plot": plot,
                        "isFolder": isFolder,
                        "extras": str(extras)
                    })
                else:
                    menu.append({
                        "title": title,
                        "url": url,
                        "mode": newMode,
                        "poster": poster,
                        "icon": poster,
                        "fanart": fanart,
                        "type": ADDON_TYPE,
                        "plot": plot,
                        "isFolder": isFolder,
                        "isPlayable": "True",
                        "extras": str(extras)
                    })
                counter = counter + 1
        try:
            regex = util.prepare(site['items'][level][pos]['next_pattern'])
            matches = re.findall(regex, next)
            if matches:
                parts = []
                if len(matches) > 1:
                    for match in matches:
                        parts.append(match)
                else:
                    match = matches

                #nextlink=util.execPy(util.replaceParts(site['items'][level][pos]['next_url'], match))
                nextlink = util.replaceParts(
                    site['items'][level][pos]['next_url'], match)
                extras['pos'] = pos

                menu.append({
                    "title": "Next Page >",
                    "url": urllib.quote_plus(nextlink),
                    "mode": "2",
                    "poster": "",
                    "icon": "",
                    "fanart": "",
                    "type": ADDON_TYPE,
                    "plot": plot,
                    "isFolder": True,
                    "extras": str(extras)
                })
        except Exception as e:
            util.logError(str(e))
            pass
        util.addMenuItems(menu)
    elif mode == 3:
        # display the Search dialog and build search results
        menu = []
        extras = ast.literal_eval(parameters['extras'])

        try:
            extras['site_xml'] = offsite['site_xml']
        except:
            pass

        term = util.searchDialog()

        if term:
            bits = util.getFile(feed, type)
            site = bits['sites'][extras['site']]
            pos = 0

            for item in site['items']:
                level = item
                extras['level'] = level
                break

            if len(site['items'][extras['level']]) > pos + 1:
                # another level is needed
                extras['pos'] = 1
                newMode = "2"
                isFolder = True
                isPlayable = True
            else:
                # on a level where next move is to check for sources
                if site['items'][
                        extras['level']][pos]['play_media'] == "multiple":
                    newMode = "113"
                    isFolder = True
                    isPlayable = False
                else:
                    newMode = "111"  # find source
                    isFolder = False
                    isPlayable = True
            if "{{" in site['search_url'] and "}}" in site['search_url']:
                url = util.execPy(site['search_url'].replace("{%}", term))
            else:
                url = site['search_url'].replace("{%}", term)
            util.logError(url)
            page = util.get(url)
            next = page

            try:
                if site['item']['global'] != "":
                    regex = util.prepare(site['item']['global'])
                    matches = re.findall(regex, page)
                    if matches:
                        page = matches[0]
            except:
                pass

            regex = util.prepare(site['items'][level][pos]['pattern'])
            matches = re.findall(regex, page)

            if matches:
                counter = 0
                for match in matches:
                    try:
                        title = h.unescape(
                            util.replaceParts(
                                site['items'][level][pos]['name'],
                                matches[counter]).replace('\n', '').replace(
                                    '\t', '').lstrip().encode('utf-8'))
                    except:
                        title = ""
                    try:
                        url = util.replaceParts(
                            site['items'][level][pos]['url'],
                            matches[counter]).encode('utf-8')
                        #util.logError(url)
                    except:
                        url = ""
                    try:
                        poster = util.replaceParts(
                            site['items'][level][pos]['poster'],
                            matches[counter]).encode('utf-8')
                    except:
                        poster = ""
                    try:
                        fanart = util.replaceParts(
                            site['items'][level][pos]['fanart'],
                            matches[counter]).encode('utf-8')
                    except:
                        fanart = ""
                    try:
                        plot = util.replaceParts(
                            site['items'][level][pos]['plot'],
                            matches[counter]).encode('utf-8')
                    except:
                        plot = ""

                    if isFolder:
                        menu.append({
                            "title": title,
                            "url": url,
                            "mode": newMode,
                            "poster": poster,
                            "icon": poster,
                            "fanart": fanart,
                            "type": ADDON_TYPE,
                            "plot": plot,
                            "isFolder": isFolder,
                            "extras": str(extras)
                        })
                    else:
                        menu.append({
                            "title": title,
                            "url": url,
                            "mode": newMode,
                            "poster": poster,
                            "icon": poster,
                            "fanart": fanart,
                            "type": ADDON_TYPE,
                            "plot": plot,
                            "isFolder": isFolder,
                            "isPlayable": "True",
                            "extras": str(extras)
                        })
                    counter = counter + 1
            try:
                regex = util.prepare(site['items'][level][pos]['next_pattern'])
                matches = re.findall(regex, next)
                if matches:
                    parts = []
                    """for match in matches:
                        parts.append(match)"""

                    if len(matches) > 1:
                        for match in matches:
                            parts.append(match)
                        else:
                            match = matches

                    #nextlink=util.execPy(util.replaceParts(site['items'][level][pos]['next_url'], match))
                    nextlink = util.replaceParts(
                        site['items'][level][pos]['next_url'], match)
                    menu.append({
                        "title": "Next Page >",
                        "url": nextlink,
                        "mode": "2",
                        "poster": "",
                        "icon": "",
                        "fanart": "",
                        "type": ADDON_TYPE,
                        "plot": plot,
                        "isFolder": True,
                        "extras": str(extras)
                    })
            except:
                pass
            util.addMenuItems(menu)
        else:
            return False
    elif mode == 4:
        # show relevant Tag video results
        menu = []

        extras = ast.literal_eval(parameters['extras'])

        try:
            extras['site_xml'] = offsite['site_xml']
        except:
            pass

        bits = util.getFile(feed, type)

        site = bits['sites'][extras['site']]['tags'][extras['tag']]

        page = util.get(parameters['url'])
        next = page

        try:
            if site['item']['global'] != "":
                regex = util.prepare(site['item']['global'])
                matches = re.findall(regex, page)
                if matches:
                    page = matches[0]
        except:
            pass

        regex = util.prepare(site['item']['pattern'])
        matches = re.findall(regex, page)
        if matches:
            counter = 0
            for match in matches:
                try:
                    title = h.unescape(
                        util.replaceParts(site['item']['name'],
                                          matches[counter]).encode('utf-8'))
                except:
                    title = ""
                try:
                    url = util.replaceParts(site['item']['url'],
                                            matches[counter]).encode('utf-8')
                except:
                    url = ""
                try:
                    poster = util.replaceParts(
                        site['item']['poster'],
                        matches[counter]).encode('utf-8')
                except:
                    poster = ""
                try:
                    fanart = util.replaceParts(
                        site['item']['fanart'],
                        matches[counter]).encode('utf-8')
                except:
                    fanart = ""
                try:
                    plot = util.replaceParts(site['item']['plot'],
                                             matches[counter]).encode('utf-8')
                except:
                    plot = ""

                menu.append({
                    "title": title,
                    "url": url,
                    "mode": "2",
                    "poster": poster,
                    "icon": poster,
                    "fanart": fanart,
                    "type": ADDON_TYPE,
                    "plot": plot,
                    "isFolder": True,
                    "extras": extras
                })
                counter = counter + 1
        util.addMenuItems(menu)
    elif mode == 5:
        pass
    elif mode == 111:
        # find playable sources in url
        #util.alert(parameters['url'])

        extras = ast.literal_eval(parameters['extras'])
        bits = util.getFile(feed, type)
        site = bits['sites'][extras['site']]

        try:
            pos = extras['pos']
        except:
            pos = 0

        try:
            selected_video = int(
                site['items'][extras['level']][pos]['play_media']) - 1
        except:
            selected_video = 0

        page = util.get(parameters['url'])

        link = False
        try:
            link = urlresolver.resolve(parameters['url'])
        except Exception as e:
            if str(e).lower() == "sign in to confirm your age":
                util.notify("YouTube Error: Login to confirm age.")
                return False
            else:
                util.notify(str(e))
                return False

        if link:
            # play if url resolver reports true
            util.playMedia(parameters['name'],
                           parameters['poster'],
                           link,
                           force=True)
        elif any(ext in parameters['url'] for ext in filetypes):
            # play if url has a video extension
            util.playMedia(parameters['name'],
                           parameters['poster'],
                           parameters['url'],
                           force=True)
        else:
            #search for video urls
            if "urlresolver" in site and site['urlresolver'].lower(
            ) == "false":
                regex = "\"([^\s]*?\.(:?" + "|".join(filetypes) + "))\""
                matches = re.findall(regex, page)
            else:
                regex = "(\/\/.*?\/embed.*?)[\?\"]"
                matches = re.findall(regex, page)
                regex = "\"((?:http:|https:)?\/\/.*?\/watch.*?)[\"]"
                matches = matches + re.findall(regex, page)
                matches2 = urlresolver.scrape_supported(page)
                #util.alert(str(matches))
                """regex="\"(https?://("+"|".join(supports)+")\..*?)\""
                matches2 = re.findall(regex, page)
                regex="\"((?:http:|https:)?\/\/.*?\/watch.*?)[\"]"
                matches3 = re.findall(regex, page)
                regex = 'https?://(.*?(?:\.googlevideo|(?:plus|drive|get|docs)\.google|google(?:usercontent|drive|apis))\.com)/(.*?(?:videoplayback\?|[\?&]authkey|host/)*.+)'
                matches4 = re.findall(regex, page)
                
                matches2=[ x for x in matches2 if any(sup in x for sup in supports) ]
                matches3=[ x for x in matches3 if any(sup in x for sup in supports) ]"""

                matches = matches + matches2
            util.logError(
                "''''''''''''''''''''''''''''''''''''''''''''''''''''''")
            util.logError(">>>>" + str(matches))
            if isinstance(matches[selected_video], tuple):
                url = matches[selected_video][0]
            else:
                url = matches[selected_video]
            #util.alert(url)
            if "http" not in url:
                url = "http:" + url

            link = urlresolver.resolve(url)

            if link == False:
                link = url

            util.playMedia(parameters['name'], parameters['poster'], link)

    elif mode == 112:
        extras = ast.literal_eval(parameters['extras'])
        bits = util.getFile(feed, type)
        site = bits['sites'][extras['site']]

        page = util.get(parameters['url'])
        """if "urlresolver" in site and site['urlresolver'].lower()=="false":
            regex="\"(.*?\.mp4)\""
            matches = re.findall(regex, page)
            if matches:
                link=matches[0]
        else:"""
        regex = "\"(//\S*?(:?" + ("|".join(filetypes)) + ")\S*?)\""
        matches = re.findall(regex, page)
        if matches:
            url = matches[selected_video][0]
            if "http" not in url:
                link = "http:" + url
        else:
            link = urlresolver.resolve(parameters['url'])
            if not link:
                try:
                    regex = "(\/\/.*?\/embed.*?)[\?\"]"
                    matches = re.findall(regex, page)
                    regex = "\"((?:http:|https:)?\/\/.*?\/watch.*?)[\"]"
                    matches = matches + re.findall(regex, page)
                    regex = 'https?://(.*?(?:\.googlevideo|(?:plus|drive|get|docs)\.google|google(?:usercontent|drive|apis))\.com)/(.*?(?:videoplayback\?|[\?&]authkey|host/)*.+)'
                    matches = matches + re.findall(regex, page)
                    if matches:
                        matches = [
                            x for x in matches
                            if any(sup in x for sup in supports)
                        ]
                        if matches:
                            link = urlresolver.resolve("http:" + matches[0])
                except Exception as e:
                    util.notify(str(e))
        if link:
            import downloader
            downloader.download(
                link,
                os.path.join(xbmcaddon.Addon().getSetting('folder'),
                             parameters['name'] + ".mp4"))
        else:
            util.notify("No video found")
    elif mode == 113:
        menu = []
        extras = ast.literal_eval(parameters['extras'])
        bits = util.getFile(feed, type)
        site = bits['sites'][extras['site']]

        page = util.get(parameters['url'])

        matches = urlresolver.scrape_supported(page)
        #regex="(//\S*?(:?"+("|".join(filetypes))+")\S*?)"
        #matches2 = re.findall(regex, page)
        """regex="(\/\/.*?\/embed.*?)[\?\"]"
        matches2 = re.findall(regex, page)
        regex="\"(https?://("+"|".join(supports)+")\..*?)\""
        matches3 = re.findall(regex, page)
        regex = 'https?://(.*?(?:\.googlevideo|(?:plus|drive|get|docs)\.google|google(?:usercontent|drive|apis))\.com)/(.*?(?:videoplayback\?|[\?&]authkey|host/)*.+)'
        matches4 = re.findall(regex, page)
        
        matches2=[ x for x in matches2 if any(sup in x for sup in supports) ]
        matches3=[ x for x in matches3 if any(sup in x for sup in supports) ]
        
        matches=matches+matches2+matches3+matches4"""

        unique = []
        for match in matches:  #+matches2:
            if isinstance(match, tuple):
                unique.append(match[0])
            else:
                unique.append(match)

        matches = list(set(unique))

        if matches:
            for match in matches:
                if "http" not in match:
                    rl = "http:" + match
                else:
                    rl = match

                menu.append({
                    "title": rl,
                    "url": rl,
                    "mode": "114",
                    "poster": parameters['poster'],
                    "icon": parameters['icon'],
                    "fanart": parameters['fanart'],
                    "type": "",
                    "plot": "",
                    "isFolder": False,
                    "isPlayable": False,
                    "extras": str(extras)
                })
            util.addMenuItems(menu)
    elif mode == 114:
        # find playable sources in url
        #util.alert(parameters['url'])
        urlresolver.relevant_resolvers()
        try:
            link = urlresolver.resolve(str(parameters['url']))
        except Exception as e:
            util.notify(str(e))
            exit()
        if link:
            try:
                util.playMedia(parameters['name'], parameters['poster'], link)
            except:
                util.playMedia(parameters['name'], parameters['poster'],
                               parameters['url'])
Ejemplo n.º 8
0
 def draw(self, surface, offset=(0,0)):
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'title.png')], (0,0))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'users_back.png')], (788,219))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'chat_back.png')], (250,624))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'rooms_back.png')], (219,252))
Ejemplo n.º 9
0
 def draw(self, surface, offset=(0,0)):
     surface.blit(self.roomF_Rendered, (10,45))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'users_back.png')], (788,219))
     surface.blit(util.IMAGECACHE[util.getFile(util.IMAGES, "LOBBY", 'chat_back.png')], (250,624-(232/2)))
Ejemplo n.º 10
0
def execute():

    try:
        opts, args = getopt.getopt(sys.argv[1:], "dhqstwcxb", [
            "quiet",
            "help",
            "start-viewer",
            "start",
            "debug=",
            "copyright",
            "version",
            "warn",
            "tempdir=",
            "format=",
            "css=",
            "base=",
            "css-dump",
            "xml-dump",
            "xhtml",
            "xml",
            "html",
            "encoding=",
            "system",
            "profile",
        ])
    except getopt.GetoptError:
        usage()
        sys.exit(2)

    errors = 0
    startviewer = 0
    quiet = 0
    debug = 0
    tempdir = None
    format = "pdf"
    css = None
    xhtml = None
    encoding = None
    xml_output = None
    base_dir = None

    log_level = logging.ERROR
    log_format = LOG_FORMAT

    for o, a in opts:

        if o in ("-h", "--help"):
            # Hilfe anzeigen
            usage()
            sys.exit()

        if o in ("-s", "--start-viewer", "--start"):
            # Anzeigeprogramm starten
            startviewer = 1

        if o in ("-q", "--quiet"):
            # Output unterdr�cken
            quiet = 1

        if o in ("-w", "--warn"):
            # Warnings
            log_level = min(log_level, logging.WARN)  # If also -d ignore -w

        if o in ("-d", "--debug"):
            # Debug
            log_level = logging.DEBUG
            log_format = LOG_FORMAT_DEBUG

            if a:
                log_level = int(a)

        if o in ("--copyright", "--version"):
            print COPYRIGHT
            sys.exit(0)

        if o in ("--system",):
            print COPYRIGHT
            print
            print "SYSTEM INFORMATIONS"
            print "--------------------------------------------"
            print "OS:                ", sys.platform
            print "Python:            ", sys.version
            print "html5lib:          ", "?"
            import reportlab

            print "Reportlab:         ", reportlab.Version
            sys.exit(0)

        if o in ("-t", "--format"):
            # Format XXX ???
            format = a

        if o in ("-b", "--base"):
            base_dir = a

        if o in ("--encoding",) and a:
            # Encoding
            encoding = a

        if o in ("-c", "--css"):
            # CSS
            css = file(a, "r").read()

        if o in ("--css-dump",):
            # CSS dump
            print DEFAULT_CSS
            return

        if o in ("--xml-dump",):
            xml_output = sys.stdout

        if o in ("-x", "--xml", "--xhtml"):
            xhtml = True
        elif o in ("--html",):
            xhtml = False

    if not quiet:
        try:
            logging.basicConfig(
                level=log_level,
                format=log_format)
        except:
            # XXX Logging doesn't work for Python 2.3
            logging.basicConfig()

    if len(args) not in (1, 2):
        usage()
        sys.exit(2)

    if len(args) == 2:
        a_src, a_dest = args
    else:
        a_src = args[0]
        a_dest = None

    if "*" in a_src:
        a_src = glob.glob(a_src)
        # print a_src
    else:
        a_src = [a_src]

    for src in a_src:

        # If not forced to parse in a special way have a look
        # at the filename suffix
        if xhtml is None:
            xhtml = src.lower().endswith(".xml")

        lc = None

        if src == "-" or base_dir is not None:
            # Output to console
            fsrc = sys.stdin
            wpath = os.getcwd()
            if base_dir:
                wpath = base_dir
        else:
            if src.startswith("http:") or src.startswith("https:"):
                wpath = src
                fsrc = getFile(src).getFile()
                src = "".join(urlparse.urlsplit(src)[1:3]).replace("/", "-")
            else:
                fsrc = wpath = os.path.abspath(src)
                fsrc = open(fsrc, "rb")

        if a_dest is None:
            dest_part = src
            if dest_part.lower().endswith(".html") or dest_part.lower().endswith(".htm"):
                dest_part = ".".join(src.split(".")[:-1])
            dest = dest_part + "." + format.lower()
            for i in xrange(10):
                try:
                    open(dest, "wb").close()
                    break
                except:
                    pass
                dest = dest_part + "-%d.%s" % (i, format.lower())
        else:
            dest = a_dest

        fdestclose = 0

        if dest == "-" or base_dir:
            if sys.platform == "win32":
                import msvcrt
                msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)

            fdest = sys.stdout
            startviewer = 0
        else:
            dest = os.path.abspath(dest)
            try:
                open(dest, "wb").close()
            except:
                print "File '%s' seems to be in use of another application." % dest
                sys.exit(2)
            fdest = open(dest, "wb")
            fdestclose = 1

        if not quiet:
            print "Converting %s to %s..." % (src, dest)

        pdf = pisaDocument(
            fsrc,
            fdest,
            debug=debug,
            path=wpath,
            errout=sys.stdout,
            tempdir=tempdir,
            format=format,
            link_callback=lc,
            default_css=css,
            xhtml=xhtml,
            encoding=encoding,
            xml_output=xml_output,
        )

        if xml_output:
            xml_output.getvalue()

        if fdestclose:
            fdest.close()

        if (not errors) and startviewer:
            if not quiet:
                print "Open viewer for file %s" % dest
            startViewer(dest)