LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories
User Name
Password
LinuxQuestions.org Member Success Stories Just spent four hours configuring your favorite program? Just figured out a Linux problem that has been stumping you for months?
Post your Linux Success Stories here.

Notices


Reply
  Search this Thread
Old 11-26-2017, 05:58 PM   #1
zpimp
Member
 
Registered: Oct 2014
Posts: 68

Rep: Reputation: Disabled
download and convert multiple youtube links


so i wanted to get music from youtube

this is the simple version, it gets files one by one, it only supports video urls (no playlists)
you need to have youtube-dl installed (latest version)
i got it from here https://packages.debian.org/sid/all/youtube-dl/download
just put your youtube urls in file called "list0.txt" one on each line
it downloads m4a (audio only) and then converts to mp3


Code:
#!/bin/bash
START=$(date +%s)
 
echo "get links and download files one by one"
youtube-dl -a list.txt --no-warnings --no-check-certificate -f 140
 
echo "convert files one by one"
for i in *.m4a; do ffmpeg -i "$i" -acodec libmp3lame -aq 2 "${i%.*}.mp3"; done
 
END=$(date +%s)
DIFF=$(( $END - $START ))
echo time-is  $DIFF

this is the second version, it does stuff in parallel
for this you also need to install aria2 and gnu parallel

just put your youtube urls (videos/playlists/channels) in "list0.txt" one on each line


Code:
#!/bin/bash
 
echo log started - $(date) > g.log

START=$(date +%s)

youtube-dl -a list0.txt -j --flat-playlist --no-check-certificate  > list1.txt
cat list1.txt |sed 's/": "/__/g ; s/"/_/g; s/,/|/g ;'|grep -Po '_id__(.{11})_\|'|sort|uniq | sed 's/_id__//g;s/_|//g' \
 |sed -e 's/^/https:\/\/www.youtube.com\/watch?v=/'>list2.txt

END=$(date +%s)
DIFF=$(( $END - $START ))
echo get video ids from links - serial youtube-dl - $DIFF >> g.log

#=====================================

START=$(date +%s)

cat list2.txt|parallel -j8 youtube-dl "{}" --no-warnings --no-check-certificate --skip-download -q -f 140 --get-filename --get-url -o "\|\|%\(id\)s_%\(title\)s.m4a" \> \$\{RANDOM\}.ttt
cat *.ttt|sed 's/||/  out=/g'>d2.txt
rm *.ttt


END=$(date +%s)
DIFF=$(( $END - $START ))
echo get download links - parallel youtube-dl - $DIFF >> g.log

#=====================================

START=$(date +%s)

echo "download - parallel"
echo time = $(date)
aria2c --check-certificate=false -i d2.txt -j 4

END=$(date +%s)
DIFF=$(( $END - $START ))
echo download video/audio - aria2 - $DIFF >> g.log

#=====================================

START=$(date +%s)

echo "convert - parallel"
echo time = $(date)
find . -name "*.m4a" |parallel -j2  ffmpeg -i "{}" -acodec libmp3lame -aq 2 "{}.mp3"
 
END=$(date +%s)
DIFF=$(( $END - $START ))
echo convert audio/video - parallel ffmpeg - $DIFF >> g.log
the m4a/aac format is better quality, most of devices nowadays support it and is smaller in size, the mp3 conversion takes some time, but its supported by any device

tell me what you think

Last edited by zpimp; 11-26-2017 at 06:01 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: youtube-dl download Youtube videos from linux command Line LXer Syndicated Linux News 0 06-24-2014 01:11 PM
download multiple video from youtube newbie0101 Linux - Software 1 04-01-2012 09:51 AM
download issue from youtube site using Firefox addon download helper ubume2 General 0 09-27-2011 08:51 AM
LXer: YouTube and GNU/Linux: download and convert videos the easy way LXer Syndicated Linux News 0 12-11-2008 06:11 PM
LXer: Youtube-dl - Download videos from Youtube in openSUSE LXer Syndicated Linux News 1 08-14-2008 09:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General > LinuxQuestions.org Member Success Stories

All times are GMT -5. The time now is 03:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration