Uploading movies to YouTube - the easy way
Post ReplyUploading movies to YouTube - the easy wayPosted: Thursday, June 27, 2013 [10:02:24] - 1
If you need to upload multiple files to YouTube - it can take time. If movies are on the same subject, educational or on any other subject that use a lot of repetition it may be easier to let program do the uploading for you. Program below takes compiled .TXT files with Title, Description and Keywords and a movie file. File Names for .MOV and .TXT files are the same except file extension. Use lower case for file extensions though. All .TXT files can be compiled out of database and movies cut by QTCoffee http://www.3am.pair.com/QTCoffee.html program. The program is an AppleScript written on-the-fly by Perl and run from the Perl program. Perl program run from Terminal. Here is the code: #################################################################################### ## This program is written to save time uploading multiple files ## Do not use it unless you fully aware of YouTube policies. ## Your YouTube account could be terminated for abuse because of use of this program ## Code posted for educational purposes only ## Use it at your own risk! ## Author is not responsible for misuse of the code or any portion of the code #################################################################################### ## Set folder for .mov files - just move the folder onto Terminal window print "Choose upload folder: "; $folder = <STDIN>; unless(-d $folder) {print "No folder: $folder found\n"; ## Choose ho many files to upload print "How many files to process "; $flprocc = <STDIN>; if($flprocc > 1) {$flprocc--;} &getcode; @all = glob("$folder/*"); randomaze( \@all ); ## All files in upload folder - shuffle array of files (optional) foreach $f (@all) { unless($f =~ m/\.mov$/i) {next;} ## Now calculate how big are movie file and add time for upload $flsz = (stat ("$f"))[7]; $flsz /= (1024 * 1024); print "File: Size: $flsz\n"; ## keep in-mind - delay depends on your Internet connection speed and a uploaded file size if($flsz > 4) {$addtime = $flsz - 4; else {$addtime = "\n\-\- Size: $flsz Mb";} $ft=$f; $tot++; unless(-f $ft) {print "\t$tot\. Support file $ft not present -> next\n"; $totd++; if($totd < 2) { ## On first upload make Safari choose the folder $addtocode = "\t\t\t\t\tset x to \"$folder\" \t\t\t\t\tkeystroke \"g\" using {command down, shift down}\n\t\t\t\t\tdelay 1\n\t\t\t\t\tkeystroke x \t\t\t\t\tdelay 1\n\t\t\t\t\tkeystroke return\n\t\t\t\t\tdelay 1\n"; } ## END FIRST RECORD ## Now read the source text file for movie title, description and some keywords ## TXT file has to be named as movie file with .txt extension ## in my case title, description and keywords are separated by double newline - it could be anything just do not forget to replace it on the next line $d = `cat $ft`; ## Do some text replacement if needed $kwd = pop(@lnz); ## Make sure title is not too long or movie will be rejected by YouTube $title =~ s/\,/ /g; if(length($title) > 70) { @ghtr = split(/ /,$title); foreach $hdprt (@ghtr) { $title .= "$ssccma$hdprt"; if(length($title) > 65) {last;} } ## FOREACH END @ghtr=(); } ## TITLE LONDER THAN 70 $ttllngth=length($title); $text =~ s/\n/\n\r/g; print "\n$tot\. ($totd) $f\n________________________________________\n"; print "TITLE: $title\nTEXT: $text\nKEYWORDS: $kwd\n"; ## Print some statistics in Terminal window @fnmz = split(/\//,$f); $tocode1 = "\t\t\t\t\tkeystroke \"$fname\"\n\t\t\t\t\tdelay 1\n\t\t\t\t\tkeystroke return\n"; $codeuse = $code; $title =~ s#\"#\\\"#g; ## This code will enter Title, Description and Keywords into YouTube form ## The only thing for you to do is to choose proper Category and it will stick for the rest of the movies $printcode = "\t\t\t\t\tkeystroke \"a\" using {command down}\n\t\t\t\t\tdelay 1 \t\t\t\t\tkeystroke \"$title\"\n\t\t\t\t\tdelay 1\n\t\t\t\t\tkeystroke tab\t \t\t\t\t\tkeystroke \"$text\"\n\t\t\t\t\tdelay 1\n\t\t\t\t\tkeystroke tab\t\n\t\t\t\t\tdelay 1\n\t\t\t\t\tkeystroke tab\t \t\t\t\t\tkeystroke \"$kwd\"\n\t\t\t\t\tdelay 1"; $codeuse =~ s#!CODE2!#$printcode#; $codeuse =~ s#!ADDTIME!#$addtime#; unless(-d "$folder/codes") {`mkdir $folder/codes`;} unless(-d "$folder/done") {`mkdir $folder/done`;} $fnamecode=$fname; ## Now move the .mov and .txt files to "done" folder ## if anything goes wrong - you can move them back and re-run the program ## it is better if AppleScript will do it ensuring AppleScript was fired ## if not - files will remain in a main folder $manmvv = $f; $toscript = "do shell script \"mv $f $folder/done/$manmvv\"\n"; $toscript .= "do shell script \"touch $folder/done/$manmvv\"\n"; $manmvv = $ft; $toscript .= "do shell script \"mv $ft $folder/done/$manmvv\"\n"; $toscript .= "do shell script \"touch $folder/done/$manmvv\"\n"; $codeuse .= "\n$toscript"; ## now safe the AppleScript code and run it ## See how many movies done and stop if pre-set number was reached if($totd > $flprocc) {exit(0);} } ## FOREACH END ## Sub - get AppleScript code sub getcode { $code = 'tell application "Safari" !CODE1! -- choose delay here according to your movie size and internet connection speed -- delay can also be configured in above Perl code delay 5 !CODE2! -- This will be replaced by code provided by the Perl end tell -- end Safari tell delay 30!ADDTIME! -- additional delay replacement here based on uploaded file size -- close Safari window tell application "System Events" end tell '; } ## END SUB GET CODE sub randomaze { my $array = shift; my $i; for ($i = @$array; --$i; ) { my $j = int rand ($i+1); next if $i == $j; @$array[$i,$j] = @$array[$j,$i]; } return @array; } Enjoy! |