WISE unpacker python port

fdm

New member
Apr 21, 2013
9
0
0
This is a port of my WISE unpacker from lua to python. WISE has very recently shown up in use with the hosts videoweed, movshare, nowvideo, novamov, and divxstage.

http://pastebin.com/K46TdpiA

You can pass the entire page to unwise_process() and it will unpack every packed JS block, including those that are embedded. Additionally you can call resolve_var() to return the correct variable when it is not explicitly set.
 

ghizzu

New member
May 21, 2012
7
0
0
Great job, and it works like a charm!
@eldorado: I think this should be added as a lib in urlresolver
 
Last edited:

mindgame

New member
Apr 13, 2013
119
0
0
Has anyone used this to make working resolvers for the listed hosts? Or will we have to wait until it is added as a lib in urlresolver?
 

fdm

New member
Apr 21, 2013
9
0
0
Has anyone used this to make working resolvers for the listed hosts? Or will we have to wait until it is added as a lib in urlresolver?
The only incompatibility is the use of print on line 76 of the example that would need to be changed for xbmc logging or removed. It does work fine if you insert and call those functions, but you might as well wait unless you really need to use those hosts. I'm sure the problem will be fixed soon anyway.

In hindsight, unwise_process should probably capture and count the occurrences of \(\s*\w+\s*\<\s*(\d+)\s*\) and pass them to the packer instead of just counting initial variables and assuming the first 5 characters are for the protection. That, and as a hole it's not very pythonic and might not follow existing code practices. It's more a rough draft or an example of how it could be done than something that could be merged.
 
Last edited:

ghizzu

New member
May 21, 2012
7
0
0
Has anyone used this to make working resolvers for the listed hosts? Or will we have to wait until it is added as a lib in urlresolver?
Yes, I've done a quick fix for nowvideo/novamov and it works. But it's better to wait the official version.
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
My coding time is limited, so if anyone can post up some code of the fixes would be appreciated.. and yes sounds like this should be a new lib available in urlresolver
 

ghizzu

New member
May 21, 2012
7
0
0
Feel like sharing? A use at your own risk scenario?
ok, at your own risk:

1) save the pastebin in the first post as unwise.py in the script.module.urlresolver/lib/urlresolver/plugins/lib folder. Delete or comment out the last 3 lines.

2) save the following as novamov.py in the script.module.urlresolver/lib/urlresolver/plugins/ folder (make a backup copy of the old file, just in case)

