Commit [d91ccb] Maximize Restore History

[plugin.video.wimp] updated to version 0.7.0. thanks sphere

spiff spiff 2012-03-07

added plugin.video.wimp/resources/language/German/strings.xml
added plugin.video.wimp/resources/lib/__init__.py
added plugin.video.wimp/resources/lib/scraper.py
added plugin.video.wimp/resources/__init__.py
removed plugin.video.wimp/resources/images
removed plugin.video.wimp/resources/images/archives.png
removed plugin.video.wimp/resources/images/back.png
changed plugin.video.wimp/resources/language/English/strings.xml
changed plugin.video.wimp/resources/settings.xml
changed plugin.video.wimp/addon.xml
changed plugin.video.wimp/changelog.txt
copied plugin.video.wimp/default.py -> plugin.video.wimp/addon.py
plugin.video.wimp/resources/language/German/strings.xml Diff Switch to side-by-side view
Loading...
plugin.video.wimp/resources/lib/__init__.py Diff Switch to side-by-side view
Loading...
plugin.video.wimp/resources/lib/scraper.py Diff Switch to side-by-side view
Loading...
plugin.video.wimp/resources/__init__.py Diff Switch to side-by-side view
Loading...
plugin.video.wimp/resources/language/English/strings.xml Diff Switch to side-by-side view
Loading...
plugin.video.wimp/resources/settings.xml Diff Switch to side-by-side view
Loading...
plugin.video.wimp/addon.xml Diff Switch to side-by-side view
Loading...
plugin.video.wimp/changelog.txt Diff Switch to side-by-side view
Loading...
plugin.video.wimp/default.py to plugin.video.wimp/addon.py
--- a/plugin.video.wimp/default.py
+++ b/plugin.video.wimp/addon.py
@@ -1,232 +1,134 @@
-# Wimp.com by Insayne
-
-import os,sys,time
-import urllib,urllib2,re
-import xbmcplugin,xbmcgui,xbmcaddon
-
-# plugin Constants
-__plugin__ = "Wimp.com"
-__author__ = "Insayne"
-__url__ = "http://code.google.com/p/insayne-projects/"
-__svn_url__ = "https://insayne-projects.googlecode.com/svn/trunk/XBMC/Video/plugin.video.wimp/"
-__version__ = "0.6"
-__svn_revision__ = "$Revision$"
-__XBMC_Revision__ = xbmc.getInfoLabel('System.BuildVersion')
-__settings__ = xbmcaddon.Addon(id='plugin.video.wimp')
-
-# Global Setting Variables
-set_video_type = __settings__.getSetting( "video_type" )
-
-# Generates the main Index
-def Generate_Index():
-	url = 'http://wimp.com/'
-	req = urllib2.Request(url)
-	response = urllib2.urlopen(req)
-	html=response.read()
-	response.close()
-	html = html.replace("\n", "")
-	html = html.replace("\r", "")
-	thumb = ''
-	regex = '<span class="video_date">(.+?)</span> - <a class=".+?" href="(.+?)">(.+?)</a><br/>'
-	videos = re.compile(regex).findall(html)
-	
-	for date,link,title in videos:
-		link = 'http://wimp.com' + link
-		title = "[" + date + "] " + cleanstring(remove_spaces(title))
-		addVideo(title,link,1, thumb)
-
-	root_path = xbmc.translatePath(__settings__.getAddonInfo('path'))
-	thumb = xbmc.translatePath(os.path.join( root_path, 'resources', 'images', 'archives.png'))
-	link = '1'
-	title = "[Archives]"
-	addDir(title,link,3, thumb)
-
-def get_archives():
-	# Request the Page
-	url = 'http://wimp.com/archives/'
-	req = urllib2.Request(url)
-	response = urllib2.urlopen(req)
-	html=response.read()
-	response.close()
-	html = html.replace("\n", "")
-	html = html.replace("\r", "")
-	thumb = ''
-	regex = '<a class="b" href="(.+?)">(.+?)</a><br/>'
-	videos = re.compile(regex).findall(html)
-	
-
-	
-	for link,title in videos:
-		link = 'http://wimp.com' + link
-		title = cleanstring(remove_spaces(title))
-		addDir(title,link,2, thumb)
-	
-	# Link back to Current Month
-	root_path = xbmc.translatePath(__settings__.getAddonInfo('path'))
-	thumb = xbmc.translatePath(os.path.join( root_path, 'resources', 'images', 'back.png'))
-	link = ""
-	title = "<< Back to Current Month"
-	addDir(title,link,4, thumb)
+import os
+from xbmcswift import Plugin, xbmcplugin, xbmcgui
+import resources.lib.scraper as scraper
 
 
-def Generate_archive_page(link):
-	# Request the Page
-	url = str(link)
-	req = urllib2.Request(url)
-	response = urllib2.urlopen(req)
-	html=response.read()
-	response.close()
-	html = html.replace("\n", "")
-	html = html.replace("\r", "")
-	thumb = ''
-	regex = '<span class="video_date">(.+?)</span> - <a class=".+?" href="(.+?)">(.+?)</a><br/>'
-	videos = re.compile(regex).findall(html)
-	
-	for date,link,title in videos:
-		link = 'http://wimp.com' + link
-		title = "[" + date + "] " + cleanstring(remove_spaces(title))
-		addVideo(title,link,1, thumb)
-	
-	root_path = xbmc.translatePath(__settings__.getAddonInfo('path'))
-	thumb = xbmc.translatePath(os.path.join( root_path, 'resources', 'images', 'archives.png'))
-	link = ""
-	title = "<< Back to Archives Listing"
-	addDir(title,link,3, thumb)
-	
-	
-def Play_Video(url):
-	global set_video_type
-	
-	# Request the Page
-	req = urllib2.Request(url)
-	response = urllib2.urlopen(req)
-	html=response.read()
-	response.close()
-		
-	html = html.replace("\n", "")
-	html = html.replace("\r", "")
+class Plugin_adv(Plugin):
 
