Skip to content

Instantly share code, notes, and snippets.

@mbainrot
Created January 28, 2014 10:26
Show Gist options
  • Save mbainrot/8665290 to your computer and use it in GitHub Desktop.
Save mbainrot/8665290 to your computer and use it in GitHub Desktop.
Simple little script to automatically play a youtube file in debian
#!/usr/bin/perl
$videoId = "PhGtxxxorPk";
$url = "https://www.youtube.com/watch/?v=$videoId";
$playURL = "https://www.youtube.com/embed/$videoId?rel=0&autoplay=1";
# Remove temp file
`rm temp.html`;
# Fetch "video"
$cmd = "wget -O temp.html \"$url\"";
`$cmd`;
$data = `cat temp.html | grep duration | grep meta`;
# now we have " <meta itemprop="duration" content="PT68M32S">"
# Strip the crap out
# Remove the first part of the string
$data =~ s/<meta itemprop="duration"//g;
# Remove the spaces
$data =~ s/ //g;
# We should now have something looking alot like this "content="PT68M32S">"
# Remove the rest of the shinaticans
$data =~ s/content="//g;
$data =~ s/">//g;
$data =~ s/PT//g;
$data =~ s/M/,/; # NOT being greedy this time :)
$data =~ s/S//; # NOT being greedy this time :)
chomp $data;
# Now we have the following "68,32"
print "Video Duration (mm,ss): $data\n";
@dataParts = split(',',$data);
$minutes = $dataParts[0];
$seconds = $dataParts[1];
$totalSeconds = $seconds + ($minutes * 60);
print "Processed duration... Minutes = $minutes, Seconds = $seconds, Total Duration (seconds): $totalSeconds\n";
$totalSeconds += 5; # add some leeway for loading time
print "Launching iceweasel and then waiting $totalSeconds, before killing it!\n";
system ("iceweasel \"$playURL\" &");
$pidraw = `ps -eo pid,cmd | grep $videoId | grep iceweasel`;
chomp $pidraw;
@pidBits = split(' ',$pidraw);
$pid = $pidBits[0];
print "Target Process id is $pid";
`sleep $totalSeconds`;
`kill -s 9 $pid`;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment