Skip to content

Commit

Permalink
- Fix subscriptions pagination (workaround over youtube bug)
Browse files Browse the repository at this point in the history
  • Loading branch information
KOL committed Jun 1, 2015
1 parent 5479883 commit cb4d848
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
20 changes: 15 additions & 5 deletions Contents/Code/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,12 +669,16 @@ def AddPlaylists(oc, uid, offset=None):
return oc


def AddSubscriptions(oc, uid, offset=None):
def AddSubscriptions(oc, uid, offset=0):

# TODO - temporary workaround while YT bug not fixed
offset = int(offset)
limit = GetLimitForOC(oc)

res = ApiRequest('subscriptions', ApiGetParams(
uid=uid,
limit=GetLimitForOC(oc),
offset=offset,
limit=limit,
offset=Video.CalculateOffset(offset),
order=str(Prefs['subscriptions_order']).lower()
))

Expand All @@ -693,13 +697,19 @@ def AddSubscriptions(oc, uid, offset=None):
thumb=GetThumbFromSnippet(item),
))

if 'nextPageToken' in res:
# TODO - temporary workaround while YT bug not fixed
# if 'nextPageToken' in res:
# offset = res['nextPageToken']
offset += limit
if 'pageInfo' in res and (
res['pageInfo']['totalResults'] > offset
):
oc.add(NextPageObject(
key=Callback(
Subscriptions,
uid=uid,
title=oc.title2,
offset=res['nextPageToken'],
offset=offset,
),
title=u'%s' % L('More subscriptions'),
thumb=ICONS['next']
Expand Down
36 changes: 36 additions & 0 deletions Contents/Services/Shared Code/video.pys
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,42 @@ def GetUrlFromStream(item):
return ret


def CalculateOffset(position):
'''
Workaround for YT bug
https://code.google.com/p/gdata-issues/issues/detail?id=7163
Original on:
https://gist.github.com/bromix/d159787a63f9d7b00036
'''
if not position:
return None

low = 'AEIMQUYcgkosw048'
high = 'ABCDEFGHIJKLMNOP'
len_low = len(low)
len_high = len(high)

overflow_token = 'Q'
if position >= 128:
overflow_token_iteration = position // 128
overflow_token = '%sE' % high[overflow_token_iteration]
pass
low_iteration = position % len_low

# at this position the iteration starts with 'I' again (after 'P')
if position >= 256:
multiplier = (position // 128) - 1
position -= 128 * multiplier
pass
high_iteration = (position / len_low) % len_high

return 'C%s%s%sAA' % (
high[high_iteration],
low[low_iteration],
overflow_token
)


def DecryptSignature(s):
key = '-'.join([str(len(p)) for p in s.split('.')])
json_obj = JSON.ObjectFromURL(
Expand Down

0 comments on commit cb4d848

Please sign in to comment.