-	if "www.dump.com" in response.geturl():
-		regex = '<script type="text/javascript">jwplayer\(.+?\).setup\(.+?file: "(.+?)".+?</script>'
-		video_urls = re.compile(regex).findall(html)
-		videos = []
-		for link in video_urls:
-			videos.append(link)
-		if len(videos) > 0:
-			return videos[0]
-		else:
-			return "ERROR"
-			
-	else:
-		# Get the Stream Type
-		if set_video_type=="0":
-			# Flash 
-			regex = 's1.addVariable\("file","(.+?)"'
-		elif set_video_type=="1":
-			# Mobile Device
-			regex = '<div id="player">.+?<a target="_self".+?href="(.+?)".+?</div>'
-		else:
-			# Fallback to Flash
-			regex = 's1.addVariable\("file","(.+?)"'
-			
-		video_urls = re.compile(regex).findall(html)
-		videos = []
-		for link in video_urls:
-			videos.append(link)
-		
-		if len(videos) > 0:
-			return videos[0]
-		else:
-			return "ERROR"
+    def add_items(self, iterable, sort_method_ids=[]):
+        items = []
+        urls = []
+        for i, li_info in enumerate(iterable):
+            items.append(self._make_listitem(**li_info))
+            if self._mode in ['crawl', 'interactive', 'test']:
+                print '[%d] %s%s%s (%s)' % (i + 1, '', li_info.get('label'),
+                                            '', li_info.get('url'))
+                urls.append(li_info.get('url'))
+        if self._mode is 'xbmc':
+            xbmcplugin.addDirectoryItems(self.handle, items, len(items))
+            for id in sort_method_ids:
+                xbmcplugin.addSortMethod(self.handle, id)
+            xbmcplugin.endOfDirectory(self.handle, cacheToDisc=False)
+        return urls
 
-# Add Video
-def addVideo(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 } )
-	liz.setProperty("Fanart_image", iconimage)
-	liz.setProperty("IsPlayable","true")
-	ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=False)
-	return ok
-	
-# Add Directory
-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 } )
-	liz.setProperty("Fanart_image", iconimage)
-	ok=xbmcplugin.addDirectoryItem(handle=int(sys.argv[1]),url=u,listitem=liz,isFolder=True)
-	return ok
-
-# Clean the String 
-def cleanstring(string):
-	string = string.replace("&amp;", "&")
-	string = string.replace("&quot;", "\"")
-	return string
-
-# Remove double spaces, etc
-def remove_spaces(string):
-	newstrg=''
-	for word in string.split():
-		newstrg=newstrg+' '+word
-	return newstrg
-
-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()
-url=None
-name=None
-mode=None
-
-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==None or url==None or len(url)<1:
-	Generate_Index()
+    def set_resolved_url(self, url, title=None):
+        if self._mode in ['crawl', 'interactive', 'test']:
+            print 'ListItem resolved to %s' % url
+        li = xbmcgui.ListItem(path=url)
+        if title:
+            li.setLabel(title)
+        xbmcplugin.setResolvedUrl(self.handle, True, li)
+        if self._mode in ['interactive', 'crawl', 'test']:
+            return []
 
 
-elif mode==1:
-	video_url = Play_Video(url)
-	if video_url!="ERROR":
-		li=xbmcgui.ListItem(path = video_url)
-		xbmcplugin.setResolvedUrl(int(sys.argv[1]), True, li)
+plugin = Plugin_adv('Wimp.com', 'plugin.video.wimp', __file__)
 
