Skip to content

navid-m/newt

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Newt

YouTube downloader library and command-line interface (CLI) built on Nim.

Usage

import newt

# False by default
announceLogs(true)

# Get the info corresponding to the provided URL
let vidInf: VideoInfo = newt.getVideoInfo("https://www.youtube.com/watch?v=5ANuXhk9qWM")

# Get the highest bitrate audio format
let bestAudioFormat: MediaFormat = newt.getBestFormat(vidInf.formats, FormatType.audio)

# Download the stream specified in the bestAudioFormat value
downloadYtStreamByFormat(bestAudioFormat, vidInf.title)

MediaFormat and VideoInfo types

type
  MediaFormat* = object
    itag*: int
    url*: string
    fps*: int
    bitrate*: int64
    averageBitrate*: int64
    mimeType*: string
    codec*: string
    extension*: string
    contentLength*: int64
    audioSampleRate*: int64
    audioChannels*: int
    projectionType*: string
    width*: int
    height*: int
    quality*: string
    qualityLabel*: string
    audioQuality*: string
    lastModified*: Time

type
  VideoInfo* = object
    videoId*: string
    title*: string
    lengthSeconds*: int64
    views*: int
    description*: string
    author*: string
    liveContent*: bool
    private*: bool
    ratingsEnabled*: bool
    channelId*: string
    thumbnailUrls*: seq[string]
    formats*: seq[MediaFormat]

CLI Usage

Download YouTube Video

newt -v <yt-video-url>

Download YouTube Audio

newt -a <yt-video-url>

Get List of Available Formats

newt -f <yt-video-url>

Download by Specific Format

newt -df <yt-video-url> <format-id>

Get Video Details

newt -i <yt-video-url>