Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--offset argument that allows to start a download from a certain... #274

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions spotify_dl/spotify.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from spotify_dl.scaffold import log
from spotify_dl.utils import sanitize
from rich.progress import Progress
def fetch_tracks(sp, item_type, url):
def fetch_tracks(sp, item_type, url, offset=0):
"""
Fetches tracks from the provided URL.
:param sp: Spotify client
Expand All @@ -12,7 +12,6 @@ def fetch_tracks(sp, item_type, url):
:return Dictionary of song and artist
"""
songs_list = []
offset = 0

if item_type == 'playlist':
with Progress() as progress:
Expand All @@ -25,6 +24,9 @@ def fetch_tracks(sp, item_type, url):
'items.track.id',
additional_types=['track'], offset=offset)
total_songs = items.get('total')
if offset > total_songs:
log.error("Offset is bigger than the total number of songs")
sys.exit(1)
track_info_task = progress.add_task(description="Fetching track info", total=len(items['items']))
for item in items['items']:
track_info = item.get('track')
Expand Down
4 changes: 3 additions & 1 deletion spotify_dl/spotify_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def spotify_dl():
parser.add_argument('-k', '--keep_playlist_order', default=False,
action='store_true',
help='Whether to keep original playlist ordering or not.')
parser.add_argument('-O', '--offset', type=int, action='store', default=0,
help='Specify offset to start downloading from.')
parser.add_argument('-m', '--skip_mp3', action='store_true',
help='Don\'t convert downloaded songs to mp3')
parser.add_argument('-s', '--skip_non_music_sections', default=False,
Expand Down Expand Up @@ -91,7 +93,7 @@ def spotify_dl():
save_path = Path(PurePath.joinpath(Path(args.output), Path(directory_name)))
save_path.mkdir(parents=True, exist_ok=True)
console.print(f"Saving songs to [bold green]{directory_name}[/bold green] directory")
songs = fetch_tracks(sp, item_type, url)
songs = fetch_tracks(sp, item_type, url, args.offset)
else:
songs = {}
if args.download is True:
Expand Down