-elif mode==2:
-	Generate_archive_page(url)
 
-elif mode==3:
-	get_archives()
+@plugin.route('/', default=True)
+def show_root():
+    log('show_root started')
+    categories = [{'label': plugin.get_string(30000),
+                   'url': plugin.url_for('show_current')},
+                  {'label': plugin.get_string(30001),
+                   'url': plugin.url_for('watch_random'),
+                   'is_folder': False,
+                   'is_playable': True},
+                  {'label': plugin.get_string(30002),
+                   'url': plugin.url_for('show_archive')},
+                  {'label': plugin.get_string(30003),
+                   'url': plugin.url_for('search')}]
+    return plugin.add_items(categories)
 
-elif mode==4:
-	Generate_Index()
-	
-xbmcplugin.setContent(handle=int(sys.argv[1]), content="movies" )
-xbmcplugin.endOfDirectory(int(sys.argv[1]))
+
+@plugin.route('/current/')
+def show_current():
+    log('show_current started')
+    videos = scraper.get_current_videos()
+    return __add_videos(videos)
+
+
+@plugin.route('/watch/<video_id>/')
+def watch_video(video_id):
+    log('watch_video started with video_id=%s' % video_id)
+    mobile = __mobile()
+    video_url, title = scraper.get_video_url(video_id, mobile=mobile)
+    log('watch_video finished with video_url=%s' % video_url)
+    return plugin.set_resolved_url(video_url)
+
+
+@plugin.route('/random/')
+def watch_random():
+    log('watch_random started')
+    mobile = __mobile()
+    video_url, title = scraper.get_random_video_url(mobile=mobile)
+    log('watch_random finished with video_url=%s' % video_url)
+    return plugin.set_resolved_url(video_url, title=title)
+
+
+@plugin.route('/archive/')
+def show_archive():
+    log('show_archive started')
+    archive_dates = scraper.get_archive_dates()
+    items = [{'label': archive_date['title'],
+              'url': plugin.url_for('show_archived_videos',
+                                    archive_id=archive_date['archive_id']),
+             } for archive_date in archive_dates]
+    return plugin.add_items(items)
+
+
+@plugin.route('/archive/<archive_id>/')
+def show_archived_videos(archive_id):
+    log('show_archived_videos started with archive_id: %s' % archive_id)
+    videos = scraper.get_videos_by_archive_date(archive_id)
+    return __add_videos(videos)
+
+
+@plugin.route('/search/')
+def search():
+    log('search start')
+    search_string = None
+    keyboard = xbmc.Keyboard('', plugin.get_string(30003))
+    keyboard.doModal()
+    if keyboard.isConfirmed() and keyboard.getText():
+        search_string = keyboard.getText()
+        log('search gots a string: "%s"' % search_string)
+        videos = scraper.get_search_result(search_string)
+        return __add_videos(videos)
+
+
+def __add_videos(videos):
+    __path = xbmc.translatePath(plugin._plugin.getAddonInfo('path'))
+    icon = os.path.join(__path, 'icon.png')
+    items = [{'label': video['title'],
+              'thumbnail': icon,
+              'url': plugin.url_for('watch_video',
+                                    video_id=video['video_id']),
+              'info': {'date': video['date']},
+              'is_folder': False,
+              'is_playable': True,
+             } for video in videos]
+    sort_methods = [xbmcplugin.SORT_METHOD_DATE,
+                    xbmcplugin.SORT_METHOD_LABEL]
+    return plugin.add_items(items, sort_method_ids=sort_methods)
+
+
+def __mobile():
+    return plugin.get_setting('pref_video') == '1'
+
+
+def log(msg):
+    xbmc.log('%s addon: %s' % ('wimp.com', msg))
+
+if __name__ == '__main__':
+    plugin.run()