wget

2013-01-16 15 views
15

के साथ YouTube वीडियो डाउनलोड करें I आमतौर पर keepvid.com या फ़ायरफ़ॉक्स डाउनलोड सहायक प्लगइन का उपयोग YouTube वीडियो को डॉउलोड करने के लिए करते हैं। क्या लिनक्स में उपलब्ध wget कमांड के साथ उन्हें डाउनलोड करना संभव है?wget

इसके अलावा, मेरे पास एक वीपीएस सर्वर है। मैं अपने वीपीएस सर्वर (सीपीनल) पर वीडियो डाउनलोड करना चाहता हूं।

यदि संभव है और यदि ऐसा है तो कैसे?

धन्यवाद।

उत्तर

18
#!/usr/bin/perl 

use strict; 
use warnings; 
## Two arguments 
## $1 YouTube URL from the browser 
## $2 Prefix to the file name of the video (optional) 
# 

## Collect the URL from the command line argument 
my $url = $ARGV[0] or die "\nError: You need to specify a YouTube URL\n\n"; 

## Declare the user defined file name prefix 
my $prefix = defined($ARGV[1]) ? $ARGV[1] : ""; 

## Download the HTML code from the YouTube page 
my $html = `wget -Ncq -e "convert-links=off" --keep-session-cookies --save-cookies /dev/null --no-check-certificate "$url" -O-` or die "\nThere was a problem downloading the HTML file.\n\n"; 

## Collect the title of the page to use as the file name 
my ($title) = $html =~ m/<title>(.+)<\/title>/si; 
$title =~ s/[^\w\d]+/_/g; 
$title =~ s/_youtube//ig; 
$title =~ s/^_//ig; 
$title = lc ($title); 

## Collect the URL of the video 
my ($download) = $html =~ /"url_encoded_fmt_stream_map"([\s\S]+?)\,/ig; 

## Clean up the URL by translating Unicode and removing unwanted strings 
$download =~ s/\:\ \"//; 
$download =~ s/%3A/:/g; 
$download =~ s/%2F/\//g; 
$download =~ s/%3F/\?/g; 
$download =~ s/%3D/\=/g; 
$download =~ s/%252C/%2C/g; 
$download =~ s/%26/\&/g; 
$download =~ s/sig=/signature=/g; 
$download =~ s/\\u0026/\&/g; 
$download =~ s/(type=[^&]+)//g; 
$download =~ s/(fallback_host=[^&]+)//g; 
$download =~ s/(quality=[^&]+)//g; 

## Collect the URL and signature since the HTML page randomizes the order 
my ($signature) = $download =~ /(signature=[^&]+)/; 
my ($youtubeurl) = $download =~ /(http.+)/; 
$youtubeurl =~ s/&signature.+$//; 

## Combine the URL and signature in order to use in Wget 
$download = "$youtubeurl\&$signature"; 

## A bit more cleanup 
$download =~ s/&+/&/g; 
$download =~ s/&itag=\d+&signature=/&signature=/g; 

## Print the file name of the video collected from the web page title for us to see on the CLI 
print "\n Download: $prefix$title.webm\n\n"; 

## Download the file using Wget and background the Wget process 
system("wget -Ncq -e \"convert-links=off\" --load-cookies /dev/null --tries=50 --timeout=45 --no-check-certificate \"$download\" -O $prefix$title.webm &"); 

#### EOF ##### 

यह एक पर्ल स्क्रिप्ट है जिसे मैं थोड़ी देर के लिए उपयोग कर रहा हूं। मुझे यकीन नहीं है कि यह कहां से है ... यह बहुत अच्छा काम करता है।

+0

धन्यवाद आपका हिस्सा। यह काम करता है। –

+0

ग्रेट, इसका काम ... – Amini

+0

टिप्पणी कर रहा है क्योंकि मैंने इस स्क्रिप्ट को आज तीन अलग-अलग वीडियो पर आजमाया, और उन सभी के लिए यह एक खाली फाइल बनाई। समस्या यूट्यूब के साथ कुछ बदलाव हो सकती है। मैंने अभी तक समस्या निवारण नहीं किया है, लेकिन मैं एक चेतावनी जोड़ना चाहता था। – LiberalArtist

19

मैं YouTube और अन्य वीडियो साइटों से कंसोल डाउनलोडर के रूप में youtube-dl की अनुशंसा करता हूं।

+3

पार्टी के लिए थोड़ा देर हो चुकी है, लेकिन पता चला कि यह होमब्रू के माध्यम से स्थापित किया जा सकता है। बहुत आसान, धन्यवाद! – JAL

+0

$ सूडो पाइप यूट्यूब-डीएल स्थापित करें –

संबंधित मुद्दे