Skip to content

Commit

Permalink
Refactor: Change the deployment and upgrade process of youtube-dl
Browse files Browse the repository at this point in the history
Currently the repository of "github.com/ytdl-org/youtube-dl" is taken down due to [DMCA takedown notice by RIAA](https://github.com/github/dmca/blob/master/2020/10/2020-10-23-RIAA.md). But downloads from [youtube_dl · PyPI](https://pypi.org/project/youtube_dl/) and [yt-dl.org](https://yt-dl.org/) still work as usual.

It is time to change the source of downloading "youtube-dl" and modify the deployment process accordingly.

After changing the sources to PyPI, several PyPI mirrors is available for chinese users to download `youtube-dl*.tar.gz` from. Just the same as the deployment of "you-get".
  • Loading branch information
LussacZheng committed Oct 27, 2020
1 parent b809a33 commit 6a6076f
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 23 deletions.
11 changes: 7 additions & 4 deletions Deploy.bat
@@ -1,15 +1,15 @@
@rem - Encoding:utf-8; Mode:Batch; Language:chs,cht,en; LineEndings:CRLF -
:: Video Downloaders (You-Get, Youtube-dl, Annie) One-Click Deployment Batch (Windows)
:: Author: Lussac (https://blog.lussac.net)
:: Version: 1.6.2
:: Last updated: 2020-09-26
:: Version: 1.7.0-beta
:: Last updated: 2020-10-27
:: >>> Get updated from: https://github.com/LussacZheng/video-downloader-deploy <<<
:: >>> EDIT AT YOUR OWN RISK. <<<
:: >>> Attention! NEVER use `::` to comment in `( )` code block, use `REM` instead!!!
@echo off
setlocal EnableDelayedExpansion
set "_Version_=1.6.2"
set "lastUpdated=2020-09-26"
set "_Version_=1.7.0-beta"
set "lastUpdated=2020-10-27"
:: Remote resources url of 'sources.txt', 'wget.exe', '7za.exe', 'scripts/CurrentVersion'
set "_RemoteRes_=https://raw.githubusercontent.com/LussacZheng/video-downloader-deploy/master/res"

Expand Down Expand Up @@ -241,6 +241,9 @@ call scripts\Download.bat dependency
call :StopIfDisconnected
call scripts\Getter.bat DeployMode
set "whetherToLog=false"
:: flag %state_isSourcesUpToDate% is used in
:: :Upgrade_youget & :Upgrade_youtubedl of `res\scripts\DoDeploy.bat`
set "state_isSourcesUpToDate=false"
echo %str_checking-update%...
if "%DeployMode%"=="portable" goto Upgrade-portable
if "%DeployMode%"=="quickstart" goto Upgrade-quickstart
Expand Down
2 changes: 1 addition & 1 deletion res/scripts/CurrentVersion
@@ -1 +1 @@
1.6.2
1.7.0-beta
77 changes: 63 additions & 14 deletions res/scripts/DoDeploy.bat
Expand Up @@ -54,14 +54,25 @@ goto :eof


:Setup_youtubedl
for /f "delims=" %%i in ('dir /b /a:a /o:d youtube-dl*.tar.gz') do ( set "ydZip=%%i" )
for /f "delims=" %%i in ('dir /b /a:a /o:d youtube*dl*.tar.gz') do ( set "ydZip=%%i" )
if NOT "%~1"=="" ( set "ydZip=%~1" )
echo %str_unzipping% %ydZip%...
7za x %ydZip% -so | 7za x -aoa -si -ttar > NUL
:: In order to avoid access denied, wait for the decompression to complete.
ping -n 5 127.0.0.1 > NUL
set ydDir=youtube-dl
set ydDir=%ydZip:~0,-7%
move %ydDir% "%ydBin%" > NUL
( echo #^^!/usr/bin/env python3
echo.
echo import sys, os.path
echo.
echo path = os.path.realpath^(os.path.abspath^(__file__^)^)
echo sys.path.insert^(0, os.path.dirname^(path^)^)
echo.
echo import youtube_dl
echo.
echo if __name__ == '__main__':
echo youtube_dl.main^(^) ) > "%ydBin%\youtube-dl"
echo Youtube-dl %str_already-deploy%
goto :eof

Expand All @@ -85,51 +96,89 @@ goto :eof


:Upgrade_youget
setlocal EnableDelayedExpansion
echo %str_upgrading% you-get...
:: %ygCurrentVersion% was set in res\scripts\CheckUpdate.bat :CheckUpdate_youget
del /Q download\you-get-%ygCurrentVersion%.tar.gz >NUL 2>NUL
set "ygFinalFilename=you-get-%ygLatestVersion%.tar.gz"
if exist deploy.settings (
for /f "tokens=2 delims= " %%i in ('findstr /i "UpgradeOnlyViaGitHub" deploy.settings') do ( set "state_upgradeOnlyViaGitHub=%%i" )
) else ( set "state_upgradeOnlyViaGitHub=disable" )
setlocal EnableDelayedExpansion
if "%state_upgradeOnlyViaGitHub%"=="enable" (
set "ygLatestVersion_Url=https://github.com/soimort/you-get/releases/download/v%ygLatestVersion%/you-get-%ygLatestVersion%.tar.gz"
set "ygLatestVersion_Url=https://github.com/soimort/you-get/releases/download/v%ygLatestVersion%/%ygFinalFilename%"
echo !ygLatestVersion_Url!>> download\to-be-downloaded.txt
wget %_WgetOptions_% !ygLatestVersion_Url! -P download
) else (
del /Q sources.txt >NUL 2>NUL
wget %_WgetOptions_% %_RemoteRes_%/sources.txt
REM flag %state_isSourcesUpToDate% is used to avoid downloading %_RemoteRes_%/sources.txt
REM twice in one upgrading process.
if NOT "%state_isSourcesUpToDate%"=="true" (
del /Q sources.txt >NUL 2>NUL
wget %_WgetOptions_% %_RemoteRes_%/sources.txt
set "state_isSourcesUpToDate=true"
)
call scripts\SourcesSelector.bat sources.txt youget %_Region_% %_SystemType_% download\to-be-downloaded.txt
wget %_WgetOptions_% -i download\to-be-downloaded.txt -P download
REM If the file fails to download because of mirror index not syncing timelier, set %_Region_% as "origin" to fetch from original source.
if NOT exist download\you-get-%ygLatestVersion%.tar.gz (
if NOT exist download\%ygFinalFilename% (
call scripts\SourcesSelector.bat sources.txt youget origin %_SystemType_% download\to-be-downloaded.txt
wget %_WgetOptions_% -i download\to-be-downloaded.txt -P download
)
REM If %_RemoteRes_%/sources.txt is not updated timely after the new release of you-get, download it from GitHub
if NOT exist download\you-get-%ygLatestVersion%.tar.gz (
set "ygLatestVersion_Url=https://github.com/soimort/you-get/releases/download/v%ygLatestVersion%/you-get-%ygLatestVersion%.tar.gz"
if NOT exist download\%ygFinalFilename% (
set "ygLatestVersion_Url=https://github.com/soimort/you-get/releases/download/v%ygLatestVersion%/%ygFinalFilename%"
( echo # RemoteRes is not updated timely after the new release of you-get, download it from GitHub:
echo !ygLatestVersion_Url!) >> download\to-be-downloaded.txt
wget %_WgetOptions_% !ygLatestVersion_Url! -P download
)
)
endlocal
rd /S /Q "%ygBin%" >NUL 2>NUL
cd download && call :Setup_youget "you-get-%ygLatestVersion%.tar.gz"
cd download && call :Setup_youget "%ygFinalFilename%"
cd .. && echo You-Get %str_already-upgrade%
goto :eof


:Upgrade_youtubedl
setlocal EnableDelayedExpansion
echo %str_upgrading% youtube-dl...
:: %ydCurrentVersion% and %ydLatestVersion% were set in res\scripts\CheckUpdate.bat :CheckUpdate_youtubedl
set "ydCurrentVersion_trimZero=%ydCurrentVersion:.0=.%"
:: If "%ydCurrentVersion%"=="2019.08.02", "%ydCurrentVersion_trimZero%" will be "2019.8.2".
set "ydLatestVersion_trimZero=%ydLatestVersion:.0=.%"
del /Q download\youtube-dl-%ydCurrentVersion%.tar.gz >NUL 2>NUL
set "ydLatestVersion_Url=https://github.com/ytdl-org/youtube-dl/releases/download/%ydLatestVersion%/youtube-dl-%ydLatestVersion%.tar.gz"
echo %ydLatestVersion_Url%>> download\to-be-downloaded.txt
wget %_WgetOptions_% %ydLatestVersion_Url% -P download
del /Q download\youtube_dl-%ydCurrentVersion_trimZero%.tar.gz >NUL 2>NUL
set "ydFinalFilename=youtube_dl-%ydLatestVersion_trimZero%.tar.gz"
if exist deploy.settings (
for /f "tokens=2 delims= " %%i in ('findstr /i "UpgradeOnlyViaGitHub" deploy.settings') do ( set "state_upgradeOnlyViaGitHub=%%i" )
) else ( set "state_upgradeOnlyViaGitHub=disable" )
if "%state_upgradeOnlyViaGitHub%"=="enable" (
set "ydFinalFilename=youtube-dl-%ydLatestVersion%.tar.gz"
set "ydLatestVersion_Url=https://github.com/ytdl-org/youtube-dl/releases/download/%ydLatestVersion%/%ydFinalFilename%"
echo %ydLatestVersion_Url%>> download\to-be-downloaded.txt
wget %_WgetOptions_% %ydLatestVersion_Url% -P download
) else (
if NOT "%state_isSourcesUpToDate%"=="true" (
del /Q sources.txt >NUL 2>NUL
wget %_WgetOptions_% %_RemoteRes_%/sources.txt
set "state_isSourcesUpToDate=true"
)
call scripts\SourcesSelector.bat sources.txt youtubedl %_Region_% %_SystemType_% download\to-be-downloaded.txt
wget %_WgetOptions_% -i download\to-be-downloaded.txt -P download
if NOT exist download\%ydFinalFilename% (
call scripts\SourcesSelector.bat sources.txt youtubedl origin %_SystemType_% download\to-be-downloaded.txt
wget %_WgetOptions_% -i download\to-be-downloaded.txt -P download
)
if NOT exist download\%ydFinalFilename% (
set "ydFinalFilename=youtube-dl-%ydLatestVersion%.tar.gz"
set "ydLatestVersion_Url=https://github.com/ytdl-org/youtube-dl/releases/download/%ydLatestVersion%/%ydFinalFilename%"
( echo # RemoteRes is not updated timely after the new release of youtube-dl, download it from GitHub:
echo !ydLatestVersion_Url!) >> download\to-be-downloaded.txt
wget %_WgetOptions_% !ydLatestVersion_Url! -P download
)
)
endlocal
rd /S /Q "%ydBin%" >NUL 2>NUL
cd download && call :Setup_youtubedl "youtube-dl-%ydLatestVersion%.tar.gz"
cd download && call :Setup_youtubedl "%ydFinalFilename%"
cd .. && echo Youtube-dl %str_already-upgrade%
goto :eof

Expand Down
18 changes: 14 additions & 4 deletions res/sources.txt
@@ -1,7 +1,7 @@
## Sources List of "video-downloader-deploy"
## https://github.com/LussacZheng/video-downloader-deploy/blob/master/res/sources.txt
## For Initial Deployment; Deployment of FFmpeg; Upgrade of You-Get.
## ( Auto-Generated by "AutoGenerateLatestSourcesLists.bat" at 2020-09-20 13:55:31 )
## ( Auto-Generated by "AutoGenerateLatestSourcesLists.bat" at 2020-10-27 11:01:29 )

<!-- DO NOT EDIT THIS FILE unless you understand the EXAMPLE. -->

Expand Down Expand Up @@ -71,14 +71,24 @@ Mirrors{
[/youget][/portable][/quickstart]


[portable]
[youtubedl][portable]
## Release log - YoutubeDL
## https://github.com/ytdl-org/youtube-dl/releases/latest
## Last released: 2020.09.20

## youtube-dl.tar.gz , 2020.09.20
https://github.com/ytdl-org/youtube-dl/releases/download/2020.09.20/youtube-dl-2020.09.20.tar.gz
[/portable]
Mirrors{
[origin]
https://files.pythonhosted.org/packages/12/8b/51cae2929739d637fdfbc706b2d5f8925b5710d8f408b5319a07ea45fe99/youtube_dl-2020.9.20.tar.gz
$ https://yt-dl.org/downloads/latest/youtube-dl-2020.09.20.tar.gz
$ https://github.com/ytdl-org/youtube-dl/releases/download/2020.09.20/youtube-dl-2020.09.20.tar.gz
[cn]
@ https://mirrors.tuna.tsinghua.edu.cn/pypi/web/packages/12/8b/51cae2929739d637fdfbc706b2d5f8925b5710d8f408b5319a07ea45fe99/youtube_dl-2020.9.20.tar.gz
$ https://mirrors.aliyun.com/pypi/packages/12/8b/51cae2929739d637fdfbc706b2d5f8925b5710d8f408b5319a07ea45fe99/youtube_dl-2020.9.20.tar.gz
[test]
@ https://mirrors.huaweicloud.com/repository/pypi/packages/12/8b/51cae2929739d637fdfbc706b2d5f8925b5710d8f408b5319a07ea45fe99/youtube_dl-2020.9.20.tar.gz
}
[/youtubedl][/portable]


[portable][withpip]
Expand Down

0 comments on commit 6a6076f

Please sign in to comment.