mirror of
				https://github.com/THIS-IS-NOT-A-BACKUP/zspotify.git
				synced 2025-11-03 21:10:34 +00:00 
			
		
		
		
	Also save ext data in .song_ids file (filename, date, etc)
This commit is contained in:
		
							parent
							
								
									c836240b30
								
							
						
					
					
						commit
						cdd013b09e
					
				@ -158,10 +158,10 @@ def download_track(mode: str, track_id: str, extra_keys={}, disable_progressbar=
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    # add song id to archive file
 | 
					                    # add song id to archive file
 | 
				
			||||||
                    if ZSpotify.CONFIG.get_skip_previously_downloaded():
 | 
					                    if ZSpotify.CONFIG.get_skip_previously_downloaded():
 | 
				
			||||||
                        add_to_archive(scraped_song_id, artists[0], name)
 | 
					                        add_to_archive(scraped_song_id, filename, artists[0], name)
 | 
				
			||||||
                    # add song id to download directory's .song_ids file
 | 
					                    # add song id to download directory's .song_ids file
 | 
				
			||||||
                    if not check_id:
 | 
					                    if not check_id:
 | 
				
			||||||
                        add_to_directory_song_ids(filedir, scraped_song_id)
 | 
					                        add_to_directory_song_ids(filedir, scraped_song_id, filename, artists[0], name)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if not ZSpotify.CONFIG.get_anti_ban_wait_time():
 | 
					                    if not ZSpotify.CONFIG.get_anti_ban_wait_time():
 | 
				
			||||||
                        time.sleep(ZSpotify.CONFIG.get_anti_ban_wait_time())
 | 
					                        time.sleep(ZSpotify.CONFIG.get_anti_ban_wait_time())
 | 
				
			||||||
 | 
				
			|||||||
@ -42,17 +42,17 @@ def get_previously_downloaded() -> List[str]:
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    return ids
 | 
					    return ids
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_to_archive(song_id: str, author_name: str, song_name: str) -> None:
 | 
					def add_to_archive(song_id: str, filename: str, author_name: str, song_name: str) -> None:
 | 
				
			||||||
    """ Adds song id to all time installed songs archive """
 | 
					    """ Adds song id to all time installed songs archive """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive())
 | 
					    archive_path = os.path.join(os.path.dirname(__file__), ZSpotify.CONFIG.get_root_path(), ZSpotify.CONFIG.get_song_archive())
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if os.path.exists(archive_path):
 | 
					    if os.path.exists(archive_path):
 | 
				
			||||||
        with open(archive_path, 'a', encoding='utf-8') as f:
 | 
					        with open(archive_path, 'a', encoding='utf-8') as file:
 | 
				
			||||||
            f.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\n')
 | 
					            file.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\t{filename}\n')
 | 
				
			||||||
    else:
 | 
					    else:
 | 
				
			||||||
        with open(archive_path, 'w', encoding='utf-8') as f:
 | 
					        with open(archive_path, 'w', encoding='utf-8') as file:
 | 
				
			||||||
            f.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\n')
 | 
					            file.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\t{filename}\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_directory_song_ids(download_path: str) -> List[str]:
 | 
					def get_directory_song_ids(download_path: str) -> List[str]:
 | 
				
			||||||
    """ Gets song ids of songs in directory """
 | 
					    """ Gets song ids of songs in directory """
 | 
				
			||||||
@ -62,18 +62,18 @@ def get_directory_song_ids(download_path: str) -> List[str]:
 | 
				
			|||||||
    hidden_file_path = os.path.join(download_path, '.song_ids')
 | 
					    hidden_file_path = os.path.join(download_path, '.song_ids')
 | 
				
			||||||
    if os.path.isfile(hidden_file_path):
 | 
					    if os.path.isfile(hidden_file_path):
 | 
				
			||||||
        with open(hidden_file_path, 'r', encoding='utf-8') as file:
 | 
					        with open(hidden_file_path, 'r', encoding='utf-8') as file:
 | 
				
			||||||
            song_ids.extend([line.strip() for line in file.readlines()])
 | 
					            song_ids.extend([line.strip().split('\t')[0] for line in file.readlines()])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    return song_ids
 | 
					    return song_ids
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def add_to_directory_song_ids(download_path: str, song_id: str) -> None:
 | 
					def add_to_directory_song_ids(download_path: str, song_id: str, filename: str, author_name: str, song_name: str) -> None:
 | 
				
			||||||
    """ Appends song_id to .song_ids file in directory """
 | 
					    """ Appends song_id to .song_ids file in directory """
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    hidden_file_path = os.path.join(download_path, '.song_ids')
 | 
					    hidden_file_path = os.path.join(download_path, '.song_ids')
 | 
				
			||||||
    # not checking if file exists because we need an exception
 | 
					    # not checking if file exists because we need an exception
 | 
				
			||||||
    # to be raised if something is wrong
 | 
					    # to be raised if something is wrong
 | 
				
			||||||
    with open(hidden_file_path, 'a', encoding='utf-8') as file:
 | 
					    with open(hidden_file_path, 'a', encoding='utf-8') as file:
 | 
				
			||||||
        file.write(f'{song_id}\n')
 | 
					        file.write(f'{song_id}\t{datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\t{author_name}\t{song_name}\t{filename}\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def get_downloaded_song_duration(filename: str) -> float:
 | 
					def get_downloaded_song_duration(filename: str) -> float:
 | 
				
			||||||
    """ Returns the downloaded file's duration in seconds """
 | 
					    """ Returns the downloaded file's duration in seconds """
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user