Monday, January 7, 2013

Some Cross-Platform Flash Alternatives

(UPDATE: A lot of this is outdated. Mplayer doesn't work with the https links Youtube now throws up, so for OS X I'd recommend PPC Media Center, and on Linux you can use Mpv with the following bash script:

#!/bin/bash
mpv --framedrop=vo --cache 8192 --cache-initial 820 $(youtube-dl -gf 18 $(xsel --clipboard))


Save it in a text editor as something.sh and make it executable with "chmod u+x /the/path/to/something.sh". The script requires Mpv, Youtube-dl, and xsel, and when you copy a video URL to the clipboard launching the script will stream the video. END UPDATE)

Put that in a #!/bin/bash script and you can just copy the video URL to clipboard and launch. This is assuming you have mpv, youtube-dl, and xsel all installed. END UPDATE)

By now you probably know about MacTubes for OS X, and I've written about quvi on Linux, but I think it's worthwhile to go through a few other Flash/Youtube alternatives given the way Google likes to break third party apps by changing its URL paths. Also, MacTubes hasn't been updated in quite awhile and has difficulty on videos with embedded ads, so who knows how long before it completely breaks? We need workarounds that have a history of rapid updates, and that's what this post is about.

Like the title says, the three alternatives I've found are cross-platform. One's a python script, and the other two are Greasemonkey scripts that work in Firefox/Iceweasel/TenFourFox.

We're also going to be using Mplayer from the shell to stream the video. You could just as easily use VLC or the new Mplayer fork, Mpv, but since I primarily use Mplayer I'll focus on that.

On Linux you can install Mplayer with your package manager, unless you're on a G3, in which case you have to compile it with the configuration option --disable-altivec (Mpv doesn't have this complication, but it's not yet available in Debian Stable). OS X users can use Macports or Tigerbrew to install Mplayer, or you can find an older pre-compiled binary inside the application package distributed at MPlayer for MacOS X.

Now to the best command line arguments for streaming Youtube, which are:

mplayer -framedrop -cache 8192 -cache-min 10

Those arguments will prevent the picture from lagging the audio, though if you have a slower computer and lagging is still a problem, you can add the argument -lavdopts skiploopfilter=all on h.264 files. Note that last argument will slightly degrade picture quality.

Next, OS X users will want to copy and paste B-G's Mplayer scripts. They're easy to edit if you need to change Mplayer's path or add arguments, and you can save them in your ~/Library/Scripts folder so you won't have to open a terminal to start a vid. As you can see from my scripts menu (enabled in AppleScript Utility), I've created way too many for every conceivable scenario:

AppleScript menu

On Linux we'll set up quick video launching with a bash script. First, install "xsel" with aptitude/apt-get. Then create a text file and paste the following (no carriage returns on the second line):

#!/bin/bash
mplayer -framedrop -cache 8192 -cache-min 10 -cookies -cookies-file ~/.cookie.txt $(youtube-dl -gf 18 --prefer-insecure --cookies ~/.cookie.txt $(xsel --clipboard))


Save it as toob.sh and make it executable with chmod +x path to toob.sh. Don't worry, that script will all make sense in a minute.

Now that Mplayer is set up, let's switch to the video downloader youtube-dl. It's a python script that requires Python 2.6, 2.7, or 3.3. Tiger and Leopard came with 2.3 and 2.5 respectively, so you'll have to update. Python 2.7 works great for me on Tiger. Next, Linux and OS X users can follow the instructions on youtube-dl's download page to install (if curl or wget mysteriously won't work on your OS X system, you can also paste the download URL in your address bar and save the file). Once it's in your /usr/local/bin and made executable, run youtube-dl -U to update to the newest version.

Ordinarily youtube-dl is used to download videos to disk, but for streaming we'll use it to retrieve the video link only. Not the page URL, but the long URL to the actual video. Before we get to the shortcuts, let's do this from the command line to see it all under the hood. In a terminal, enter (on one line):

youtube-dl -gf 18 --prefer-insecure "Youtube page URL inside quotes"

The -g option outputs the video link only, -f 18 specifies the format of the vid, in this case 360p mp4 (with no arguments it defaults to the highest resolution, and -F outputs all available formats). The --prefer-insecure is a new option to deal with Youtube throwing up https links, which Mplayer doesn't handle (Mpv, however, does). Now you'll notice the output is a really long link. That's the link to your video! So to get Mplayer to play it, you enter in a terminal (on one line):

mplayer -quiet -framedrop -cache 8192 -cache-min 10 "youtube-dl output link inside quotes"

and to retrieve the link and play, all in one command, enter (on one line):

mplayer -quiet -framedrop -cache 8192 -cache-min 10 -cookies -cookies-file ~/.cookie.txt $(youtube-dl -gf 18 --prefer-insecure --cookies ~/.cookie.txt "Youtube page URL inside quotes")

Some people say you need those cookies options on some rare videos, so that's why I'm including them. Otherwise, they're harmless.

Now to the shortcuts. In OS X, copying the long link from the youtube-dl output and choosing B-G's streaming script from your AppleScript menu will play the video. Alternately, you can "Save As..." in Terminal.app, and where it says "Execute this command (specify complete path)" enter:

mplayer -quiet -framedrop -cache 8192 -cache-min 10 -cookies -cookies-file ~/.cookie.txt $(youtube-dl -gf 18 --prefer-insecure --cookies ~/.cookie.txt $(pbpaste))

and check "Execute command in a shell". Now when you copy a Youtube page URL to clipboard, choose the command from the File | Library submenu in Terminal.app and the video will play.

On Linux it's even easier. Just copy the Youtube page URL to clipboard and launch that bash script I showed you above. Your video will now play.

So that's one Flash alternative, but I mentioned there were two others. These two are Greasemonkey scripts for Firefox/Iceweasel/TenFourFox, so first install Greasemonkey. Then install the user script Youtube EZ Download. Now when you go to a Youtube page you'll see a box on the lower right corner with a list of download links:

Youtube - EZ Download

In OS X, copy a link to the clipboard, then choose B-G's streaming script from the AppleScript menu and watch the video. In Linux, use the Firefox add-on Open With to create a new menu item for Mplayer and its args. Then right-click a link in the Youtube EZ Download box and choose "Open Link with Mplayer".

Open With add-on

The other Greasemonkey script has been around awhile and is called Viewtube (also in the screenshots). It replaces Youtube's video player with a picture preview and several buttons for playback and downloading. You can use the Play function to play back videos with the gecko-mediaplayer browser plugin and gnome-mplayer, but that's not cross-platform to OS X. OS X users will still find it useful as the Get button works for downloading, and it replaces Youtube's CPU eating no-flash warning with the aforementioned picture preview. It also works with Youtube's Feather Beta.

So there you have it. Streaming Youtube through Mplayer with just a couple of clicks. Also, youtube-dl and these two Greasemonkey scripts have a history of frequent updates so any of Google's periodic breakages shouldn't last long.

I found a couple of other Youtube browsers I didn't try. One was yt, a command line browser, but it didn't have thumbnails so it wasn't for me. Also, there's gtk-youtube-viewer (bottom of page), but I didn't see any documentation about compiling on Debian, and knowing my compiling skills...

Thanks to Peter S. for telling me about youtube-dl :)

UPDATE: There's some good stuff in the comments, too, about UnPlug and more AppleScripts. Read on!

UPDATE II: Peter S. reports playback on his G3 is way smoother with VLC than Mplayer. Here's his VLC + youtube-dl command:

/Applications/VLC.app/Contents/MacOS/VLC $(youtube-dl -gf 18 --prefer-insecure "http://www.youtube.com/watch?v=pSwy412nttI")

So you can adjust all the above commands by pointing to the binary in the VLC app package.

