コード例 #1
0
	def MakePage(self, flipnotes, page, next, count):
		ugo = UGO()
		ugo.Loaded = True
		ugo.Items = []
		
		#meta
		ugo.Items.append(("layout", (2, 1)))
		ugo.Items.append(("topscreen text", ["Liked Flipnotes", "Flipnotes", str(count), "", "The most liked new Flipnotes."], 0))
		
		#categories
		ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/hotmovies.uls", "Most Popular", False))
		ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/likedmovies.uls", "Most Liked", True))
		#ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/recommended.uls", "Recommended", False))
		ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/newmovies.uls", "New Flipnotes", False))
		#ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/following.uls", "New Favourites", False))
		
		#the "post flipnote" button
		ugo.Items.append(("unknown", ("3", "http://flipnote.hatena.com/ds/v2-xx/help/post_howto.htm", "UABvAHMAdAAgAEYAbABpAHAAbgBvAHQAZQA=")))
		
		#previous page
		if page > 1:
			ugo.Items.append(("button", 115, "Previous", "http://flipnote.hatena.com/ds/v2-xx/frontpage/likedmovies.uls?page=%i" % (page-1), ("", ""), None))
		
		#Flipnotes
		for creatorid, filename in flipnotes:#[i*50 : i*50+50]:
			stars = str(Database.GetFlipnote(creatorid, filename)[2])
			ugo.Items.append(("button", 3, "", "http://flipnote.hatena.com/ds/v2-xx/movie/%s/%s.ppm" % (creatorid, filename), (stars, "765", "573", "0"), (filename+".ppm", Database.GetFlipnoteTMB(creatorid, filename))))
		
		#next page
		if next:
			ugo.Items.append(("button", 115, "Next", "http://flipnote.hatena.com/ds/v2-xx/frontpage/likedmovies.uls?page=%i" % (page+1), ("", ""), None))
		
		return ugo.Pack()
コード例 #2
0
ファイル: hotmovies.ugo.py プロジェクト: dylmye/hatena-server
	def MakePage(self, flipnotes, page, next, count):
		ugo = UGO()
		ugo.Loaded = True
		ugo.Items = []
		
		#meta
		ugo.Items.append(("layout", (2, 1)))
		ugo.Items.append(("topscreen text", ["Popular Flipnotes", "Flipnotes", str(count), "", "The most popular new Flipnotes."], 0))
		
		#categories
		ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/hotmovies.uls", "Most Popular", True))
		ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/likedmovies.uls", "Most Liked", False))
		#ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/recommended.uls", "Recommended", False))
		ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/newmovies.uls", "New Flipnotes", False))
		#ugo.Items.append(("category", "http://flipnote.hatena.com/ds/v2-xx/frontpage/following.uls", "New Favourites", False))
		
		#the "post flipnote" button
		ugo.Items.append(("unknown", ("3", "http://flipnote.hatena.com/ds/v2-xx/help/post_howto.htm", "UABvAHMAdAAgAEYAbABpAHAAbgBvAHQAZQA=")))
		
		#previous page
		if page > 1:
			ugo.Items.append(("button", 115, "Previous", "http://flipnote.hatena.com/ds/v2-xx/frontpage/hotmovies.uls?page=%i" % (page-1), ("", ""), None))
		
		#Flipnotes
		for creatorid, filename in flipnotes:
			stars = str(Database.GetFlipnote(creatorid, filename)[2])
			ugo.Items.append(("button", 3, "", "http://flipnote.hatena.com/ds/v2-xx/movie/%s/%s.ppm" % (creatorid, filename), (stars, "765", "573", "0"), (filename+".ppm", Database.GetFlipnoteTMB(creatorid, filename))))
		
		#next page
		if next:
			ugo.Items.append(("button", 115, "Next", "http://flipnote.hatena.com/ds/v2-xx/frontpage/hotmovies.uls?page=%i" % (page+1), ("", ""), None))
		
		return ugo.Pack()
コード例 #3
0
    def FetchHatena(self, addr):
        if DEBUG: print "hatenafetch:", addr

        request = urllib2.Request(addr)
        request.add_header('x-dsi-sid', 'pbsds\' flipnote player')
        resp = urllib2.urlopen(request)

        data = resp.read()

        if 0 and addr.split("/")[-1].split("?")[0][-4:] == ".ugo":

            print "writing ugo...",
            f = open("hatenafetch/" + addr.split("/")[-1].replace("?", "."),
                     "wb")
            f.write(data)
            f.close()

            print "writing ugoxml..."
            name = addr.split("/")[-1].split("?")[0] + "xml" + "." * (len(
                addr.split("/")[-1].split("?")) > 1) + ".".join(
                    addr.split("/")[-1].split("?")[1:])
            UGO.UGO().Read(data).WriteXML(xmlname="hatenafetch/" + name,
                                          folder=("%s embedded" % name))

            print "done"

        return data
コード例 #4
0
    def FetchHatena(self, addr):
        if DEBUG: print "hatenafetch:", addr

        #sudomemo fix. Sudomemo blocks requests with user-agents and requires each session to have a unique SID
        if addr == "http://flipnote.hatena.com/ds/v2-eu/index.ugo":
            self.SID = 'pbsdsFlipnotePlayer%s' % "".join((chr(
                random.randrange(ord("A"),
                                 ord("Z") + 1) +
                random.choice((0, ord("a") - ord("A")))) for _ in xrange(21)))
            if DEBUG: print "generated SID:", self.SID
        urllib2._opener.addheaders = []

        request = urllib2.Request(addr, headers={'x-dsi-sid': self.SID})

        resp = urllib2.urlopen(request)

        data = resp.read()

        if 0 and addr.split("/")[-1].split("?")[0][-4:] == ".ugo":

            print "writing ugo...",
            f = open("hatenafetch/" + addr.split("/")[-1].replace("?", "."),
                     "wb")
            f.write(data)
            f.close()

            print "writing ugoxml..."
            name = addr.split("/")[-1].split("?")[0] + "xml" + "." * (len(
                addr.split("/")[-1].split("?")) > 1) + ".".join(
                    addr.split("/")[-1].split("?")[1:])
            UGO.UGO().Read(data).WriteXML(xmlname="hatenafetch/" + name,
                                          folder=("%s embedded" % name))

            print "done"

        return data
