Skip to content

Commit

Permalink
Merge pull request #125 from vrienstudios/develop
Browse files Browse the repository at this point in the history
merge devel into master
  • Loading branch information
ShujianDou authored Aug 11, 2022
2 parents 4c20910 + 0eec3ec commit 99f9d8b
Show file tree
Hide file tree
Showing 2 changed files with 127 additions and 38 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
| SITE | Search | Download |
|-------------------|--------|----------|
| NovelHall | YES | YES |
| VidStream (anime) | YES | YES |
| MangaKakalot | NO | NO |
| VidStream (anime) | YES | YES |
| MangaKakalot | YES | YES |

| NOVELS | VIDEO | MANGA |
|-----------|-----------|-------|
| NovelHall | VidStream | NONE |
| NOVELS | VIDEO | MANGA |
|-----------|-----------|---------------|
| NovelHall | VidStream | MangaKakalot |

## Goal Of This Port

Expand Down
155 changes: 122 additions & 33 deletions src/animeDL.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,39 @@ import EPUB, EPUB/genericHelpers
# TODO: Implement params/commandline arguments.

block:
type Segment = enum
Quit, Welcome,
Novel, NovelSearch, NovelDownload, NovelUrlInput,
Anime, AnimeSearch, AnimeUrlInput, AnimeDownload,
Manga, MangaSearch, MangaUrlInput, MangaDownload

var usrInput: string
var downBulk: bool
var curSegment: int = 0
var curSegment: Segment = Segment.Welcome
var novelObj: Novel
var videoObj: Video

proc WelcomeScreen() =
stdout.styledWriteLine(ForegroundColor.fgRed, "Welcome to anime-dl 3.0")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t1) Anime")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t2) Novel")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t3) (SOON) Manga")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t3) Manga")
while true:
stdout.styledWrite(ForegroundColor.fgGreen, "0 > ")
usrInput = readLine(stdin)
if usrInput.len > 1 or ord(usrInput[0]) <= ord('1') and ord(usrInput[0]) >= ord('3'):
stdout.styledWriteLine(ForegroundColor.fgRed, "ERR: put isn't 1, 2, 3")
continue
if usrInput[0] == '1':
curSegment = 6
curSegment = Segment.Anime
break
if usrInput[0] == '2':
curSegment = 2
curSegment = Segment.Novel
break
if usrInput[0] == '3':
stdout.styledWriteLine(ForegroundColor.fgRed, "MANGA NOT AVAILABLE RIGHT NOW")
curSegment = Segment.Manga
break

proc NovelScreen() =
stdout.styledWriteLine(ForegroundColor.fgRed, "novel-dl (Utilizing NovelHall, for now)")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t1) Search")
Expand All @@ -42,10 +50,10 @@ block:
continue
if usrInput[0] == '1':
novelObj = GenerateNewNovelInstance("NovelHall", "")
curSegment = 3
curSegment = Segment.NovelSearch
break
elif usrInput[0] == '2':
curSegment = 5
curSegment = Segment.NovelUrlInput
break
proc NovelSearchScreen() =
stdout.styledWrite(ForegroundColor.fgWhite, "Enter Search Term:")
Expand All @@ -69,32 +77,36 @@ block:
stdout.styledWriteLine(ForegroundColor.fgRed, "ERR: Doesn't seem to be valid input 0-8")
continue
novelObj = GenerateNewNovelInstance("NovelHall", mSeq[parseInt(usrInput)].uri)
curSegment = 4
curSegment = Segment.NovelDownload
break
proc NovelUrlInputScreen() =
stdout.styledWriteLine(ForegroundColor.fgWhite, "Paste/Type URL:")
stdout.styledWrite(ForegroundColor.fgGreen, "0 > ")
usrInput = readLine(stdin)
novelObj = GenerateNewNovelInstance("NovelHall", usrInput)
curSegment = 4
curSegment = Segment.NovelDownload
proc NovelDownloadScreen() =
discard novelObj.getChapterSequence
discard novelObj.getMetaData()
var idx: int = 1
var epb: Epub = Epub(title: novelObj.metaData.name, author: novelObj.metaData.author)
discard epb.StartEpubExport("./" & novelObj.metaData.name)
for chp in novelObj.chapters:
stdout.styledWriteLine(fgGreen, $idx, "/", $novelObj.chapters.len, fgWhite, chp.name)
eraseLine()
stdout.styledWriteLine(fgRed, $idx, "/", $novelObj.chapters.len, " ", fgWhite, chp.name, " ", fgGreen, "Mem: ", $getOccupiedMem(), "/", $getFreeMem())
cursorUp 1
let nodes = novelObj.getNodes(chp)
discard epb.AddPage(GeneratePage(nodes, chp.name))
inc idx
cursorDown 1
var coverBytes: string = ""
try:
coverBytes = novelObj.ourClient.getContent(novelObj.metaData.coverUri)
except:
stdout.styledWriteLine(fgRed, "Could not get novel cover, does it exist?")
discard epb.EndEpubExport("001001", "ADLCore", coverBytes)
curSegment = -1
curSegment = Segment.Quit

proc AnimeScreen() =
stdout.styledWriteLine(ForegroundColor.fgRed, "anime-dl (Utilizing vidstream, for now)")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t1) Search")
Expand All @@ -108,10 +120,10 @@ block:
continue
if usrInput[0] == '1':
videoObj = GenerateNewVideoInstance("vidstreamAni", "")
curSegment = 7
curSegment = Segment.AnimeSearch
break
elif usrInput[0] == '2':
curSegment = 8
curSegment = Segment.AnimeUrlInput
break
proc AnimeSearchScreen() =
stdout.styledWriteLine(ForegroundColor.fgWhite, "Enter Search Term:")
Expand All @@ -137,7 +149,7 @@ block:
videoObj = GenerateNewVideoInstance("vidstreamAni", mSeq[parseInt(usrInput)].uri)
discard videoObj.getMetaData()
discard videoObj.getStream()
curSegment = 9
curSegment = Segment.AnimeDownload
break
proc AnimeUrlInputScreen() =
stdout.styledWriteLine(ForegroundColor.fgWhite, "Paste/Type URL:")
Expand All @@ -146,21 +158,24 @@ block:
videoObj = GenerateNewVideoInstance("vidstreamAni", usrInput)
discard videoObj.getMetaData()
discard videoObj.getStream()
curSegment = 9
curSegment = Segment.AnimeDownload

proc loopVideoDownload() =
stdout.styledWriteLine(fgWhite, "Downloading video for " & videoObj.metaData.name)
while videoObj.downloadNextVideoPart("./$1.mp4" % [videoObj.metaData.name]):
stdout.styledWriteLine(ForegroundColor.fgWhite, "Got ", ForegroundColor.fgRed, $videoObj.videoCurrIdx, fgWhite, " of ", fgRed, $(videoObj.videoStream.len - 1))
cursorUp 1
eraseLine()
if videoObj.audioStream.len <= 0:
stdout.styledWriteLine(ForegroundColor.fgWhite, "Got ", ForegroundColor.fgRed, $videoObj.videoCurrIdx, fgWhite, " of ", fgRed, $(videoObj.videoStream.len - 1), " ", fgGreen, "Mem: ", $getOccupiedMem(), "/", $getFreeMem())
cursorUp 1
cursorDown 1
if videoObj.audioStream.len > 0:
stdout.styledWriteLine(fgWhite, "Downloading audio for " & videoObj.metaData.name)
while videoObj.downloadNextAudioPart("./$1.ts" % [videoObj.metaData.name]):
stdout.styledWriteLine(ForegroundColor.fgWhite, "Got ", ForegroundColor.fgRed, $videoObj.audioCurrIdx, fgWhite, " of ", fgRed, $(videoObj.audioStream.len - 1))
stdout.styledWriteLine(ForegroundColor.fgWhite, "Got ", ForegroundColor.fgRed, $videoObj.audioCurrIdx, fgWhite, " of ", fgRed, $(videoObj.audioStream.len - 1), " ", fgGreen, "Mem: ", $getOccupiedMem(), "/", $getFreeMem())
cursorUp 1
eraseLine()
cursorDown 1
# TODO: merge formats.

proc AnimeDownloadScreen() =
# Not Finalized
assert videoObj != nil
Expand All @@ -182,7 +197,7 @@ block:
stdout.styledWriteLine(ForegroundColor.fgRed, "ERR: Doesn't seem to be valid input 0-^1")
continue
break
let selMedia = mVid[parseInt(usrInput)]
let selMedia = mVid[parseInt(usrInput) - 1]
videoObj.selResolution(selMedia)
if downBulk:
let mData = videoObj.getEpisodeSequence()
Expand All @@ -196,20 +211,94 @@ block:
loopVideoDownload()
else:
loopVideoDownload()
curSegment = -1
curSegment = Segment.Quit

