Torrent browser and downloader for site X
#16
grajen3 Wrote:right, sorry for misleading You
...
[/code]

thanks again, will try it out tomorrow!
  • Livingroom - C2D E8400, P5N7A-VM on a Samsung 46" LE46M86 FullHD via HDMI
  • Kitchen - ASRock 330 HT Displayed on a Samsung Lapfit 22" dual touch screen LD220Z
  • Bedroom - LG Laptop on a 32" tv
Reply
#17
it will be great, if it is possible to browse btjunkie.org with an interface like Forum Browser.
Reply
#18
cool, I finally got it working and made a nicer structure of it. Thanks a lot grajen3!

Now I'm just wondering if there's anyway to speed it up. What I realized, after adding some debug code, is that the major culprit is the first url-fetch. There seems to be some initializing going on in XBMC.

the "one" is before the first "resp = opener.open('https://xxxx.yyy/login.php')" and the "two" is directly after it. As you can see it takes 11 seconds to load it up. Is that normal? Or should I perhaps use other methods of fetching urls?
(It needs to be able to handle cookies)

Code:
21:45:00 T:504 M:2348601344  NOTICE: one
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Load(ADVAPI32.DLL)
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Load(KERNEL32.DLL)
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Load(USER32.DLL)
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Load(NETAPI32.DLL)
21:45:00 T:504 M:2348564480   DEBUG: FreeLibrary(NETAPI32.DLL) -> 07BF6268
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Unload NETAPI32.DLL
21:45:00 T:504 M:2348564480   DEBUG: FreeLibrary(ADVAPI32.DLL) -> 07BF64E8
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Unload ADVAPI32.DLL
21:45:00 T:504 M:2348564480   DEBUG: FreeLibrary(USER32.DLL) -> 07BF5CA8
21:45:00 T:504 M:2348564480   DEBUG: Win32DllLoader::Unload USER32.DLL
21:45:10 T:504 M:2348662784   DEBUG: FreeLibrary(KERNEL32.DLL) -> 07BF69E8
21:45:10 T:504 M:2348662784   DEBUG: Win32DllLoader::Unload KERNEL32.DLL
21:45:11 T:504 M:2348621824  NOTICE: two

/watz
  • Livingroom - C2D E8400, P5N7A-VM on a Samsung 46" LE46M86 FullHD via HDMI
  • Kitchen - ASRock 330 HT Displayed on a Samsung Lapfit 22" dual touch screen LD220Z
  • Bedroom - LG Laptop on a 32" tv
Reply
#19
Here's the "final" working code (if anyone googles in here):
Code:
import string, urllib2, urllib, re, cookielib, xbmc, xbmcgui, xbmcplugin, sys, os, traceback, xbmcaddon, string

__settings__ = xbmcaddon.Addon(id='plugin.video.torrentsite')

username = __settings__.getSetting('username')
user_password = __settings__.getSetting('user_password')
downloadPath = __settings__.getSetting('downloadPath')

print 'username: ' + username
print 'user_password: ' + user_password
print 'downloadPath: ' + downloadPath

def addLink(name,url,mode,iconimage):
    u = sys.argv[0] + '?url=' + urllib.quote_plus(url) + '&mode='+str(mode) + '&name=' +urllib.quote_plus(name)
    ok = True
    liz=xbmcgui.ListItem(name, iconImage="DefaultVideo.png", thumbnailImage=iconimage)
    liz.setInfo( type="Video", infoLabels={ "Title": name } )
    ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz)
    return ok

def addDir(name,url,mode,iconimage):
    u=sys.argv[0]+'?url='+urllib.quote_plus(url)+'&mode='+str(mode)+'&name='+urllib.quote_plus(name)
    ok=True
    liz=xbmcgui.ListItem(name, iconImage='DefaultFolder.png',thumbnailImage=iconimage)
    liz.setInfo( type='Video', infoLabels={ 'Title': name })
    ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
    return ok

def CATEGORIES():
    addDir('Ordered by amount of leechers','http://torrentsite.com/browse.php?c1=1&co1=1&m3=1&page=0&sort=leechers&h=11&d=DESC',1,'')
    addDir("Ordered by amount of seeders",'http://torrentsite.com/browse.php?c1=1&co1=1&m3=1&sort=seeders&h=10&d=DESC',1,'')
    addDir("Ordered by date added",'https://torrentsite.com/browse.php?c1=1&co1=1&m3=1&incldead=0&descriptions=0&from=&to=&imdbgt=0&imdblt=10&uppedby=&imdb=&search=',1,'')

def DOWNLOAD():
    url=urllib.unquote_plus(params['url'])
    name=urllib.unquote_plus(params['name'])
    resp = opener.open(url)
    svar4 = resp.read()
    resp.close()
    valid_chars = "-_.() %s%s" % (string.ascii_letters, string.digits)
    cleanfilename = ''.join(c for c in name if c in valid_chars)
    torrent_filename = downloadPath + '/' + cleanfilename + '.torrent'
    torrent_file = open(torrent_filename, 'wb')
    torrent_file.write(svar4)
    torrent_file.close()

def TORRENTS(url):
    movies = [['null']*3 for i in range(25)]
    print 'three'
    resp = opener.open(url)
    print 'four'
    svar2 = resp.read()
    resp.close()
    items = re.compile('<a href="details\.php\?id=(.+?)&amp;hit=1">(.+?)</a>.+?<a href="http://www\.imdb\.com/title/tt(.+?)/">IMDB').findall(svar2)

    for i in range(0, len(items)):
        movies[i][0] = str('https://torrentsite.com/download.php?id=' + items[i][0])
        movies[i][1] = str(items[i][1])
        movies[i][2] = str('https://torrentsite.com/pic/imdb_poster_cache/' + items[i][2] + '_big.jpg')
        xbmc
        addLink(movies[i][1], movies[i][0], 2, movies[i][2])

url=None
name=None
mode=None

def get_params():
    param=[]
    paramstring=sys.argv[2]
    if len(paramstring)>=2:
        params=sys.argv[2]
        cleanedparams=params.replace('?','')
        if (params[len(params)-1]=='/'):
            params=params[0:len(params)-2]
        pairsofparams=cleanedparams.split('&')
        param={}
        for i in range(len(pairsofparams)):
            splitparams={}
            splitparams=pairsofparams[i].split('=')
            if (len(splitparams))==2:
                param[splitparams[0]]=splitparams[1]
    return param

params = get_params();

try:
        url=urllib.unquote_plus(params['url'])
except:
        pass
try:
        name=urllib.unquote_plus(params['name'])
except:
        pass
try:
        mode=int(params['mode'])
except:
        pass

if mode==1 or mode==2:
    cj = cookielib.CookieJar()
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)
    print 'one'
    resp = opener.open('https://torrentsite.com/login.php')
    print 'two'    
    svar3 = resp.read()
    resp.close()
    lols = re.compile('<input type="hidden" name="lol" value="(.+?)" />').findall(svar3)
    if len(lols) == 1:
        lol = str(lols[0])
        data = urllib.urlencode({'uname':username,'password':user_password,'lol':lol})
        resp = opener.open('https://torrentsite.com/takelogon.php', data)
        svar1 = resp.read()
        resp.close()

if mode==None or url==None or len(url)<1:
        CATEGORIES()

elif mode==1:
        TORRENTS(url)
        
elif mode==2:
        DOWNLOAD()
        TORRENTS(url)


xbmcplugin.endOfDirectory(int(sys.argv[1]))
  • Livingroom - C2D E8400, P5N7A-VM on a Samsung 46" LE46M86 FullHD via HDMI
  • Kitchen - ASRock 330 HT Displayed on a Samsung Lapfit 22" dual touch screen LD220Z
  • Bedroom - LG Laptop on a 32" tv
Reply
#20
Could you post a link where i could get this code to install? thanks
Reply
#21
unom Wrote:Could you post a link where i could get this code to install? thanks

What? the code is in the last post.

Anyways, here is the final project: http://forum.xbmc.org/showthread.php?tid=97861
  • Livingroom - C2D E8400, P5N7A-VM on a Samsung 46" LE46M86 FullHD via HDMI
  • Kitchen - ASRock 330 HT Displayed on a Samsung Lapfit 22" dual touch screen LD220Z
  • Bedroom - LG Laptop on a 32" tv
Reply

Logout Mark Read Team Forum Stats Members Help
Torrent browser and downloader for site X0