Skip to content

Commit

Permalink
Issue #26 disable search for non all access
Browse files Browse the repository at this point in the history
 - turn off aa search for non subscribed accounts. searching in the
   local library will still be supported.
  • Loading branch information
soulfx committed Dec 6, 2015
1 parent 1f05240 commit 7af2e7a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 1 addition & 2 deletions ImportList.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ def search_for_track(details):
if not len(query):
query = track
dlog('aa search query:'+query)
aa_results = api.search_all_access(query,max_results=7).get(
'song_hits')
aa_results = aa_search(query,7)
dlog('aa search results: '+str(len(aa_results)))
search_results.extend(aa_results)

Expand Down
20 changes: 19 additions & 1 deletion common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from collections import Counter
from gmusicapi import Mobileclient
from gmusicapi.exceptions import CallFailure
from preferences import *
import time
import getpass
Expand All @@ -19,6 +20,9 @@
# provide a shortcut for track_info_separator
tsep = track_info_separator

# flag indicating if account is all access capable
allaccess = True

# check for debug set via cmd line
if '-dDEBUG' in sys.argv:
debug = True
Expand Down Expand Up @@ -58,9 +62,23 @@ def dlog(message):
def plog(message):
log(message, nl = False)

# search all access
def aa_search(search_string,max_results):
global allaccess
results = []
if allaccess:
try:
results = api.search_all_access(search_string,
max_results=max_results).get('song_hits')
except CallFailure:
allaccess = False
log('WARNING no all access subscription detected. '+
' all access search disabled.')
return results

# gets the track details available for google tracks
def get_google_track_details(sample_song = 'one u2'):
results = api.search_all_access(sample_song,max_results=1).get('song_hits')
results = aa_search(sample_song,1)
if len(results):
return (results[0].get('track').keys())
return "['title','artist','album']"
Expand Down

0 comments on commit 7af2e7a

Please sign in to comment.