-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- bump version - update readme - add utf-8 convert option - make sure files are parsed as utf-8 - pull out playlist name extractor - first update outline & tests with m3u8 extension - add overall test - validate file extension - validate empty playlist file
- Loading branch information
Showing
17 changed files
with
251 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
m3u8==0.5.4 | ||
m3u8>=0.7.1 | ||
spotipy==2.11.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#EXTM3U | ||
#EXTINF:290,Eiv�r - Tr�llabundin | ||
..\..\Music\Selection\Nordic\Eiv�r - Tr�llabundin.mp3 |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/Music/Selection/Faun - Sieben Raben.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#EXTM3U | ||
#EXTINF:200,Marcin Przybyłowicz - The Wolven Storm (Priscilla's Song) | ||
/Music/Marcin Przybyłowicz - The Wolven Storm (Priscilla's Song).mp3 | ||
#EXTINF:290,Eivør - Trøllabundin | ||
/Music/Eivør - Trøllabundin.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#EXTM3U | ||
#EXTINF:277,Faun - Sieben Raben | ||
/Music/Selection/Faun - Sieben Raben.mp3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import os | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
|
||
from tospotify.run import main | ||
|
||
|
||
class MockArgs: | ||
def __init__(self, playlist_path, playlist_id=None): | ||
self.verbose = False | ||
self.convert = False | ||
self.spotify_username = 'test_username' | ||
self.public = True | ||
self.playlist_path = playlist_path | ||
self.playlist_id = playlist_id | ||
|
||
|
||
# the point here is to run through the whole flow | ||
@patch('tospotify.run._parse_args') | ||
@patch('tospotify.run.prompt_for_user_token', lambda x, y: 'token') | ||
@patch('tospotify.search._find_track', lambda x, y, z: 'uri') | ||
@patch('tospotify.search.add_tracks', lambda x, y, z: None) | ||
@pytest.mark.parametrize('playlist', [ | ||
os.path.join('test', 'data', 'valid_playlist.m3u'), | ||
os.path.join('test', 'data', 'empty_playlist.m3u'), | ||
os.path.join('test', 'data', 'empty_playlist.m3u'), | ||
os.path.join('test', 'data', 'utf8_playlist.m3u8') | ||
]) | ||
def test_integration(mock_function, playlist): | ||
mock_function.return_value = MockArgs(playlist_path=playlist, playlist_id=1) | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from tospotify.parser import parse_songs | ||
|
||
|
||
def test_parse_songs(): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import logging | ||
|
||
import m3u8 | ||
|
||
|
||
def convert_utf8(playlist_path: str) -> str: | ||
""" Convert file to utf-8 after parsing with locale.getpreferredencoding | ||
:param playlist_path: absolute path of the playlist | ||
:return: Path of converted file | ||
""" | ||
logging.warning('Converting file to utf-8') | ||
path_without_extension = playlist_path.rsplit('.', 1)[0] | ||
output_path = path_without_extension + '_utf8.m3u8' | ||
|
||
# here it uses the locale.getpreferredencoding, which could be cp1252 for Windows | ||
with open(playlist_path, mode='r') as input_: | ||
with open(output_path, encoding='utf-8', mode='w') as output_: | ||
for line in input_.readlines(): | ||
output_.write(line.encode('utf-8').decode('utf-8')) | ||
|
||
return output_path | ||
|
||
|
||
def parse_songs(playlist_path: str) -> m3u8.SegmentList: | ||
""" Parse and return the songs found in the file | ||
:param playlist_path: absolute path of the playlist | ||
:type playlist_path: str | ||
:return: | ||
""" | ||
# m3u8 uses open(..., encoding='utf-8') which will through exception when the file cannot be parsed as utf-8 | ||
playlist = m3u8.load(playlist_path) | ||
segments = playlist.segments | ||
|
||
if len(segments) <= 0: | ||
logging.error('Could not find any songs in the file!') | ||
|
||
return segments |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.