Skip to content

Commit

Permalink
reinstate search functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
qzdl committed Feb 7, 2020
1 parent 2f9d8be commit 6efa5d0
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 137 deletions.
10 changes: 0 additions & 10 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,24 +1,14 @@
beautifulsoup4==4.8.0
cachetools==3.1.1
certifi==2019.6.16
chardet==3.0.4
fuzzywuzzy==0.17.0
google-api-python-client==1.7.11
google-auth==1.6.3
google-auth-httplib2==0.0.3
google-auth-oauthlib==0.4.0
httplib2==0.13.1
idna==2.8
oauthlib==3.1.0
objectpath==0.6.1
pyasn1==0.4.7
pyasn1-modules==0.2.6
python-Levenshtein==0.12.0
requests==2.22.0
requests-oauthlib==1.2.0
rsa==4.0
six==1.12.0
soupsieve==1.9.3
spotipy==2.4.4
uritemplate==3.0.0
urllib3==1.25.3
15 changes: 12 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,22 @@
long_description=long_description,
long_description_content_type="text/markdown",
url="https://github.com/qzdl/samplify",
packages=setuptools.find_packages('src', 'src/tools'),
packages=setuptools.find_packages('src' 'platforms'),
package_dir={'': 'src'},
install_requires=[
"BeautifulSoup4",
"objectpath==0.6.1",
"beautifulsoup4==4.8.0",
"fuzzywuzzy==0.17.0",
"google-api-python-client==1.7.11",
"google-auth==1.6.3",
"google-auth-httplib2==0.0.3",
"google-auth-oauthlib==0.4.0",
"objectpath==0.6.1",
"python-Levenshtein==0.12.0",
"requests==2.22.0",
"rsa==4.0",
"six==1.12.0",
"soupsieve==1.9.3",
"urllib3==1.25.3",
"spotipy @ git+https://github.com/qzdl/spotipy.git",
],
# dependency_links=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
from spotipy.oauth2 import SpotifyClientCredentials
from spotipy import util

from config import config
from samplify.config import config

SPOTIFY = 'spotify'
YOUTUBE = 'youtube'
STDOUT = 'stdout'

def get_platform(name):
if name == SPOTIFY:
Expand Down Expand Up @@ -246,3 +247,7 @@ def add_item_to_playlist(self, playlist_id, item_id):
}
}) # end insert
return add_request.execute() # yields body of request


class StdOut(Platform):
pass
5 changes: 0 additions & 5 deletions src/samplify/platforms/spotify.py

This file was deleted.

72 changes: 0 additions & 72 deletions src/samplify/platforms/youtube.py

This file was deleted.

6 changes: 3 additions & 3 deletions src/samplify/sample_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from samplify.tools.logger import Logger
from samplify.tools import direction as d

from samplify.platforms import platform
import samplify.platform as platform
import samplify.config as cfg

# uri => spotify:album:2laBNOqPW85M3js7qCYhKt
Expand Down Expand Up @@ -45,7 +45,7 @@ def samplify(self, options):
def from_search(self, search_term, content_type,
direction=None, output_name=None, output_type=None):
options = Options()
result = self.input_platform.search(search_term)
builder, result = self.input_platform.search(search_term)
self.log(message=f'Searched for "{search_term}"',
function='from_search',
data=result)
Expand All @@ -55,7 +55,7 @@ def from_search(self, search_term, content_type,
# build objectpath query & get first result
tree_obj = objectpath.Tree(result)
search_mod = '.album' if options.type_is_album(content_type) else ''
query = f'$.tracks.items{search_mod}.(name, uri)'
query = f'${search_mod}.(name, uri)'
queried = json.loads(json.dumps(tuple(tree_obj.execute(query))))[0]

options.parent_name = queried['name']
Expand Down
85 changes: 44 additions & 41 deletions src/samplify/samplify.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import argparse
from samplify.platforms import platform
import samplify.platform as platform
from samplify.sample_finder import Samplify
from samplify.tools.options import Options
"""
Expand All @@ -9,66 +9,71 @@
def main():
options = Options()
parser = argparse.ArgumentParser()
i_platform_group = parser.add_mutually_exclusive_group(required=True)

# input platform, default = platform.SPOTIFY
i_platform_group = parser.add_mutually_exclusive_group(required=False)
i_platform_group.add_argument(
'--input-spotify',
action="store_const",
const=platform.SPOTIFY,
dest='i_platform'
)
dest='i_platform')

o_platform_group = parser.add_mutually_exclusive_group(required=True)
# output platform, default = platform.SPOTIFY
o_platform_group = parser.add_mutually_exclusive_group(required=False)
o_platform_group.add_argument(
'--output-spotify',
action="store_const",
const=platform.SPOTIFY,
dest='o_platform'
)
dest='o_platform')

o_platform_group.add_argument(
'--output-youtube',
action="store_const",
const=platform.YOUTUBE,
dest='o_platform'
)
dest='o_platform')

o_platform_group.add_argument(
'--output-stdout',
action='store_const',
const=platform.STDOUT,
dest='o_platform')

reference_group = parser.add_mutually_exclusive_group(required=True)
reference_group.add_argument(
'-l',
'--link',
help='Click "Share" > "Copy Link"'
)
help='Click "Share" > "Copy Link"')

reference_group.add_argument(
'-s',
'--search',
help='Search as you would in the app'
)
help='Search as you would in the app')

content_group = parser.add_mutually_exclusive_group(required=True)
content_group.add_argument(
'--album',
action="store_const",
const=options.ALBUM,
dest='content_type'
)
dest='content_type')

content_group.add_argument(
'--playlist',
action="store_const",
const=options.PLAYLIST,
dest='content_type'
)
dest='content_type')

content_group.add_argument(
'--song',
action="store_const",
const=options.SONG,
dest='content_type'
)
dest='content_type')

# FIXME: current song can't work with '--search'
content_group.add_argument(
'--current-song',
action="store_const",
const=options.CURRENT_SONG,
dest='content_type'
)
dest='content_type')

parser.add_argument("--direction")
parser.add_argument("--output-name")
Expand All @@ -81,70 +86,68 @@ def main():
help='Include function detail',
action="store_const",
const=1,
dest='verbosity'
)
dest='verbosity')

debug_group.add_argument(
'-vv',
help='Multiline, include limited data',
action="store_const",
const=2,
dest='verbosity'
)
dest='verbosity')

debug_group.add_argument(
'-vvv',
help='Multiline, include full data',
action="store_const",
const=3,
dest='verbosity'
)
dest='verbosity')

args = parser.parse_args()

samplify = Samplify(
verbosity=args.verbosity or 0,
input_platform=args.i_platform,
output_platform=args.o_platform,
);
result = None
input_platform=args.i_platform or platform.SPOTIFY,
output_platform=args.o_platform or platform.SPOTIFY);

result = None
if args.search:
result = samplify.from_search(
search_term=args.search,
direction=args.direction,
content_type=args.content_type,
output_name=args.output_name,
output_type=args.output_type
)
output_type=args.output_type)

elif options.type_is_playlist(args.content_type):
result = samplify.playlist(
reference=args.link,
direction=args.direction,
output_name=args.output_name,
output_type=args.output_type,
username=args.username
)
username=args.username)

elif options.type_is_album(args.content_type):
result = samplify.album(
reference=args.link,
direction=args.direction,
output_name=args.output_name,
output_type=args.output_type
)
output_type=args.output_type)

elif options.type_is_song(args.content_type):
result = samplify.song(
reference=args.link,
direction=args.direction,
output_name=args.output_name,
output_type=args.output_type,
username=args.username
)
username=args.username)

elif options.type_is_current_song(args.content_type):
result = samplify.current_song(
reference=args.link,
direction=args.direction,
output_name=args.output_name,
output_type=args.output_type,
username=args.username
)
username=args.username)

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion src/samplify/tools/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class Logger:
def __init__(self, verbosity, log_file):
self.verbosity = verbosity
self.log_file = f'logs/{log_file}.log'
self.log_file = f'{log_file}.log'
self.logs = []
self._log(f'verbosity == {verbosity}')
self._log(f'log_file == {log_file}')
Expand Down
2 changes: 1 addition & 1 deletion src/samplify/tools/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,4 @@ def generate(self, reference, direction=None, content_type=None, scope=None,
self.output_name = output_name
self.output_type = output_type if output_type else self.CREATE_ONLY
self.scope = scope
self.username = username if username else config.username
self.username = username if username else config.config.username

0 comments on commit 6efa5d0

Please sign in to comment.