14 comments:

  1. Great post!
    I found a way to use Open With to launch MPlayer in OS X, by using an application bundle derived by the Net To MPLayer script. Just link Open With to it. See:
    http://forums.macrumors.com/showpost.php?p=16623586&postcount=62
    Please notice that the NetToMPLayer application will stay open during playback. It won't consume many resources (almost none, in effect) but if you want to squeeze every drop of performance you better use the scripts. They are more versatile anyway. If you want to change the parameters passed to MPlayer, just open and edit the application in Script Editor.

    ReplyDelete
    Replies
    1. I've had success with these tips so I wanted to say a big THANKS! youtube working via right-click and send to gnome-mplayer on mintppc running on a G4 1Ghz emac with 512 of RAM.

      Delete
  2. By the way, what I use to find video URLs in TenFourFox is UnPlug:

    https://addons.mozilla.org/it/firefox/addon/unplug/

    As the name says, it has been designed to be used without plugins, so it's perfect for TFF. It has a good user interface, it works even with embedded videos, and it is launched only on request, so it won't consume unnecessary resources. Click on the little fish icon and a window containing a list of all the video files available on the page will pop up. Move the mouse over the desired file and a small arrow will appear on the right. Click on it and you will be able to copy the link.
    On paper it should be able to launch VLC, but for some reason this has never worked on OS X (maybe you will have more luck on Linux).

    ReplyDelete
  3. I second the great post! You set the bar very, very high for those of us trying to write a first post!

    I also second unplug. I have yet to find a site that unplug couldn't "see" the video. Well, Hulu, BBC and anything DRM'ed to hell and back won't play.

    Wildy on Macrumors recently showed a neat hack using Gimmeblocker to force sites serve up some HTML 5. I've tried that with TFF and the useragent extentions but most of the time they won't play well on my ibook, but for a faster G4 it could work.

    For spotted cats Click to Flash and Click to Plugin continue to astound with Leopard Webkit, something you can't use on striped Tiger I know. Using B-G's hacked Click to Flash info.plist tells many sites you are Flash 11.5, without having to have the hacked plugin there. Then launch the video in Quicktime and you are golden. Cool beans as the Swiss say.

    ReplyDelete
  4. I can only use the above "toob" method if I CD in a terminal to where toob is located, and ./ in front of toob. Am I missing something Linux-ee, or is that just "understood?".

    ReplyDelete
    Replies
    1. Oops, I forgot to say copy it to your /usr/local/bin. I thought I might also have to use chmod to make it executable, but I tried it without it and it worked.

      Delete
  5. Thank you for this wonderful post! Now I can play any Youtube videos with little to no lag on my G3 800mhz. I am having trouble getting the Apple Scripts to work, but with unplug, I think I will figure it out. I also found a cool thing you can do if you want to save a video for convenient watching on OS X. Just open Text Edit, make it a Plain Text document (Command+Shift+T) and paste the mplayer commands into the document (e.g. mplayer -really-quiet -framedrop -cache 8192 cache-min 10 $(youtube-dl -gf 18 "http://www.youtube.com/watch?v=ZCbI2K9-3bU") )

    Then, go to File/Save As name the file and put a .command on the end, when you click save it will ask if you want to use the .txt or the .command extension, click Use .command. Now, go into the Terminal and chmod it (chmod a+x ~/Movies/video.command).
    When you double click it, the video will hopefully open and start playing.

    ReplyDelete
  6. I've had success with these tips so I wanted to say a big THANKS! youtube working via right-click and send to gnome-mplayer on mintppc running on a G4 1Ghz emac with 512 of RAM.

    ReplyDelete
  7. Another Flash alternative you can do is downloading the Debian Testing version of Minitube here: https://packages.debian.org/jessie/minitube . It works perfectly if you install it on Wheezy with dpkg, and then do a "sudo apt-get -f install" to install all the required dependencies. You can then add Minitube to Open With (It's in /usr/bin), and simply right-clicking any link to a YouTube video will open it in Minitube.

    ReplyDelete
  8. I think the best way to play Youtube movies on PowerPC is YouView. Just use the max 480p setting and all is fine. It plays every Youtube video perfectly on my 1GHz iMac G4.

    ReplyDelete
  9. Being a no-tech user of an old PPC OS 10.4 iMac Desk Lamp i tried You View and it works great, thanks for the tip Wolfram

    ReplyDelete
  10. By the way, if you put a parameter in the "youtube" script (so it's
    mpv --framedrop=vo --cache 8192 --cache-initial 410 $(youtube-dl -gf 18 $1)
    ), you can open that with Open With, thus letting you open any youtube link simply by right-clicking it.

    ReplyDelete