def current_song(self, direction=None, output_name=None, output_type=None): """API for E2E rip of sample data from current song playing""" # scope required? options = Options() options.generate(reference=None, direction=direction, content_type=options.CURRENT_SONG, output_name=output_name, output_type=output_type) return self.samplify(options)
def song(self, reference, direction=None, output_name=None, output_type=None): """API for E2E rip of sample data from song""" options = Options() options.generate(reference=reference, direction=direction, content_type=options.SONG, output_name=output_name, output_type=output_type) return self.samplify(options)
def playlist(self, reference, direction=None, output_name=None, output_type=None, username=None): options = Options() options.generate(reference=reference, direction=direction, content_type=options.PLAYLIST, output_name=output_name, output_type=output_type, username=username) return self.samplify(options)
def from_search(self, search_term, content_type, direction=None, output_name=None, output_type=None): options = Options() result = self.spotify.search(search_term, limit=50) self.log(message=f'Searched for "{search_term}"', function='from_search', data=result) if not result: return None # 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)' queried = json.loads(json.dumps(tuple(tree_obj.execute(query))))[0] options.parent_name = queried['name'] reference = queried['uri'] options.generate(reference=reference, direction=direction, content_type=content_type, output_name=output_name, output_type=output_type) return self.samplify(options)
def main(): options = Options() parser = argparse.ArgumentParser() reference_group = parser.add_mutually_exclusive_group(required=True) reference_group.add_argument('-l', '--link', help='Click "Share" > "Copy Link"') reference_group.add_argument('-s', '--search', 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') content_group.add_argument('--playlist', action="store_const", const=options.PLAYLIST, dest='content_type') content_group.add_argument('--song', action="store_const", const=options.SONG, 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') parser.add_argument("--direction") parser.add_argument("--output-name") parser.add_argument("--output-type") parser.add_argument("--username") debug_group = parser.add_mutually_exclusive_group(required=False) debug_group.add_argument('-v', help='Include function detail', action="store_const", const=1, dest='verbosity') debug_group.add_argument('-vv', help='Multiline, include limited data', action="store_const", const=2, dest='verbosity') debug_group.add_argument('-vvv', help='Multiline, include full data', action="store_const", const=3, dest='verbosity') args = parser.parse_args() samplify = Samplify(verbosity=args.verbosity or 0) 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) 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) 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) 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) 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)