コード例 #5
0
    def GotoDir(self, dir, lappend=None, lforce=False):
        self.history.append((self.dir, self.labeldir[0]))
        self.dir = dir
        self.scroll = 0

        if dir == None:
            self.labeldir[0] = "root"
            self.history = []
        elif self.labeldir[0] == "root" or lforce:
            self.labeldir[0] = lappend
        elif lappend:
            self.labeldir[0] = os.path.join(self.labeldir[0], lappend)
        self.labeldir[1] = Text.CreateShadowed(self.labeldir[0], 9,
                                               self.TextColor[0],
                                               self.TextColor[1])

        self.files = [
        ]  #[i] = (folder(bool), name(spr), label(surface), icon, full path)
        if dir == None:
            if len(glob.glob("saved/*.ppm")):
                self.files.append(
                    (True, "saved",
                     Text.CreateShadowed("saved flipnotes", 9,
                                         self.TextColor[0], self.TextColor[1]),
                     self.sIconFolder, "saved"))

            #self.files.append((True, "local", Text.CreateShadowed("local files", 9, self.TextColor[0], self.TextColor[1]), self.sIconFolder, os.getcwd()))#temp path

            for i, (letter, label) in enumerate(GetDriveNames()):
                self.files.append(
                    (True, "%s:" % letter,
                     Text.CreateShadowed("%s (%s:/)" % (label, letter), 9,
                                         self.TextColor[0], self.TextColor[1]),
                     self.sIconDrive, "%s:/" % letter))  #temp path

            for name, address, port, icon in self.servers:
                self.files.append(
                    (True, "hatena",
                     Text.CreateShadowed(name, 9, self.TextColor[0],
                                         self.TextColor[1]), icon,
                     "prox://%s:%s" % (address, port)))

            #self.files.append((True, "local files", self.LoadIcon(), os.getcwd()))#temp path
            pass
        elif dir[4:7] == "://":
            if dir[:4] == "prox":
                urllib2.install_opener(
                    urllib2.build_opener(
                        urllib2.ProxyHandler({'http': dir[7:]})))
                dir = "http://flipnote.hatena.com/ds/v2-eu/index.ugo"

            if dir[:4] == "http":
                ugo = UGO.UGO().Read(self.FetchHatena(dir))

                for i in ugo.Items:
                    if i[0] == "category":
                        link, label, selected = i[1:]
                        if not selected and link.split("?")[0][-4:] == ".uls":
                            split = link.split("?")
                            addr = split[0][:-4] + ".ugo" + "?" * (
                                len(split) > 1) + "?".join(split[1:])

                            name = split[0][:-4].split("/")[-1]

                            self.files.append(
                                (True, name,
                                 Text.CreateShadowed(label, 9,
                                                     self.TextColor[0],
                                                     self.TextColor[1]),
                                 self.sIconFolder, addr))  #temp path

                    elif i[0] == "button":
                        trait, label, link, other, file = i[1:]

                        if link.split("?")[0][-4:] == ".uls":
                            split = link.split("?")
                            addr = split[0][:-4] + ".ugo" + "?" * (
                                len(split) > 1) + "?".join(split[1:])

                            name = split[0][:-4].split("/")[-1]

                            if file:
                                icon = self.LoadIcon(file[1])  #ntft
                            else:
                                icon = self.sIconFolder

                            self.files.append(
                                (True, name,
                                 Text.CreateShadowed(label, 9,
                                                     self.TextColor[0],
                                                     self.TextColor[1]), icon,
                                 addr))  #temp path
                        elif link[-4:] == ".ppm":
                            icon = self.LoadIcon(file[1])  #tmb

                            username = Text.CreateShadowed(
                                u"submitted by " + self.tmb.Username, 9,
                                self.TextColor[0], self.TextColor[1])
                            filename = Text.CreateShadowed(
                                file[0][:-4], 9, self.TextColor[0],
                                self.TextColor[1])
                            stars = Text.CreateShadowed(
                                other[0] + " stars", 9, self.StarColor[0],
                                self.StarColor[1])

                            self.files.append(
                                (False, "flipnote", (filename, username,
                                                     stars), icon, link))
        else:
            folders = []
            files = []
            for i in glob.glob(os.path.join(dir, "*")):
                if os.path.isdir(i):
                    folders.append(i)
                elif i[-4:] == ".ppm":
                    files.append(i)

            folders.sort(key=lambda x: x.lower())
            for i in folders:
                name = os.path.basename(i)
                self.files.append(
                    (True, name,
                     Text.CreateShadowed(name, 9, self.TextColor[0],
                                         self.TextColor[1]), self.sIconFolder,
                     i))

            files.sort()
            for i in files:
                name = os.path.basename(i)

                f = open(i, "rb")
                icon = self.LoadIcon(f.read())
                f.close()

                username = Text.CreateShadowed(
                    u"submitted by " + self.tmb.Username, 9, self.TextColor[0],
                    self.TextColor[1])
                filename = Text.CreateShadowed(self.tmb.CurrentFilename[:-4],
                                               9, self.TextColor[0],
                                               self.TextColor[1])

                self.files.append((False, name, (username, filename), icon, i))