示例#1
0
    def test_ud(ilist):
        filter = UserDefinedFilter(ilist)

        from cStringIO import StringIO
        from element import Element
        from media import MediaFactory,GenericMedia,List
        fd = StringIO('''<TrackerList>
    <Tracker publisher="th-torrent">
        <Url name="login" url="http://forums.btthai.com/" method="post">
            <Param name="UserName" value="%(user)s"/>
            <Param name="PassWord" value="%(password)s"/>
            <Param name="act" value="Login"/>
            <Param name="CODE" value="01"/>
            <Param name="CookieDate" value="1"/>
        </Url>
        <Url name="catalog" url="http://forums.btthai.com/" method="get">
            <Param name="act" value="bt"/>
            <Param name="func" value="browse"/>
            <Filter name="main"><![CDATA[<tr>\s*<td class="[^"]+" align="center"><img src="style_images/[^/]+/cat_(?P<category>[^\.]+).[^<]+" border="0" alt="[^"]+" width="\d+" height="\d+"/></td>\s*<td class="[^"]+" align="left"><a href="(?P<link>[^"]+)">(?P<title>[^<]+)</a></td>\s*<td class="[^"]+" align="right">(?P<files>\d+)</td>\s*<td class="[^"]+" align="center">[^<]+</td>\s*<td class="[^"]+" align="center" nowrap>(?P<date>[^<]+(<br/>| )[^<]*)</td>\s*<td class="[^"]+" align="center">[^<]+</td>\s*<td class="[^"]+" align="center">\d+</td>\s*<td class="[^"]+" align="right">\d+</td>\s*<td class="[^"]+" align="right">\d+</td>\s*<td class="[^"]+" align="center"><a href="[^"]+">(?P<publisher>[^<]+)</a></td>\s*</tr>]]></Filter>
            <Filter name="detail"><![CDATA[<tr><td align="left" class='pformleft'>Name</td><td class='pformright'><a href="index.php\?showtopic=\d+">(?P<description>[^<]+)</a></td></tr>\s*<tr><td align="left" class='pformleft'>Info Hash</td><td class='pformright'>[^<]+</td></tr>\s*<tr><td align="left" class='pformleft'>Download</td><td class='pformright'><a href="(?P<download>[^\?]+\?act=bt&func=download&id=\d+)">[^<]+</a></td></tr>]]></Filter>
        </Url>
        <Url name="logout" url="http://th-torrent.mine.nu/"/>
    </Tracker>
</TrackerList>''' % {'user': user,
                     'password': passwd})
        element = Element()
        element.load(fd)
        factory = MediaFactory(GenericMedia,List)
        tlist = factory.from_element(element)
        fd.close()

        loader = TrackerLoader(tlist[0],filter)
        loader.fetch().to_element().save(sys.stdout)
示例#2
0
 def from_file(self,file):
     close_flag = 0
     if type(file) == type(''):
         fd = open(file,'r')
         close_flag = 1
     else:
         fd = file
     e = Element()
     e.load(fd)
     if close_flag:
         fd.close()
     return self.from_element(e)
示例#3
0
factory.register('enclosure',rssEnclosure)

if __name__ == '__main__':
    import sys
    from cStringIO import StringIO
    mlist = List('MediaList')
    mlist.append(Generic('Media',{'title': 'test'}))
    mlist.append(Series('Anime',{'title': 'Gundam Seed','episode': 1}))
    fd = StringIO()
    mlist.to_element().save(fd)
    fd.seek(0,0)
    result = fd.read()
    print result
    fd.seek(0,0)
    element = Element()
    element.load(fd)
    mlist = factory.from_element(element)
    fd.close()
    mlist.to_element().save(sys.stdout)

    fd = StringIO('''<TrackerList>
    <Tracker publisher="th-torrent">
        <Url name="login" url="http://th-torrent.mine.nu/" method="post">
            <Param name="user" value="sugree"/>
            <Param name="password" value="xxxx"/>
        </Url>
        <Url name="catalog" url="http://th-torrent.mine.nu/">
            <Filter name="main"><![CDATA[<tr>\s*<td class="[^"]+" align="center"><img src="style_images/[^/]+/cat_(?P<category>[^\.]+).[^<]+" border="0" alt="[^"]+" width="\d+" height="\d+"/></td>\s*<td class="[^"]+" align="left"><a href="(?P<link>[^"]+)">(?P<title>[^<]+)</a></td>\s*<td class="[^"]+" align="right">(?P<files>\d+)</td>\s*<td class="[^"]+" align="center">[^<]+</td>\s*<td class="[^"]+" align="center" nowrap>(?P<date>[^<]+(<br/>| )[^<]*)</td>\s*<td class="[^"]+" align="center">[^<]+</td>\s*<td class="[^"]+" align="center">\d+</td>\s*<td class="[^"]+" align="right">\d+</td>\s*<td class="[^"]+" align="right">\d+</td>\s*<td class="[^"]+" align="center"><a href="[^"]+">(?P<publisher>[^<]+)</a></td>\s*</tr>]]></Filter>
            <Filter name="detail"><![CDATA[<a href="(?P<download>[^\?]+\?act=bt&func=download&id=\d+)">]]></Filter>
        </Url>
        <Url name="logout" url="http://th-torrent.mine.nu/"/>