/* * [Video.java] * * Summary: Generate a reference to Video. Click on the audio icon to see. * * Copyright: (c) 2009-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.8 2009-02-06 include go package in ZIP bundle. * 1.9 2009-08-04 add Freelance and optional description. */ package com.mindprod.htmlmacros.macro; import com.mindprod.amper.Amper; import com.mindprod.fastcat.FastCat; import com.mindprod.htmlmacros.support.BuildImage; import com.mindprod.htmlmacros.support.ImageAlignment; import java.io.File; import static java.lang.System.*; /** * Generate a reference to Video. Click on the audio icon to see. *

* * @author Roedy Green, Canadian Mind Products * @version 1.9 2009-08-04 add Freelance and optional description. * @noinspection WeakerAccess * @see com.mindprod.htmlmacros.macro.VideoFormat * @see VideoFormat for the various flavours of video, in this source file. * @since 2009 */ public final class Video extends Macro { /** * how to use the macro, works with ampered on unampered URL. */ private static final String USAGE = "\nVideo macro needs mediaURL format(e.g. bittorrent dailymotion divx dvd flash" + " freelance " + "google html5 mpg mp3 mp4 ms pp qt real shockwave vhs youtube lyrics transcript unknown) " + "[desc]"; /** * guts to Generate reference to a Video reference. * * @param videoURL qualified reference to an video file, relative or absolute. * @param format format ofDVDd flash mp3 mp4 ms qt real unknown vhs google. * @param desc description of the video * @param fileBeingProcessed the file currently being processed. * * @return expand ref with icon. * @noinspection CanBeStatic */ private static String expand( String videoURL, VideoFormat format, String desc, final File fileBeingProcessed ) { final FastCat sb = new FastCat( 9 ); sb.append( "\n" ); if ( desc.length() > 0 ) { sb.append( "", desc, " " ); } sb.append( BuildImage.buildImgTag( "video/" + format + ".png", "click to watch", ImageAlignment.middle, !videoURL.contains( "ericblumrich" ) ? null : "broken"/* cssclass */, fileBeingProcessed ) ); sb.append( "" ); return sb.toString(); } /** * Generate Video icon to hear a broadcast typical use: *

* *

* Expands: click to watch. * * @param parms first is video file, absolute or relative, second is code for format: dvd flash mp3 mp4 * ms pp qt real unknown vhs google. * @param quiet true if want output suppressed. * @param verbose @return expanded macro HTML */ public final String expandMacro( String[] parms, final boolean quiet, final boolean verbose ) { if ( !quiet ) { out.print( "V" ); } if ( !( 2 <= parms.length && parms.length <= 3 ) ) { throw new IllegalArgumentException( USAGE ); } final String video = Amper.ampifyUncommentedString( parms[ 0 ] ); final VideoFormat format = VideoFormat.valueOf( parms[ 1 ].toLowerCase() ); final String desc = ( parms.length > 2 ) ? parms[ 2 ] : ""; // validate url final String[] servers = format.getServers(); boolean valid = servers.length == 0; for ( String server : servers ) { if ( video.startsWith( server ) ) { valid = true; break; } } if ( !valid ) { err.println( "Warning: Unusual server\n " + video + "\n for video type: " + format + " on page " + fileBeingProcessed.toString() + "\n" ); } return expand( video, format, desc, fileBeingProcessed ); } }