Skip to content

Commit

Permalink
Merge pull request #3 from saleem-latif/bug-fix
Browse files Browse the repository at this point in the history
Fix a bug
  • Loading branch information
saleem-latif authored Sep 6, 2016
2 parents 46d68d6 + 7f4a257 commit 9be6e5a
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 66 deletions.
26 changes: 13 additions & 13 deletions youtube/parsers/channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ class ChannelListResponse(ResponseParser):
in the response.
"""
@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def etag(self):
return self.result['etag']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def kind(self):
return self.result['kind']

@property
@default_on_error(KeyError, None)
@default_on_error((KeyError, TypeError), None)
def next_page_token(self):
return self.result['nextPageToken']

@property
@default_on_error(KeyError, 1)
@default_on_error((KeyError, TypeError), 1)
def total_results(self):
return self.result['pageInfo']['totalResults']

@property
@default_on_error(KeyError, 1)
@default_on_error((KeyError, TypeError), 1)
def results_per_page(self):
return self.result['pageInfo']['resultsPerPage']

Expand All @@ -49,41 +49,41 @@ class Channel(ResponseParser):
more info about videos api https://developers.google.com/youtube/v3/docs/playlists/list
"""
@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def etag(self):
return self.result['etag']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def kind(self):
return self.result['kind']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def id(self):
return self.result['id']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def title(self):
return self.result['snippet']['title']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def description(self):
return self.result['snippet']['description']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def published_at(self):
return self.result['snippet']['publishedAt']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def custom_url(self):
return self.result['snippet']['customUrl']

@property
@default_on_error(KeyError, ThumbnailsParser(result={}))
@default_on_error((KeyError, TypeError), ThumbnailsParser(result={}))
def thumbnails(self):
return ThumbnailsParser(self.result['snippet']['thumbnails'])
10 changes: 5 additions & 5 deletions youtube/parsers/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,27 +29,27 @@ class ThumbnailsParser(ResponseParser):
Youtube API parser for thumbnails.
"""
@property
@default_on_error(KeyError, {})
@default_on_error((KeyError, TypeError), {})
def default(self):
return self.result['default']

@property
@default_on_error(KeyError, {})
@default_on_error((KeyError, TypeError), {})
def medium(self):
return self.result['medium']

@property
@default_on_error(KeyError, {})
@default_on_error((KeyError, TypeError), {})
def high(self):
return self.result['high']

@property
@default_on_error(KeyError, {})
@default_on_error((KeyError, TypeError), {})
def maxres(self):
return self.result['maxres']

@property
@default_on_error(KeyError, {})
@default_on_error((KeyError, TypeError), {})
def standard(self):
return self.result['standard']

Expand Down
30 changes: 15 additions & 15 deletions youtube/parsers/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ class PlaylistListResponse(ResponseParser):
in the response.
"""
@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def etag(self):
return self.result['etag']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def kind(self):
return self.result['kind']

@property
@default_on_error(KeyError, None)
@default_on_error((KeyError, TypeError), None)
def next_page_token(self):
return self.result['nextPageToken']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def region_code(self):
return self.result['regionCode']

@property
@default_on_error(KeyError, 1)
@default_on_error((KeyError, TypeError), 1)
def total_results(self):
return self.result['pageInfo']['totalResults']

@property
@default_on_error(KeyError, 1)
@default_on_error((KeyError, TypeError), 1)
def results_per_page(self):
return self.result['pageInfo']['resultsPerPage']

Expand All @@ -54,46 +54,46 @@ class Playlist(ResponseParser):
more info about videos api https://developers.google.com/youtube/v3/docs/playlists/list
"""
@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def etag(self):
return self.result['etag']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def kind(self):
return self.result['kind']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def id(self):
return self.result['id']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def channel_id(self):
return self.result['snippet']['channelId']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def title(self):
return self.result['snippet']['title']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def description(self):
return self.result['snippet']['description']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def channel_title(self):
return self.result['snippet']['channelTitle']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def published_at(self):
return self.result['snippet']['publishedAt']

@property
@default_on_error(KeyError, ThumbnailsParser({}))
@default_on_error((KeyError, TypeError), ThumbnailsParser({}))
def thumbnails(self):
return ThumbnailsParser(self.result['snippet']['thumbnails'])
34 changes: 17 additions & 17 deletions youtube/parsers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,32 +14,32 @@ class SearchResponse(ResponseParser):
in the response.
"""
@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def etag(self):
return self.result['etag']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def kind(self):
return self.result['kind']

@property
@default_on_error(KeyError, None)
@default_on_error((KeyError, TypeError), None)
def next_page_token(self):
return self.result['nextPageToken']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def region_code(self):
return self.result['regionCode']

@property
@default_on_error(KeyError, 1)
@default_on_error((KeyError, TypeError), 1)
def total_results(self):
return self.result['pageInfo']['totalResults']

@property
@default_on_error(KeyError, 1)
@default_on_error((KeyError, TypeError), 1)
def results_per_page(self):
return self.result['pageInfo']['resultsPerPage']

Expand All @@ -54,54 +54,54 @@ class SearchResult(ResponseParser):
more info about search api https://developers.google.com/youtube/v3/docs/search/list
"""
@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def etag(self):
return self.result['etag']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def kind(self):
return self.result['id']['kind']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def video_id(self):
return self.result['id']['videoId']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def channel_id(self):
try:
return self.result['id']['channelId']
except KeyError:
except (KeyError, TypeError):
return self.result['snippet']['channelId']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def playlist_id(self):
return self.result['id']['playlistId']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def title(self):
return self.result['snippet']['title']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def description(self):
return self.result['snippet']['description']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def channel_title(self):
return self.result['snippet']['channelTitle']

@property
@default_on_error(KeyError, '')
@default_on_error((KeyError, TypeError), '')
def published_at(self):
return self.result['snippet']['publishedAt']

@property
@default_on_error(KeyError, ThumbnailsParser({}))
@default_on_error((KeyError, TypeError), ThumbnailsParser({}))
def thumbnails(self):
return ThumbnailsParser(self.result['snippet']['thumbnails'])
Loading

0 comments on commit 9be6e5a

Please sign in to comment.