Code:
"""
    urlresolver XBMC Addon
    Copyright (C) 2011 t0mm0

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import re, urllib2, os
from t0mm0.common.net import Net
from urlresolver import common
from urlresolver.plugnplay.interfaces import UrlResolver
from urlresolver.plugnplay.interfaces import PluginSettings
from urlresolver.plugnplay import Plugin
from lib import unwise

#SET ERROR_LOGO# THANKS TO VOINAGE, BSTRDMKR, ELDORADO
error_logo = os.path.join(common.addon_path, 'resources', 'images', 'redx.png')

class NovamovResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "novamov"


    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()


    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        #find key
        r=None
        try:
            html = self.net.http_GET(web_url).content
            
            test = unwise.unwise_process(html)
            #print test
            filekey = unwise.resolve_var(test, "flashvars.filekey")
            filename = unwise.resolve_var(test, "flashvars.file")
            cid2 = unwise.resolve_var(test, "flashvars.cid2")


            #get stream url from api
            if 'movshare' in host:
                api = 'http://www.movshare.net/api/player.api.php?key=%s&file=%s' % (filekey, filename)
            elif 'nowvideo' in host:
                api = 'http://www.nowvideo.eu/api/player.api.php?key=%s&file=%s' % (filekey, filename)
            elif 'novamov' in host:
                api = 'http://www.novamov.com/api/player.api.php?key=%s&file=%s&cid2=%s' % (filekey, filename, cid2)
                api = api + '&cid3=undefined&cid=1&numOfErrors=0&user=undefined&pass=undefined'
            print api
            html = self.net.http_GET(api).content
        
            r = re.search('url=(.+?)&title', html)
            if r:
                stream_url = r.group(1)
                stream_url = re.sub('%3A',':',stream_url)
                stream_url = re.sub('%2F','/',stream_url)
            else:
                r = re.search('file no longer exists',html)
                if r:
                    raise Exception ('File Not Found or removed')
            
            return stream_url
        except urllib2.URLError, e:
            common.addon.log_error('Novamov: got http error %d fetching %s' %
                                    (e.code, web_url))
            return False
        except Exception, e:
            common.addon.log_error('**** Novamov Error occured: %s' % e)
            common.addon.show_small_popup(title='[B][COLOR white]NOVAMOV[/COLOR][/B]', msg='[COLOR red]%s[/COLOR]' % e, delay=5000, image=error_logo)
            return False

        
    def get_url(self, host, media_id):
        if 'movshare' in host:
            return 'http://www.movshare.net/video/%s' % media_id
        elif 'nowvideo' in host:
            return 'http://www.nowvideo.eu/video/%s' % media_id
        elif 'novamov' in host:
            return 'http://www.novamov.com/video/%s' % media_id

            
    def get_host_and_id(self, url):
        if 'nowvideo' in url:
            r = re.search('http://(www.|embed.nowvideo.eu)/(?:video/|embed.php\?v=([0-9a-z]+)&width)', url) 
        if 'movshare' in url:
            r = re.search('//(www.movshare.net)/(?:video|embed)/([0-9a-z]+)', url)
        else:
            r = re.search('//(?:embed.)?(.+?)/(?:video/|embed.php\?v=)' + 
                      '([0-9a-z]+)', url)
        if r:
            return r.groups()
        else:
            return False


    def valid_url(self, url, host):
        if self.get_setting('enabled') == 'false': return False
        return re.match('http://(www.|embed.)?no.+?/(video/|embed.php\?)', url) or 'novamov' in host or re.match('http://(?:www.)?movshare.net/(?:video|embed)/',url) or 'movshare' in host or re.match('http://(www.|embed.)?nowvideo.(?:eu)/(video/|embed.php\?)' +
                        '(?:[0-9a-z]+|width)', url) or 'nowvideo' in host
I've only tried nowvideo, don't know about novamov or movshare.
Update: novamov was broken, now it works. Movshare uses wise AND packed js so I think it will need
some more work.
 
Last edited:

msenoz

New member
Sep 26, 2012
35
0
0
ok, at your own risk:

1) save the pastebin in the first post as unwise.py in the script.module.urlresolver/lib/urlresolver/plugins/lib folder. Delete or comment out the last 3 lines.

2) save the following as novamov.py in the script.module.urlresolver/lib/urlresolver/plugins/ folder (make a backup copy of the old file, just in case)

Code:
"""
    urlresolver XBMC Addon
    Copyright (C) 2011 t0mm0

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
"""

import re, urllib2, os
from t0mm0.common.net import Net
from urlresolver import common
from urlresolver.plugnplay.interfaces import UrlResolver
from urlresolver.plugnplay.interfaces import PluginSettings
from urlresolver.plugnplay import Plugin
from lib import unwise

#SET ERROR_LOGO# THANKS TO VOINAGE, BSTRDMKR, ELDORADO
error_logo = os.path.join(common.addon_path, 'resources', 'images', 'redx.png')

class NovamovResolver(Plugin, UrlResolver, PluginSettings):
    implements = [UrlResolver, PluginSettings]
    name = "novamov"


    def __init__(self):
        p = self.get_setting('priority') or 100
        self.priority = int(p)
        self.net = Net()


    def get_media_url(self, host, media_id):
        web_url = self.get_url(host, media_id)
        #find key
        r=None
        try:
            html = self.net.http_GET(web_url).content
            
            test = unwise.unwise_process(html)
            #print test
            filekey = unwise.resolve_var(test, "flashvars.filekey")
            filename = unwise.resolve_var(test, "flashvars.file")
            cid2 = unwise.resolve_var(test, "flashvars.cid2")


            #get stream url from api
            if 'movshare' in host:
                api = 'http://www.movshare.net/api/player.api.php?key=%s&file=%s' % (filekey, filename)
            elif 'nowvideo' in host:
                api = 'http://www.nowvideo.eu/api/player.api.php?key=%s&file=%s' % (filekey, filename)
            elif 'novamov' in host:
                api = 'http://www.novamov.com/api/player.api.php?key=%s&file=%s&cid2=%s' % (filekey, filename, cid2)
                api = api + '&cid3=undefined&cid=1&numOfErrors=0&user=undefined&pass=undefined'
            print api
            html = self.net.http_GET(api).content
        
            r = re.search('url=(.+?)&title', html)
            if r:
                stream_url = r.group(1)
                stream_url = re.sub('%3A',':',stream_url)
                stream_url = re.sub('%2F','/',stream_url)
            else:
                r = re.search('file no longer exists',html)
                if r:
                    raise Exception ('File Not Found or removed')
            
            return stream_url
        except urllib2.URLError, e:
            common.addon.log_error('Novamov: got http error %d fetching %s' %
                                    (e.code, web_url))
            return False
        except Exception, e:
            common.addon.log_error('**** Novamov Error occured: %s' % e)
            common.addon.show_small_popup(title='[B][COLOR white]NOVAMOV[/COLOR][/B]', msg='[COLOR red]%s[/COLOR]' % e, delay=5000, image=error_logo)
            return False

        
    def get_url(self, host, media_id):
        if 'movshare' in host:
            return 'http://www.movshare.net/video/%s' % media_id
        elif 'nowvideo' in host:
            return 'http://www.nowvideo.eu/video/%s' % media_id
        elif 'novamov' in host:
            return 'http://www.novamov.com/video/%s' % media_id

            
    def get_host_and_id(self, url):
        if 'nowvideo' in url:
            r = re.search('http://(www.|embed.nowvideo.eu)/(?:video/|embed.php\?v=([0-9a-z]+)&width)', url) 
        if 'movshare' in url:
            r = re.search('//(www.movshare.net)/(?:video|embed)/([0-9a-z]+)', url)
        else:
            r = re.search('//(?:embed.)?(.+?)/(?:video/|embed.php\?v=)' + 
                      '([0-9a-z]+)', url)
        if r:
            return r.groups()
        else:
            return False


    def valid_url(self, url, host):
        if self.get_setting('enabled') == 'false': return False
        return re.match('http://(www.|embed.)?no.+?/(video/|embed.php\?)', url) or 'novamov' in host or re.match('http://(?:www.)?movshare.net/(?:video|embed)/',url) or 'movshare' in host or re.match('http://(www.|embed.)?nowvideo.(?:eu)/(video/|embed.php\?)' +
                        '(?:[0-9a-z]+|width)', url) or 'nowvideo' in host
I've only tried nowvideo, don't know about novamov or movshare.
Update: novamov was broken, now it works. Movshare uses wise AND packed js so I think it will need
some more work.
Movshare also works with the same way.
 

mindgame

New member
Apr 13, 2013
119
0
0
Thanks. I followed the instructions and I can now resolve novamov and nowvideo. I had to keep the existing pastebin complete without deleting the bottom 3 lines or else I would get an error.
 

fdm

New member
Apr 21, 2013
9
0
0
I made a pull request that includes the unpacker and fixes for all 5 hosts that use it, so it should be fixed upstream soon.
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
Yes, thanks for that pull!

Just need time to go thru it, but quickly noticed some small changes need - we're just trying to establish some rules to make all addon dev's lives easier, nothing too crazy
 

Eldorado

Moderator
Staff member
May 7, 2012
990
0
16
I'm going to send out a beta today just as a safe guard then get another release out, these seem to be pretty popular hosts

@Highway99 - where are you? I don't get responses from you when I make comments on your git pull requests, your latest one needs some small changes and needs to be re-based, I'm not able to auto-merge it