Esempio n. 1
0
def load_defaults():
    const.args = handle.get_arguments(raw_args="",
                                      to_group=False,
                                      to_merge=False)
    const.args.overwrite = "skip"

    spotdl.args = const.args
    spotdl.log = const.logzero.setup_logger(formatter=const._formatter,
                                            level=const.args.log_level)
Esempio n. 2
0
def get_track():
    const.args = handle.get_arguments()

    internals.filter_path(const.args.folder)
    youtube_tools.set_api_key()

    try:
        if const.args.song:
            for track in const.args.song:
                track_dl = downloader.Downloader(raw_song=track)
                track_dl.download_single()
    except KeyboardInterrupt as e:
        print("Exception occured in method 'get_track':", e)
        return False
    return True
Esempio n. 3
0
def main():
    const.args = handle.get_arguments()

    if const.args.version:
        print("spotdl {version}".format(version=__version__))
        sys.exit()

    internals.filter_path(const.args.folder)
    youtube_tools.set_api_key()

    logzero.setup_default_logger(formatter=const._formatter,
                                 level=const.args.log_level)

    log.debug("Python version: {}".format(sys.version))
    log.debug("Platform: {}".format(platform.platform()))
    log.debug(pprint.pformat(const.args.__dict__))

    try:
        if const.args.song:
            download_single(raw_song=const.args.song)
        elif const.args.list:
            if const.args.write_m3u:
                youtube_tools.generate_m3u(track_file=const.args.list)
            else:
                download_list(
                    tracks_file=const.args.list,
                    skip_file=const.args.skip,
                    write_successful_file=const.args.write_successful,
                )
        elif const.args.playlist:
            spotify_tools.write_playlist(playlist_url=const.args.playlist)
        elif const.args.album:
            spotify_tools.write_album(album_url=const.args.album)
        elif const.args.all_albums:
            spotify_tools.write_all_albums_from_artist(
                artist_url=const.args.all_albums)
        elif const.args.username:
            spotify_tools.write_user_playlist(username=const.args.username)

        # actually we don't necessarily need this, but yeah...
        # explicit is better than implicit!
        sys.exit(0)

    except KeyboardInterrupt as e:
        log.exception(e)
        sys.exit(3)
Esempio n. 4
0
def main():
    const.args = handle.get_arguments()

    internals.filter_path(const.args.folder)
    youtube_tools.set_api_key()

    logzero.setup_default_logger(formatter=const._formatter, level=const.args.log_level)

    try:
        match_args()
        # actually we don't necessarily need this, but yeah...
        # explicit is better than implicit!
        sys.exit(0)

    except KeyboardInterrupt as e:
        log.exception(e)
        sys.exit(3)
Esempio n. 5
0
def main():
    const.args = handle.get_arguments()

    if const.args.version:
        print('spotdl {version}'.format(version=__version__))
        sys.exit()

    internals.filter_path(const.args.folder)
    youtube_tools.set_api_key()

    const.log = const.logzero.setup_logger(formatter=const._formatter,
                                      level=const.args.log_level)
    global log
    log = const.log
    log.debug('Python version: {}'.format(sys.version))
    log.debug('Platform: {}'.format(platform.platform()))
    log.debug(pprint.pformat(const.args.__dict__))

    try:
        if const.args.song:
            download_single(raw_song=const.args.song)
        elif const.args.list:
            download_list(text_file=const.args.list)
        elif const.args.playlist:
            spotify_tools.write_playlist(playlist_url=const.args.playlist)
        elif const.args.album:
            spotify_tools.write_album(album_url=const.args.album)
        elif const.args.username:
            spotify_tools.write_user_playlist(username=const.args.username)

        # actually we don't necessarily need this, but yeah...
        # explicit is better than implicit!
        sys.exit(0)

    except KeyboardInterrupt as e:
        log.exception(e)
        sys.exit(3)
Esempio n. 6
0
from spotdl import handle
from spotdl import const
from spotdl import downloader

import os
import sys

const.args = handle.get_arguments(to_group=True)

track = downloader.Downloader(raw_song=const.args.song[0])

track_title = track.refine_songname(track.content.title)
track_filename = track_title + const.args.output_ext
track_download_path = os.path.join(const.args.folder, track_filename)

track.download_single()
Esempio n. 7
0
def arg(song_url=None):
    options = get_arguments(raw_args=song_url)
    return options
Esempio n. 8
0
def test_grouped_arguments(tmpdir):
    sys.path[0] = str(tmpdir)
    with pytest.raises(SystemExit):
        handle.get_arguments(to_group=True, to_merge=True)
Esempio n. 9
0
def test_m3u_with_list():
    handle.get_arguments(raw_args=("-l cool_list.txt", "--write-m3u"),
                         to_group=True)
