mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 14:45:14 +00:00 
			
		
		
		
	[update] Implement --update-to repo
				
					
				
			Authored by: Grub4K, pukkandan
This commit is contained in:
		| @@ -129,27 +129,36 @@ class Updater: | ||||
|         self.ydl = ydl | ||||
| 
 | ||||
|         self.target_channel, sep, self.target_tag = (target or CHANNEL).rpartition('@') | ||||
|         if not sep and self.target_tag in UPDATE_SOURCES:  # stable => stable@latest | ||||
|             self.target_channel, self.target_tag = self.target_tag, None | ||||
|         # stable => stable@latest | ||||
|         if not sep and ('/' in self.target_tag or self.target_tag in UPDATE_SOURCES): | ||||
|             self.target_channel = self.target_tag | ||||
|             self.target_tag = None | ||||
|         elif not self.target_channel: | ||||
|             self.target_channel = CHANNEL | ||||
|             self.target_channel = CHANNEL.partition('@')[0] | ||||
| 
 | ||||
|         if not self.target_tag: | ||||
|             self.target_tag, self._exact = 'latest', False | ||||
|             self.target_tag = 'latest' | ||||
|             self._exact = False | ||||
|         elif self.target_tag != 'latest': | ||||
|             self.target_tag = f'tags/{self.target_tag}' | ||||
| 
 | ||||
|     @property | ||||
|     def _target_repo(self): | ||||
|         try: | ||||
|             return UPDATE_SOURCES[self.target_channel] | ||||
|         except KeyError: | ||||
|             return self._report_error( | ||||
|                 f'Invalid update channel {self.target_channel!r} requested. ' | ||||
|                 f'Valid channels are {", ".join(UPDATE_SOURCES)}', True) | ||||
|         if '/' in self.target_channel: | ||||
|             self._target_repo = self.target_channel | ||||
|             if self.target_channel not in (CHANNEL, *UPDATE_SOURCES.values()): | ||||
|                 self.ydl.report_warning( | ||||
|                     f'You are switching to an {self.ydl._format_err("unofficial", "red")} executable ' | ||||
|                     f'from {self.ydl._format_err(self._target_repo, self.ydl.Styles.EMPHASIS)}. ' | ||||
|                     f'Run {self.ydl._format_err("at your own risk", "light red")}') | ||||
|                 self.restart = self._blocked_restart | ||||
|         else: | ||||
|             self._target_repo = UPDATE_SOURCES.get(self.target_channel) | ||||
|             if not self._target_repo: | ||||
|                 self._report_error( | ||||
|                     f'Invalid update channel {self.target_channel!r} requested. ' | ||||
|                     f'Valid channels are {", ".join(UPDATE_SOURCES)}', True) | ||||
| 
 | ||||
|     def _version_compare(self, a, b, channel=CHANNEL): | ||||
|         if channel != self.target_channel: | ||||
|         if self._exact and channel != self.target_channel: | ||||
|             return False | ||||
| 
 | ||||
|         if _VERSION_RE.fullmatch(f'{a}.{b}'): | ||||
| @@ -372,6 +381,12 @@ class Updater: | ||||
|         _, _, returncode = Popen.run(self.cmd) | ||||
|         return returncode | ||||
| 
 | ||||
|     def _blocked_restart(self): | ||||
|         self._report_error( | ||||
|             'Automatically restarting into custom builds is disabled for security reasons. ' | ||||
|             'Restart yt-dlp to use the updated version', expected=True) | ||||
|         return self.ydl._download_retcode | ||||
| 
 | ||||
| 
 | ||||
| def run_update(ydl): | ||||
|     """Update the program file with the latest version from the repository | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Simon Sawicki
					Simon Sawicki