Skip to content

Instantly share code, notes, and snippets.

@lxfly2000
Last active June 23, 2019 08:48
Show Gist options
  • Save lxfly2000/2b4c2b5feb4ee294d51085cf57079a71 to your computer and use it in GitHub Desktop.
Save lxfly2000/2b4c2b5feb4ee294d51085cf57079a71 to your computer and use it in GitHub Desktop.
Copy Bilibili cache from phone to PC.
@echo off
setlocal enabledelayedexpansion
set ADB_PATH=D:\Android\Sdk\platform-tools\adb.exe
set DEVICE_CACHE_PATH=/sdcard/Android/data/com.bilibili.app.in/download
set LOCAL_CACHE_PATH=D:\Yueyu\Bilibili\download
set INCLUDE=0
if /i "%~2"=="video" set INCLUDE=1
if /i "%~2"=="bangumi" set INCLUDE=2
if /i "%~2"=="all" set INCLUDE=3
if "%~3" neq "" set LOCAL_CACHE_PATH=%~3
if "%~4" neq "" set DEVICE_CACHE_PATH=%~4
if /i "%~1"=="kill" goto :kill
if /i "%~1"=="push" goto :bili_push
if /i "%~1"=="pull" goto :bili_pull
echo Usage: %~n0 push^|pull video^|bangumi^|all [local_path] [device_path]
echo %~n0 kill
exit /b 1
:bili_push
if !INCLUDE!==0 (
echo Missing 2nd parameter.
goto :end
)
for /f %%i in ('dir /b "!LOCAL_CACHE_PATH!"') do (
set dir_name=%%i
set pass=0
if /i !INCLUDE! neq 1 if /i !INCLUDE! neq 3 if /i "!dir_name:~0,2!" neq "s_" set pass=1
if /i !INCLUDE! neq 2 if /i !INCLUDE! neq 3 if /i "!dir_name:~0,2!"=="s_" set pass=1
if /i !pass!==0 (
for /f %%j in ('dir /b "!LOCAL_CACHE_PATH!\%%i"') do (
"%ADB_PATH%" shell ls "!DEVICE_CACHE_PATH!/%%i/%%j">nul 2>nul ||(
"%ADB_PATH%" push "!LOCAL_CACHE_PATH!\%%i\%%j" "!DEVICE_CACHE_PATH!/%%i/%%j"
)
)
)
)
goto :end
:bili_pull
if !INCLUDE!==0 (
echo Missing 2nd parameter.
goto :end
)
for /f %%i in ('%ADB_PATH% shell ls "!DEVICE_CACHE_PATH!"') do (
set dir_name=%%i
set pass=0
if /i !INCLUDE! neq 1 if /i !INCLUDE! neq 3 if /i "!dir_name:~0,2!" neq "s_" set pass=1
if /i !INCLUDE! neq 2 if /i !INCLUDE! neq 3 if /i "!dir_name:~0,2!"=="s_" set pass=1
if /i !pass!==0 (
for /f %%j in ('%ADB_PATH% shell ls "!DEVICE_CACHE_PATH!/%%i"') do (
if not exist "!LOCAL_CACHE_PATH!\%%i\%%j" (
if not exist "!LOCAL_CACHE_PATH!\%%i" md "!LOCAL_CACHE_PATH!\%%i"
"%ADB_PATH%" pull "!DEVICE_CACHE_PATH!/%%i/%%j" "!LOCAL_CACHE_PATH!\%%i"
)
)
)
)
goto :end
:kill
"%ADB_PATH%" kill-server
:end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment