Skip to content

Commit

Permalink
Add search content support
Browse files Browse the repository at this point in the history
Fix readme
  • Loading branch information
KOL committed Oct 12, 2014
1 parent 424b5ef commit 214b604
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 25 deletions.
67 changes: 58 additions & 9 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ def VideoMainMenu():
title=L('My friends')
))

oc.add(InputDirectoryObject(
key=Callback(Search, search_type='video', title=L('Search Video')),
title=L('Search'), prompt=L('Search Video')
))

return AddVideoAlbums(oc, Dict['user_id'])


Expand Down Expand Up @@ -278,6 +283,11 @@ def MusicMainMenu():
title=L('My friends')
))

oc.add(InputDirectoryObject(
key=Callback(Search, search_type='audio', title=L('Search Music')),
title=L('Search'), prompt=L('Search Music')
))

return AddMusicAlbums(oc, Dict['user_id'])


Expand Down Expand Up @@ -417,6 +427,54 @@ def GetTrackObject(item):
# Common
###############################################################################

def Search(query, title=L('Search'), search_type='video', offset=0):

is_video = search_type == 'video'

params = {
'sort': 2,
'offset': offset,
'count': VK_LIMIT,
'q': query
}

if is_video:
if Prefs['search_hd']:
params['hd'] = 1
if Prefs['search_adult']:
params['adult'] = 1

res = ApiRequest(search_type+'.search', params)

if not res or not res['count']:
return ObjectContainer(
header=L('Error'),
message=L('No entries found')
)

oc = ObjectContainer(title2=(u'%s' % title), replace_parent=(offset > 0))

method = GetVideoObject if is_video else GetTrackObject

for item in res['items']:
oc.add(method(item))

offset = int(offset)+VK_LIMIT
if offset < res['count']:
oc.add(NextPageObject(
key=Callback(
Search,
query=query,
title=title,
search_type=search_type,
offset=offset
),
title=L('Next page')
))

return oc


def NormalizeExternalUrl(url):
# Rutube service crutch
if Regex('//rutube.ru/[^/]+/embed/[0-9]+').search(url):
Expand Down Expand Up @@ -512,15 +570,6 @@ def GetFriends(callback_action, callback_page, uid, offset):
return oc


def Notimplemented():
return MessageContainer(
L('Not implemented'),
L('In real life, you would probably perform some search using ' +
'python\nand then build a MediaContainer with items\nfor ' +
'the results')
)


def ApiRequest(method, params):
params['access_token'] = Dict['token']
params['v'] = VK_VERSION
Expand Down
41 changes: 27 additions & 14 deletions Contents/DefaultPrefs.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
[
{
"id": "username",
"type": "text",
"label": "Username",
"default": ""
},
{
"id": "password",
"type": "text",
"label": "Password",
"default": "",
"option": "hidden"
}
[
{
"id": "username",
"type": "text",
"label": "Username",
"default": ""
},
{
"id": "password",
"type": "text",
"label": "Password",
"default": "",
"option": "hidden"
},
{
"id": "search_hd",
"type": "bool",
"label": "Search HD only",
"default": "true",
},
{
"id": "search_adult",
"type": "bool",
"label": "Allow search adult",
"default": "false",
}

]
2 changes: 1 addition & 1 deletion Contents/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<key>CFBundleSignature</key>
<string>hook</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<string>1.1</string>

<key>PlexClientPlatforms</key>
<string>*</string>
Expand Down
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
VKontakte Plex Plugin
=====

VKontakte Plex Plugin allows to browse media content from largest russian social networking service [VKontakte](http://vk.com/) using [Plex Media Center](http://plex.tv/).
VKontakte Plex Plugin allows to browse media content from largest russian social networking service [VKontakte](http://vk.com/) using [Plex Media Server](http://plex.tv/).


Current status
Expand All @@ -10,6 +10,7 @@ Current status
* Support video and music
* Support albums
* Support friends and groups media content
* Support video and music searching


Installation
Expand Down

0 comments on commit 214b604

Please sign in to comment.