<commit_before>-- Setting the "playing" property to the constant returned by Spotify as a "player state" when it's playing.
property playing : constant ****kPSP

if (isInLoginItems("SpotiFree", ":Applications:SpotiFree.app") = false) then -- Check if SpotiFree is login items.
	local dialogTitle, dialogMessage, dialogButtonYes, dialogButtonYes, spotifreeAppName, spotifreeAppPath
	set spotifreeAppName to "SpotiFree"
	set spotifreeAppPath to ":Applications:SpotiFree.app"
	set dialogTitle to "Open SpotiFree at login"
	set dialogMessage to "Do you want SpotiFree to run automatically on startup? You'll never notice it, seriously."
	set dialogButtonNo to "No, thanks"
	set dialogButtonYes to "OK"
	
	-- Run the dialog to a user.
	set runAtStartupQuestion to (display dialog dialogMessage with title dialogTitle with icon 1 buttons {dialogButtonNo, dialogButtonYes} default button 2)
	-- Assign the result to the variable runAtStartupAnswer.
	set runAtStartupAnswer to the button returned of runAtStartupQuestion
	-- Check if user agreed.
	if (runAtStartupAnswer = dialogButtonYes) then
		try
			-- Add SpotiFree to the Login Items.
			my addToLoginItems(spotifreeAppName, spotifreeAppPath)
		end try
	end if
end if

-- Repeat this entire block every .3 seconds. As set at the end.
repeat
	try
		if (isRunning() and isPlaying()) then -- Is Spotify running? Is it playing?
			global currentVolume
			local currentTrackPopularity, currentTrackDuration, currentTrackPosition
			tell application "Spotify"
				try
					-- Get the popularity of a current track and save it in a variable currentTrackPopularity.
					set currentTrackPopularity to popularity of current track
				end try
				try
					-- Get the duration of current track and save it in a variable currentTrackDuration.
					set currentTrackDuration to duration of current track
				end try
			end tell
			
			-- Check if current track is an advertisement.
			if (isAnAd(currentTrackPopularity, currentTrackDuration)) then
				try
					tell application "Spotify"
						try
							-- Get the current sound volume from Spotify and save it in a variable currentVolume.
							set currentVolume to sound volume
						end try
						try
							-- Get the current track position and save it in a variable currentTrackPosition.
							set currentTrackPosition to player position
						end try
					end tell
					
					-- Mute Spotify.
					mute()
					
					-- Wait until the end of an ad. Then go forward.
					delay currentDuration - currentPosition + 0.5
				end try
				
				try
					repeat
						local trackPopularity, trackDuration, trackPosition
						tell application "Spotify"
							try
								-- Get the popularity of a current track and save it in a variable currentTrackPopularity.
								set trackPopularity to popularity of current track
							end try
							try
								-- Get the duration of current track and save it in a variable currentTrackDuration.
								set trackDuration to duration of current track
							end try
							try
								-- Get the current track position and save it in a variable currentTrackPosition.
								set trackPosition to player position
							end try
						end tell
						
						if (isAnAd(trackPopularity, trackDuration) = false) then -- Check if current track is not an advertisement.
							unmute(currentVolume)
							exit repeat
						else
							delay trackDuration - trackPosition + 0.5
						end if
					end repeat
				end try
				
			end if
			
		end if
	end try
	delay 0.3
end repeat

on mute()
	try
		tell application "Spotify"
			try
				pause
				set sound volume to 0
				play
			end try
		end tell
	end try<commit_msg>Solving the variable mishap. Reverting the delay addition back to 1s.<commit_after>-- Setting the "playing" property to the constant returned by Spotify as a "player state" when it's playing.
property playing : constant ****kPSP
global currentVolume, currentTrackPopularity, currentTrackDuration, currentTrackPosition

if (isInLoginItems("SpotiFree", ":Applications:SpotiFree.app") = false) then -- Check if SpotiFree is login items.
	local dialogTitle, dialogMessage, dialogButtonYes, dialogButtonYes, spotifreeAppName, spotifreeAppPath
	set spotifreeAppName to "SpotiFree"
	set spotifreeAppPath to ":Applications:SpotiFree.app"
	set dialogTitle to "Open SpotiFree at login"
	set dialogMessage to "Do you want SpotiFree to run automatically on startup? You'll never notice it, seriously."
	set dialogButtonNo to "No, thanks"
	set dialogButtonYes to "OK"
	
	-- Run the dialog to a user.
	set runAtStartupQuestion to (display dialog dialogMessage with title dialogTitle with icon 1 buttons {dialogButtonNo, dialogButtonYes} default button 2)
	-- Assign the result to the variable runAtStartupAnswer.
	set runAtStartupAnswer to the button returned of runAtStartupQuestion
	-- Check if user agreed.
	if (runAtStartupAnswer = dialogButtonYes) then
		try
			-- Add SpotiFree to the Login Items.
			my addToLoginItems(spotifreeAppName, spotifreeAppPath)
		end try
	end if
end if

-- Repeat this entire block every .3 seconds. As set at the end.
repeat
	try
		if (isRunning() and isPlaying()) then -- Is Spotify running? Is it playing?
			tell application "Spotify"
				try
					-- Get the popularity of a current track and save it in a variable currentTrackPopularity.
					set currentTrackPopularity to popularity of current track
				end try
				try
					-- Get the duration of current track and save it in a variable currentTrackDuration.
					set currentTrackDuration to duration of current track
				end try
			end tell
			
			-- Check if current track is an advertisement.
			if (isAnAd(currentTrackPopularity, currentTrackDuration)) then
				try
					tell application "Spotify"
						try
							-- Get the current sound volume from Spotify and save it in a variable currentVolume.
							set currentVolume to sound volume
						end try
						try
							-- Get the current track position and save it in a variable currentTrackPosition.
							set currentTrackPosition to player position
						end try
					end tell
					
					-- Mute Spotify.
					mute()
					
					-- Wait until the end of an ad. Then go forward.
					delay currentTrackDuration - currentTrackPosition + 1
				end try
				
				try
					repeat
						tell application "Spotify"
							try
								-- Get the popularity of a current track and save it in a variable currentTrackPopularity.
								set currentTrackPopularity to popularity of current track
							end try
							try
								-- Get the duration of current track and save it in a variable currentTrackDuration.
								set currentTrackDuration to duration of current track
							end try
							try
								-- Get the current track position and save it in a variable currentTrackPosition.
								set currentTrackPosition to player position
							end try
						end tell
						
						if (isAnAd(currentTrackPopularity, currentTrackDuration) = false) then -- Check if current track is not an advertisement.
							unmute(currentVolume)
							exit repeat
						else
							delay currentTrackDuration - currentTrackPosition + 1
						end if
					end repeat
				end try
				
			end if
			
		end if
	end try
	delay 0.3
end repeat

on mute()
	try
		tell application "Spotify"
			try
				pause
				set sound volume to 0
				play
			end try
		end tell
	end try
{'fraction_non_alphanumeric': 0.04494535519125683, 'fraction_numerical': 0.0025956284153005466, 'mean_word_length': 2.9024520255863537, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4080213', 'n_tokens_mistral': 2573, 'n_tokens_neox': 1899, 'n_words': 884}