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

Error when running scan command ytmusic-sync.py #1

Open
driesdeclercq opened this issue Nov 9, 2024 · 10 comments
Open

Error when running scan command ytmusic-sync.py #1

driesdeclercq opened this issue Nov 9, 2024 · 10 comments

Comments

@driesdeclercq
Copy link

driesdeclercq commented Nov 9, 2024

I'm getting YTM authentication error. I tried with both Chrome and Firefox.

I run the command :
ytmusic-sync.py -d C:\Users\my-music-folder

When prompted, I paste the result from the oauth.json (I replaced the actual tokens with dashes)
{ "scope": "https://www.googleapis.com/auth/youtube", "token_type": "Bearer", "access_token": "---", "refresh_token": "---", "expires_at": 1731237783, "expires_in": 70895 }

I then get this error:
Traceback (most recent call last): File "C:\Users\dries\Documents\Python projects\ytmusic-sync-master\ytmusic-sync.py", line 455, in <module> authenticate() ~~~~~~~~~~~~^^ File "C:\Users\dries\Documents\Python projects\ytmusic-sync-master\ytmusic-sync.py", line 212, in authenticate ytmusicapi.setup(filepath=str(authFile)) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dries\AppData\Local\Programs\Python\Python313\Lib\site-packages\ytmusicapi\setup.py", line 22, in setup return setup_browser(filepath, headers_raw) File "C:\Users\dries\AppData\Local\Programs\Python\Python313\Lib\site-packages\ytmusicapi\auth\browser.py", line 51, in setup_browser raise YTMusicUserError( ...<3 lines>... ) ytmusicapi.exceptions.YTMusicUserError: The following entries are missing in your headers: cookie, x-goog-authuser. Please try a different request (such as /browse) and make sure you are logged in.

I am logged in.

I added the cookie header manually and tried again.
However, I do nog see an x-goog-authuser in the request header.

I also get this warning:

Writing config file
Problem saving config file: [Errno 2] No such file or directory: 'C:\\Users\\dries\\AppData\\Local\\YT Music Sync\\config.ini'

Any suggestions, please.

@phirestalker
Copy link
Owner

Ah, my program does not use the oath method as it incorporates uploads. It expects the headers copied from the browser. Try those instructions and let me know if that works.

@driesdeclercq
Copy link
Author

Hi, thank you for the swift reply.

I tried pasting the headers directly from the browser inspector. And there seems to be progress.

I'm still getting an error though.

Traceback (most recent call last): File "C:\Users\dries\Documents\Python projects\ytmusic-sync-master\ytmusic-sync.py", line 455, in <module> authenticate() ~~~~~~~~~~~~^^ File "C:\Users\dries\Documents\Python projects\ytmusic-sync-master\ytmusic-sync.py", line 212, in authenticate ytmusicapi.setup(filepath=str(authFile)) ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\Users\dries\AppData\Local\Programs\Python\Python313\Lib\site-packages\ytmusicapi\setup.py", line 22, in setup return setup_browser(filepath, headers_raw) File "C:\Users\dries\AppData\Local\Programs\Python\Python313\Lib\site-packages\ytmusicapi\auth\browser.py", line 67, in setup_browser with open(filepath, "w") as file: ~~~~^^^^^^^^^^^^^^^ FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\dries\\AppData\\Local\\YT Music Sync\\headers_auth.json'

To resolve this, I tried running the command prompt as administrator, but to no avail.

@phirestalker
Copy link
Owner

Do me a favor and create the directory "YT Music Sync" inside the AppData\Local folder, and then try it again. It is supposed to be able to create the file if it does not exist, but I don't remember if I had already created the folder beforehand.
The ytmusicapi library has been updated many times since I have used this program, so it may need some reworking.

@driesdeclercq
Copy link
Author

driesdeclercq commented Nov 9, 2024

A lot better.
It's now communicating with YTB music and getting libraries, playlists ansd likes.

loading config from file getting uploaded songs from YT music getting library songs from YT music getting library playlists from YT music getting liked songs from YT music saved cache file Invalid directory: C:\Users\dries\Music\Air saved cache file

Now I need to figure out what's wrong with the directory.
It works fine, when I add some tracks to C:\temp\test
Update: it scans the YTM library and stores this in the cache file.
It does not seem to be adding music to the library or uploading to YTM.

And thanks a lot for this tool!
Once I figure it out, this will save me a lot of time and effort.
The goal is to get all my local music into YTM.

@phirestalker
Copy link
Owner

It should print something for every file. I would need the full output of a run to find out why it is not uploading or adding songs to the library. The most likely is it is printing song not found.

As for the invalid directory I believe you forgot to put quotes around a path with spaces in it.

@driesdeclercq
Copy link
Author

I made some progres, but songs are not getting added to YTM.
So I ran the script from Visual Studio code (which is very new to me).

I had to modify the script, as I couldn't figure out how to pass the folder to scan when running debugger.
I added the folder as such:

def commandOptions(command, query):
    switcher = {
        '-d': lambda: loadDir("C:/Users/dries/Music/Aphex Twin - 1999 - Windowlicker"),

This is the output.

PS C:\Users\dries\Documents\Python projects\ytmusic-sync-master>  c:; cd 'c:\Users\dries\Documents\Python projects\ytmusic-sync-master'; & 'c:\Users\dries\AppData\Local\Programs\Python\Python313\python.exe' 'c:\Users\dries\.vscode\extensions\ms-python.debugpy-2024.12.0-win32-x64\bundled\libs\debugpy\adapter/../..\debugpy\launcher' '58926' '--' 'C:\Users\dries\Documents\Python projects\ytmusic-sync-master\ytmusic-sync.py' '-d' 
loading config from file
Loading uploads and library from cache file
getting uploaded songs from YT music
getting library playlists from YT music
saved cache file

When debugging the track variable in the function Processfile:
Something seems wrong with Mutagen:
track, title, album are all empty
duration is correct

    try:
        track = mutagen.File(filename)
    except Exception as e:
        print(f'Mutagen could not process file ({filename})\n {e}')
    # skip damaged or non-audio file
    if not track:
        return False
    **tmpArtist = track.get('artist')**
    artist = tmpArtist[0].split(' feat.')[0] if tmpArtist else '' # truncate artist at feat. so only one artists name is present
    **album = track['album'][0] if 'album' in track.keys() else ''
    title = track['title'][0] if 'title' in track.keys() else ''**
    # get duration as a familiar M:S formated string
    **duration = strftime("%M:%S", gmtime(track.info.length))**

@phirestalker
Copy link
Owner

I was afraid of something like that. It sounds like mutagen has changed the format of their return object. It will take me a while to debug this and update my code.

As for passing the directory, you can use something like python ytmusic-syny.py -d "C:\Users\My Music" putting the quotes around the path if it has spaces in it.

@phirestalker
Copy link
Owner

Quick stupid question: Your files have all the correct tag information in them right? Also, what types of files are they, and are they using the tag format for their file type? In other words not suing ID3 tags for m4a files.

@phirestalker
Copy link
Owner

It turns out that I was assuming Mutagen would handle mutliple tag formats for me. It does not. I have updated the code to use a library that does support multiple tag formats easily. This should fix the blank tags problem you are having.

@driesdeclercq
Copy link
Author

driesdeclercq commented Nov 10, 2024

You're fast :-)
I'll give this a try tomorrow.
And yes, all the test files are mp3 and have ID3 tags. I'll let you know how it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants