remove requests, use downloadUrl instead

This commit is contained in:
faush01 2014-10-09 20:03:31 +11:00
parent 5d1479972d
commit aa2266bd97
7 changed files with 315 additions and 31 deletions

215
.gitignore vendored Normal file
View File

@ -0,0 +1,215 @@
#################
## Eclipse
#################
*.pydevproject
.project
.metadata
bin/
tmp/
*.tmp
*.bak
*.swp
*~.nib
local.properties
.classpath
.settings/
.loadpath
# External tool builders
.externalToolBuilders/
# Locally stored "Eclipse launch configurations"
*.launch
# CDT-specific
.cproject
# PDT-specific
.buildpath
#################
## Visual Studio
#################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
*.suo
*.user
*.sln.docstates
# Build results
[Dd]ebug/
[Rr]elease/
x64/
build/
[Bb]in/
[Oo]bj/
# MSTest test Results
[Tt]est[Rr]esult*/
[Bb]uild[Ll]og.*
*_i.c
*_p.c
*.ilk
*.meta
*.obj
*.pch
*.pdb
*.pgc
*.pgd
*.rsp
*.sbr
*.tlb
*.tli
*.tlh
*.tmp
*.tmp_proj
*.log
*.vspscc
*.vssscc
.builds
*.pidb
*.log
*.scc
# Visual C++ cache files
ipch/
*.aps
*.ncb
*.opensdf
*.sdf
*.cachefile
# Visual Studio profiler
*.psess
*.vsp
*.vspx
# Guidance Automation Toolkit
*.gpState
# ReSharper is a .NET coding add-in
_ReSharper*/
*.[Rr]e[Ss]harper
# TeamCity is a build add-in
_TeamCity*
# DotCover is a Code Coverage Tool
*.dotCover
# NCrunch
*.ncrunch*
.*crunch*.local.xml
# Installshield output folder
[Ee]xpress/
# DocProject is a documentation generator add-in
DocProject/buildhelp/
DocProject/Help/*.HxT
DocProject/Help/*.HxC
DocProject/Help/*.hhc
DocProject/Help/*.hhk
DocProject/Help/*.hhp
DocProject/Help/Html2
DocProject/Help/html
# Click-Once directory
publish/
# Publish Web Output
*.Publish.xml
*.pubxml
# NuGet Packages Directory
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
#packages/
# Windows Azure Build Output
csx
*.build.csdef
# Windows Store app package directory
AppPackages/
# Others
sql/
*.Cache
ClientBin/
[Ss]tyle[Cc]op.*
~$*
*~
*.dbmdl
*.[Pp]ublish.xml
*.pfx
*.publishsettings
# RIA/Silverlight projects
Generated_Code/
# Backup & report files from converting an old project file to a newer
# Visual Studio version. Backup files are not needed, because we have git ;-)
_UpgradeReport_Files/
Backup*/
UpgradeLog*.XML
UpgradeLog*.htm
# SQL Server files
App_Data/*.mdf
App_Data/*.ldf
#############
## Windows detritus
#############
# Windows image file caches
Thumbs.db
ehthumbs.db
# Folder config file
Desktop.ini
# Recycle Bin used on file shares
$RECYCLE.BIN/
# Mac crap
.DS_Store
#############
## Python
#############
*.py[co]
# Packages
*.egg
*.egg-info
dist/
build/
eggs/
parts/
var/
sdist/
develop-eggs/
.installed.cfg
# Installer logs
pip-log.txt
# Unit test / coverage reports
.coverage
.tox
#Translations
*.mo
#Mr Developer
.mr.developer.cfg

45
MBCon.pyproj Normal file
View File

@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{32210f10-ebc2-4c61-8d61-dfc843cf5f99}</ProjectGuid>
<ProjectHome />
<StartupFile>default.py</StartupFile>
<SearchPath />
<WorkingDirectory>.</WorkingDirectory>
<OutputPath>.</OutputPath>
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
<ItemGroup>
<Content Include="addon.xml" />
<Content Include="LICENSE.txt" />
<Content Include="icon.png" />
<Compile Include="default.py" />
<Compile Include="service.py" />
<Content Include="resources\mb3.png" />
<Compile Include="resources\__init__.py" />
<Compile Include="resources\lib\ArtworkLoader.py" />
<Compile Include="resources\lib\ClientInformation.py" />
<Compile Include="resources\lib\DisplayItems.py" />
<Compile Include="resources\lib\DownloadUtils.py" />
<Compile Include="resources\lib\ItemInfo.py" />
<Compile Include="resources\lib\MenuLoad.py" />
<Compile Include="resources\lib\PersonInfo.py" />
<Compile Include="resources\lib\SearchDialog.py" />
<Compile Include="resources\lib\Utils.py" />
<Compile Include="resources\lib\websocket.py" />
<Compile Include="resources\lib\WebSocketClient.py" />
<Compile Include="resources\lib\__init__.py" />
<Content Include="resources\media\BlankPoster.png" />
</ItemGroup>
<ItemGroup>
<Folder Include="resources" />
<Folder Include="resources\lib" />
<Folder Include="resources\media" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" />
</Project>

View File

@ -4,7 +4,6 @@
version="0.0.1"
provider-name="">
<requires>
<import addon="script.module.requests" version="1.1.0" />
<import addon="xbmc.python" version="2.1.0"/>
</requires>
<extension point="xbmc.python.pluginsource" library="default.py">

View File

@ -36,7 +36,6 @@ import inspect
import base64
import random
import datetime
import requests
from urlparse import urlparse
import cProfile
import pstats
@ -279,29 +278,25 @@ def getCollections(detailsString):
return collections
def markWatched (url):
authHeaders = downloadUtils.getAuthHeader()
resp = requests.post(url, data='', headers=authHeaders)
downloadUtils.downloadUrl(url, postBody="", type="POST")
WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("force_data_reload", "true")
xbmc.executebuiltin("Container.Refresh")
def markUnwatched (url):
authHeaders = downloadUtils.getAuthHeader()
resp = requests.delete(url, data='', headers=authHeaders)
downloadUtils.downloadUrl(url, type="DELETE")
WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("force_data_reload", "true")
xbmc.executebuiltin("Container.Refresh")
def markFavorite (url):
authHeaders = downloadUtils.getAuthHeader()
resp = requests.post(url, data='', headers=authHeaders)
downloadUtils.downloadUrl(url, postBody="", type="POST")
WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("force_data_reload", "true")
xbmc.executebuiltin("Container.Refresh")
def unmarkFavorite (url):
authHeaders = downloadUtils.getAuthHeader()
resp = requests.delete(url, data='', headers=authHeaders)
downloadUtils.downloadUrl(url, type="DELETE")
WINDOW = xbmcgui.Window( 10000 )
WINDOW.setProperty("force_data_reload", "true")
xbmc.executebuiltin("Container.Refresh")
@ -345,9 +340,7 @@ def delete (url):
printDebug('Deleting via URL: ' + url)
progress = xbmcgui.DialogProgress()
progress.create(__language__(30052), __language__(30053))
authHeaders = downloadUtils.getAuthHeader()
resp = requests.delete(url, data='', headers=authHeaders)
deleteSleep=0
downloadUtils.downloadUrl(url, type="DELETE")
progress.close()
xbmc.executebuiltin("Container.Refresh")

22
media.sln Normal file
View File

@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "MBCon", "MBCon.pyproj", "{32210F10-EBC2-4C61-8D61-DFC843CF5F99}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{32210F10-EBC2-4C61-8D61-DFC843CF5F99}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{32210F10-EBC2-4C61-8D61-DFC843CF5F99}.Debug|Any CPU.Build.0 = Debug|Any CPU
{32210F10-EBC2-4C61-8D61-DFC843CF5F99}.Release|Any CPU.ActiveCfg = Release|Any CPU
{32210F10-EBC2-4C61-8D61-DFC843CF5F99}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal

View File

@ -4,7 +4,6 @@ import xbmcaddon
import urllib
import urllib2
import httplib
import requests
import hashlib
import StringIO
import gzip
@ -175,13 +174,18 @@ class DownloadUtils():
headers = {'Accept-encoding': 'gzip', 'Authorization' : authString}
sha1 = hashlib.sha1(self.addonSettings.getSetting('password'))
resp = requests.post(url, data={'password':sha1.hexdigest(),'Username':self.addonSettings.getSetting('username')}, headers=headers)
code = str(resp.status_code)
result = resp.json()
accessToken = result.get("AccessToken")
if int(code) >= 200 and int(code) < 300 and accessToken != None:
messageData = "username=" + self.addonSettings.getSetting('username') + "&password=" + sha1.hexdigest()
resp = self.downloadUrl(url, postBody=messageData, type="POST", authenticate=False)
accessToken = None
try:
result = json.loads(resp)
accessToken = result.get("AccessToken")
except:
pass
if(accessToken != None):
self.logMsg("User Authenticated : " + accessToken)
WINDOW.setProperty("AccessToken", accessToken)
return accessToken
@ -190,19 +194,22 @@ class DownloadUtils():
WINDOW.setProperty("AccessToken", "")
return ""
def getAuthHeader(self):
def getAuthHeader(self, authenticate):
clientInfo = ClientInformation()
txt_mac = clientInfo.getMachineId()
version = clientInfo.getVersion()
userid = self.getUserId()
deviceName = self.addonSettings.getSetting('deviceName')
deviceName = deviceName.replace("\"", "_")
authString = "MediaBrowser UserId=\"" + userid + "\",Client=\"XBMC\",Device=\"" + deviceName + "\",DeviceId=\"" + txt_mac + "\",Version=\"" + version + "\""
#userid = self.getUserId()
#authString = "MediaBrowser UserId=\"" + userid + "\",Client=\"XBMC\",Device=\"" + deviceName + "\",DeviceId=\"" + txt_mac + "\",Version=\"" + version + "\""
authString = "MediaBrowser Client=\"XBMC\",Device=\"" + deviceName + "\",DeviceId=\"" + txt_mac + "\",Version=\"" + version + "\""
headers = {"Accept-encoding": "gzip", "Accept-Charset" : "UTF-8,*", "Authorization" : authString}
if(authenticate == False):
return headers
authToken = self.authenticate()
if(authToken != ""):
headers["X-MediaBrowser-Token"] = authToken
@ -210,7 +217,7 @@ class DownloadUtils():
xbmc.log("MBCon Authentication Header : " + str(headers))
return headers
def downloadUrl(self, url, suppress=False, type="GET", popup=0, authenticate=True):
def downloadUrl(self, url, suppress=False, postBody=None, type="GET", popup=0, authenticate=True):
self.logMsg("== ENTER: getURL ==")
link = ""
try:
@ -229,12 +236,16 @@ class DownloadUtils():
self.logMsg("urlPath = "+str(urlPath), level=2)
conn = httplib.HTTPConnection(server, timeout=20)
head = {}
if(authenticate):
head = self.getAuthHeader()
head = self.getAuthHeader(authenticate)
self.logMsg("HEADERS : " + str(head), level=1)
conn.request(method=type, url=urlPath, headers=head)
if(postBody != None):
head["Content-Type"] = "application/x-www-form-urlencoded"
self.logMsg("POST DATA : " + postBody)
conn.request(method=type, url=urlPath, body=postBody, headers=head)
else:
conn.request(method=type, url=urlPath, headers=head)
data = conn.getresponse()
self.logMsg("GET URL HEADERS : " + str(data.getheaders()), level=2)

View File

@ -5,7 +5,6 @@ import urllib
import httplib
import os
import time
import requests
import socket
import threading