Esempio n. 10
0
def test_error_m3u_without_list():
    with pytest.raises(SystemExit):
        handle.get_arguments(raw_args=("-s cool song", "--write-m3u"),
                             to_group=True)
Esempio n. 11
0
def test_m3u_with_list():
    handle.get_arguments(raw_args=('-l cool_list.txt', '--write-m3u',),
                         to_group=True)
Esempio n. 12
0
def spotify_dl(context, update, link):

    user_id = update.message.chat_id,
    status = context.bot.send_message(
        chat_id=update.message.chat_id,
        text="Downloading Song!..\nPlease wait..",
        reply_to_message_id=update.message.message_id)
    try:
        # modify attributes on `const.args` to change any default arguments
        # https://github.com/ritiek/spotify-downloader/blob/67ae7d5c4c9ed289f278a3ad6bfae658b812196f/spotdl/handle.py#L15-L36
        const.args = handle.get_arguments(to_group=False)
        # loglevel can be one of `logging.NOTSET`, `logging.INFO`, `logging.WARNING`, `logging.ERROR`, `logging.DEBUG`
        const.logzero.setup_default_logger(formatter=const._formatter,
                                           level=const.logzero.logging.INFO)
        const.args.folder = os.getcwd()
        const.args.trim_silence = True
        #key=link.split('https://open.spotify.com/')[1].split('/')[0]
        #print(link)
        if '/track/' in link:
            print("Track Invoked")
            # raw_song can take Spotify/Youtube URLs or a string
            track = downloader.Downloader(raw_song=link)
            #print(const.args)
            # you probably need one of these variables
            track_title = track.refine_songname(track.content.title)
            track_filename = track_title + const.args.output_ext
            #track_download_path = os.path.join(const.args.folder, track_filename)
            # download, convert and embed metadata
            track.download_single()
            status.edit_text(text='Sending your awesome song!...\n')
            a = context.bot.send_audio(
                chat_id=update.message.chat_id,
                audio=open(track_filename, 'rb'),
                caption='Downloaded using @emojifymusicbot',
                timeout=1000)
            os.remove(track_filename)
        elif '/album/' in link:
            print("Album")
            cmd = ['spotdl', '--write-to', 'album.txt', '--album', link]
            subprocess.call(cmd)
            with open('album.txt', 'r') as myfile:
                data = myfile.read()
            data = data.split('\n')
            data.pop()
            os.remove('album.txt')
            i = 1

            for link in data:
                try:
                    track = downloader.Downloader(raw_song=link)
                    #print(const.args)
                    # you probably need one of these variables
                    track_title = track.refine_songname(track.content.title)
                    track_filename = track_title + const.args.output_ext
                    #track_download_path = os.path.join(const.args.folder, track_filename)
                    # download, convert and embed metadata
                    track.download_single()
                    status.edit_text(text='Sending ' + str(i) + '/' +
                                     str(len(data)) + ' songs...\n')
                    a = context.bot.send_audio(
                        chat_id=update.message.chat_id,
                        audio=open(track_filename, 'rb'),
                        caption='Downloaded using @emojifymusicbot',
                        timeout=1000)
                    os.remove(track_filename)
                except Exception as e:
                    print(e)
                finally:
                    i = i + 1
            status.edit_text(text='Thanks for using @emojifymusicbot\n')

        elif '/playlist/' in link:
            cmd = ['spotdl', '--write-to', 'playlist.txt', '--playlist', link]
            subprocess.call(cmd)
            with open('playlist.txt', 'r') as myfile:
                data = myfile.read()
            data = data.split('\n')
            data.pop()
            os.remove('playlist.txt')
            i = 1

            for link in data:
                try:
                    ack = mongo.send_saved_song(link, user_id)
                    if ack == 1:
                        update_db(bot, update, link, 'Cached', 'from_cache')
                        continue
                    track = downloader.Downloader(raw_song=link)
                    #print(const.args)
                    # you probably need one of these variables
                    track_title = track.refine_songname(track.content.title)
                    track_filename = track_title + const.args.output_ext
                    #track_download_path = os.path.join(const.args.folder, track_filename)
                    # download, convert and embed metadata
                    track.download_single()
                    status.edit_text(text='Sending ' + str(i) + '/' +
                                     str(len(data)) + ' songs...\n')
                    if '/app/' in track_filename:
                        track_filename = str(track_filename.split('/app/')[-1])
                    a = context.bot.send_audio(
                        chat_id=update.message.chat_id,
                        audio=open(track_filename, 'rb'),
                        caption='Downloaded using @emojifymusicbot',
                        timeout=1000)
                    os.remove(track_filename)
                except Exception as e:
                    print(e)
                finally:
                    i = i + 1
            status.edit_text(text='Thanks for using @emojifymusicbot\n')
    except Exception as e:
        status.edit_text(
            text='Error Occured\nPlease try downloading a different song\n')