Tiavor

series watching helper

Jun 19th, 2020 (edited)
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 3.23 KB | None | 0 0
  1. REM can't remember which episode you watched last? this batch will list all video files of the current folder and subfolders, sort them alphabetical and then play back the next episode.
  2.  
  3. REM copy this text into a text file and change the file ending to .bat
  4. REM update 4: How to go through subfolders: create a shortcut to this bat file and add -sub after the target as command line parameter.
  5. REM you can change the target directory of the shortcut to another folder if you like. e.g. the .bat file in somefolder and the loaded movie files in someotherfolder.
  6. REM if you have lots of folders to go through, use this other batch file to create a shortcut, linking to a random folder: https://pastebin.com/vCAMYQD9
  7.  
  8. REM summary of previous updates: "enable delayedexpansion" doesn't work together with paths that include exclamation mark; findstr uses backslash as escape character so that doesn't work too.
  9.  
  10. @echo off
  11. if exist next.txt goto play
  12. REM if next.txt is not present, create a new file with all .avi, .mkv, .mov and .mp4 files in this folder and all sub folders (/s)
  13. REM /b reduces the dir command to just the file name, /s searches through all sub folders and writes the complete path into the list
  14. REM add -sub to the shortcut to activate the search through subfolders
  15. if "%1"=="-sub" goto yes
  16. goto no
  17. :yes
  18.     dir *.mkv /b /s > temp.txt
  19.     dir *.mp4 /b /s >> temp.txt
  20.     dir *.avi /b /s >> temp.txt
  21.     dir *.mov /b /s >> temp.txt
  22.     echo included subfolders
  23.     goto continue
  24. :no
  25.     dir *.mkv /b > temp.txt
  26.     dir *.mp4 /b >> temp.txt
  27.     dir *.avi /b >> temp.txt
  28.     dir *.mov /b >> temp.txt
  29. :continue
  30.  
  31. REM sorting the result in case file formats are mixed
  32. sort temp.txt > list.txt
  33. del temp.txt
  34.  
  35.  
  36. REM if exists watched.txt compare with list.txt
  37. REM    put not matching entries in next.txt
  38. if exist list.txt (
  39.     if exist watched.txt (
  40.         echo filtering next.txt
  41.         REM the given example for findstr weren't helpful. g: is the key(s) and the second parameter is the list to check for the key(s)
  42.         REM if not exist next.txt echo.> next.txt
  43.         REM note: removed findstr because it doesn't work with complete paths as backslash is an escape char
  44.         for /f "tokens=*" %%f in (watched.txt) do (
  45.             if exist %%f (
  46.                 echo %%f>> watched2.txt
  47.                 echo filtering "%%f"
  48.                 echo @echo off> sort.bat
  49.                 echo for /f "tokens=*" %%%%d in ^(list.txt^) do ^(>> sort.bat
  50.                 echo if not "%%%%d"=="%%f" ^(>> sort.bat
  51.                 echo echo %%%%d^>^> list2.txt>> sort.bat
  52.                 echo ^)>> sort.bat
  53.                 echo ^)>> sort.bat
  54.                 echo del list.txt>> sort.bat
  55.                 echo ren list2.txt list.txt>> sort.bat
  56.                 call sort.bat
  57.             )
  58.         )
  59.         del watched.txt
  60.         ren watched2.txt watched.txt
  61.         echo filter complete
  62.         del sort.bat
  63.     )
  64. )
  65. ren list.txt next.txt
  66.  
  67. :play
  68. REM if playlist was already created, pick next title and play, ignore the rest
  69. set /p line=< next.txt
  70. for /f "tokens=*" %%a in (next.txt) do (
  71.     REM check if line is not empty
  72.     if not "%%a" == "" (
  73.         if "%line%"=="%%a" (
  74.             REM first line entry is started/played
  75.             echo starting: %%a
  76.             start "" "%%a"
  77.             REM put entry in watched.txt
  78.             echo %%a>> watched.txt
  79.         ) else (
  80.             REM rest of the lines are copied into a new file, effectively reving the first line
  81.             echo %%a>> temp.txt
  82.         )
  83.     )
  84. )
  85. del next.txt
  86. ren temp.txt next.txt
Add Comment
Please, Sign In to add comment