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

reusing ytmusic after uploads - Unknown Error #79

Closed
tonyhallett opened this issue Sep 15, 2020 · 1 comment
Closed

reusing ytmusic after uploads - Unknown Error #79

tonyhallett opened this issue Sep 15, 2020 · 1 comment
Labels
bug Something isn't working

Comments

@tonyhallett
Copy link

The code below does not throw an error but does if the same instance is used.

Uploading all tracks in a folder, then getting their video ids ( using the difference from before ) and adding to existing playlist.

def getYTMusic():
  return YTMusic('headers_auth.json')

def UploadFolderTracksAndAddToPlaylistWorker(folder:str,playlistId:str,initialFetchLimit:int,sleepTime:float) -> UploadFolderTracksAndAddToPlaylistResult:
  # ytmusic.get_library_upload_songs 
  uploadVideoIdsBefore = GetLatestUploadVideoIds(getYTMusic(),initialFetchLimit)
  ytmusic = getYTMusic();
  
  notUploadable = []
  uploadResponses = []  
  numSuccessfulUploads = 0
  for root, dirs, files in os.walk(folder, topdown=False):
    for name in files:
      fullPath = os.path.join(root, name)
      if IsUploadable(name):
        response = ytmusic.upload_song(fullPath)
        if successfulResponse(response):
          uploadResponses.append(UploadResponse(fullPath,True))
          numSuccessfulUploads = numSuccessfulUploads + 1
        else:
          uploadResponses.append(UploadResponse(fullPath,False))
      else:
        notUploadable.append(fullPath)

  newFetchLimit = initialFetchLimit + len(uploadResponses)

  print("sleeping to allow for videoIds *********************")
  time.sleep(sleepTime)
  
  uploadVideoIdsAfter = GetLatestUploadVideoIds(getYTMusic(),newFetchLimit)

  newUploadVideoIds = list(filter(lambda videoId:not videoId in uploadVideoIdsBefore,uploadVideoIdsAfter))

  numNewUploadVideoIds = len(newUploadVideoIds)
  if numNewUploadVideoIds != numSuccessfulUploads:
    print("Not all videoids present") # could sleep and retrieve again

  updatePlaylistResponse = getYTMusic().add_playlist_items(playlistId,newUploadVideoIds)
  return UploadFolderTracksAndAddToPlaylistResult(notUploadable,uploadResponses,newFetchLimit,updatePlaylistResponse)
  

response object

{'error': {'code': 400, 'errors': [...], 'message': 'Unknown error.', 'status': 'INVALID_ARGUMENT'}} 
special variables: 
function variables: 'error': {'code': 400, 'errors': [{...}], 'message': 'Unknown error.', 'status': 'INVALID_ARGUMENT'} 
special variables: 
function variables: 
'code': 400 
'message': 'Unknown error.' 
'errors': [{'domain': 'gdata.CoreErrorDomain', 'location': 'client', 'locationType': 'other', 'message': 'Unknown error.', 'reason': 'INVALID_VALUE'}] 
special variables: 
function variables: 
0: {'domain': 'gdata.CoreErrorDomain', 'location': 'client', 'locationType': 'other', 'message': 'Unknown error.', 'reason': 'INVALID_VALUE'} 
len(): 1 
'status': 'INVALID_ARGUMENT' 
len(): 4 
len(): 1
@sigma67
Copy link
Owner

sigma67 commented Sep 15, 2020

Ah yes, I believe this error is caused by assigning a reference to self.headers and then modifying it, instead of making a shallow copy. Good catch.

Can you change

headers = self.headers

in your local install to

headers = self.headers.copy()

and report back?

I believe that should fix it.

@sigma67 sigma67 added the bug Something isn't working label Sep 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants