Skip to content

Commit

Permalink
Added Random Tracks
Browse files Browse the repository at this point in the history
+ minor fixes
  • Loading branch information
gordielachance authored and gordielachance committed Oct 4, 2016
1 parent 32f706f commit 73c6bd5
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## v2.0.3
Released 4 October 2016
* Random tracks submenu
* Download tracks
* Star tracks
* Context menu for downloading or marking items as favorite

## v2.0.2
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Contributions are welcome:
https://github.com/gordielachance/plugin.audio.subsonic

## Features
* Browse by artist, album, tracks, and playlists
* Browse by artist, albums (newest/most played/recently played/random), tracks (starred/random), and playlists
* Download songs
* Star songs

Expand Down
59 changes: 46 additions & 13 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ def menu_tracks(params):
'name': 'Starred tracks',
'thumb': None,
'is_stars_list': True
},
'tracks_random': {
'name': 'Random tracks',
'thumb': None
}
}

Expand Down Expand Up @@ -329,23 +333,22 @@ def list_albums(params):
if connection is False:
return

query_args_json = params['query_args']
query_args = json.loads(query_args_json)
#query
query_args = {}
try:
query_args_json = params['query_args']
query_args = json.loads(query_args_json)
except:
pass

#size
albums_per_page = int(Addon().get_setting('albums_per_page'))
query_args["size"] = albums_per_page

#offset
offset = int(params.get('page')) - 1;
offset = int(params.get('page',1)) - 1;
if offset > 0:
query_args["offset"] = offset * albums_per_page

#TO FIX this test is for pagination
#query_args["fromYear"] = 2016
#query_args["toYear"] = 2016
#query_args["ltype"] = 'byYear'


#debug
query_args_json = json.dumps(query_args)
Expand Down Expand Up @@ -482,6 +485,27 @@ def list_tracks(params):

listing = []

#query
query_args = {}
try:
query_args_json = params['query_args']
query_args = json.loads(query_args_json)
except:
pass

#size
tracks_per_page = int(Addon().get_setting('tracks_per_page'))
query_args["size"] = tracks_per_page

#offset
offset = int(params.get('page',1)) - 1;
if offset > 0:
query_args["offset"] = offset * tracks_per_page

#debug
query_args_json = json.dumps(query_args)
plugin.log('list_tracks with args:' + query_args_json);

# get connection
connection = get_connection()

Expand All @@ -493,7 +517,7 @@ def list_tracks(params):
items = connection.walk_album(params['album_id'])

# Playlist
if 'playlist_id' in params:
elif 'playlist_id' in params:
items = connection.walk_playlist(params['playlist_id'])

#TO FIX
Expand All @@ -503,9 +527,18 @@ def list_tracks(params):
# items[item]['tracknumber'] = tracknumber

# Starred
if menu_id == 'tracks_starred':
elif menu_id == 'tracks_starred':
items = connection.walk_tracks_starred()

# Random
elif menu_id == 'tracks_random':
items = connection.walk_tracks_random(**query_args)

# Filters
#else:
#TO WORK


# Iterate through items
key = 0;
for item in items:
Expand All @@ -514,8 +547,8 @@ def list_tracks(params):
key +=1

# Root menu
link_root = navigate_root()
listing.append(link_root)
#link_root = navigate_root()
#listing.append(link_root)

# Pagination if we've not reached the end of the lsit
# if type(items) != type(True): TO FIX
Expand Down

0 comments on commit 73c6bd5

Please sign in to comment.