proc MangaScreen() =
stdout.styledWriteLine(ForegroundColor.fgRed, "manga-dl (Utilizing MangaKakalot, for now)")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t1) Search")
stdout.styledWriteLine(ForegroundColor.fgWhite, "\t2) Download")
while true:
stdout.styledWrite(ForegroundColor.fgGreen, "0 > ")
usrInput = readLine(stdin)
if usrInput.len > 1 or ord(usrInput[0]) <= ord('1') and ord(usrInput[0]) >= ord('2'):
stdout.styledWriteLine(ForegroundColor.fgRed, "ERR: put isn't 1, 2")
continue
if usrInput[0] == '1':
novelObj = GenerateNewNovelInstance("MangaKakalot", "")
curSegment = Segment.MangaSearch
break
elif usrInput[0] == '2':
curSegment = Segment.MangaUrlInput
break
proc MangaSearchScreen() =
stdout.styledWrite(ForegroundColor.fgWhite, "Enter Search Term:")
stdout.styledWrite(ForegroundColor.fgGreen, "0 > ")
usrInput = readLine(stdin)
let mSeq = novelObj.searchDownloader(usrInput)
var idx: int = 0
var mSa: seq[MetaData]
if mSeq.len > 9:
mSa = mSeq[0..9]
else:
mSa = mSeq
for mDat in mSa:
stdout.styledWriteLine(ForegroundColor.fgGreen, $idx, fgWhite, " | ", fgWhite, mDat.name, " | " & mDat.author)
inc idx
while true:
stdout.styledWriteLine(ForegroundColor.fgWhite, "Select Manga:")
stdout.styledWrite(ForegroundColor.fgGreen, "0 > ")
usrInput = readLine(stdin)
if usrInput.len > 1 or ord(usrInput[0]) <= ord('0') and ord(usrInput[0]) >= ord('8'):
stdout.styledWriteLine(ForegroundColor.fgRed, "ERR: Doesn't seem to be valid input 0-8")
continue
novelObj = GenerateNewNovelInstance("MangaKakalot", mSeq[parseInt(usrInput)].uri)
curSegment = Segment.MangaDownload
break
proc MangaUrlInputScreen() =
stdout.styledWriteLine(ForegroundColor.fgWhite, "Paste/Type URL:")
stdout.styledWrite(ForegroundColor.fgGreen, "0 > ")
usrInput = readLine(stdin)
novelObj = GenerateNewNovelInstance("MangaKakalot", usrInput)
curSegment = Segment.MangaDownload
proc MangaDownloadScreen() =
discard novelObj.getChapterSequence
discard novelObj.getMetaData()
var idx: int = 1
var epb: Epub = Epub(title: novelObj.metaData.name, author: novelObj.metaData.author)
discard epb.StartEpubExport("./" & novelObj.metaData.name)
for chp in novelObj.chapters:
eraseLine()
stdout.styledWriteLine(fgRed, $idx, "/", $novelObj.chapters.len, " ", fgWhite, chp.name, " ", fgGreen, "Mem: ", $getOccupiedMem(), "/", $getFreeMem())
cursorUp 1
let nodes = novelObj.getNodes(chp)
discard epb.AddPage(GeneratePage(nodes, chp.name))
inc idx
cursorDown 1
var coverBytes: string = ""
try:
coverBytes = novelObj.ourClient.getContent(novelObj.metaData.coverUri)
except:
stdout.styledWriteLine(fgRed, "Could not get manga cover, does it exist?")
discard epb.EndEpubExport("001001", "ADLCore", coverBytes)
curSegment = Segment.Quit

while true:
case curSegment:
of -1:
of Segment.Quit:
quit(1)
of 0: WelcomeScreen()
of 2: NovelScreen()
of 3: NovelSearchScreen()
of 4: NovelDownloadScreen()
of 5: NovelUrlInputScreen()
of 6: AnimeScreen()
of 7: AnimeSearchScreen()
of 8: AnimeUrlInputScreen()
of 9: AnimeDownloadScreen()
else:
quit(-1)
of Segment.Welcome: WelcomeScreen()

of Segment.Novel: NovelScreen()
of Segment.NovelSearch: NovelSearchScreen()
of Segment.NovelUrlInput: NovelUrlInputScreen()
of Segment.NovelDownload: NovelDownloadScreen()

of Segment.Anime: AnimeScreen()
of Segment.AnimeSearch: AnimeSearchScreen()
of Segment.AnimeUrlInput: AnimeUrlInputScreen()
of Segment.AnimeDownload: AnimeDownloadScreen()

of Segment.Manga: MangaScreen()
of Segment.MangaSearch: MangaSearchScreen()
of Segment.MangaUrlInput: MangaUrlInputScreen()
of Segment.MangaDownload: MangaDownloadScreen()

0 comments on commit 99f9d8b

Please sign in to comment.