Android Open Source - epgreader-android E P G Reader Url Finder






From Project

Back to project page epgreader-android.

License

The source code is released under:

Apache License

If you think the Android project epgreader-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.jeffpalm.android.epg.app;
/*from   ww  w.  j a  v a  2  s  .  co m*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import android.net.Uri;
import android.util.Log;

/**
 * A class to find the MP4 video URL given a video page URL.
 */
public final class EPGReaderUrlFinder {

  private static final String TAG = "TMZUrlFinder";

  // "videoUrl":
  // "http:\/\/tmz.vo.llnwd.net\/o28\/2014-05\/04\/0_35wig9pj_0_3yuavu7l_2.mp4",
  private static final Pattern VIDEO_URL_PATTERN = Pattern.compile("\"videoUrl\":\\s+\"([^\"]+)\"");

  // class="lightbox-link" href="http://www.tmz.com/videos/0_vcbn115m"
  private static final Pattern VIDEO_PAGE_URL_PATTERN = Pattern
      .compile("class=\"lightbox-link\"\\s+href=\"([^\"]+)\"");

  // <img alt="0828-joan-rivers-tmz-05"
  // src="http://ll-media.tmz.com/2014/08/30/0828-joan-rivers-tmz-6.jpg">
  private static final Pattern WEB_PAGE_IMAGE_URL_PATTERN = Pattern
      .compile("<img alt=\"[^\"]+\"\\s*src=\"(http:\\/\\/ll-media.tmz.com\\/[^\"]+)\"");

  /**
   * 
   * @param webPageUrl url of the mobile web page story
   * @return the main photo src URL or null if not found
   * @throws IOException
   */
  public Uri getPhotoUrl(String webPageUrl) throws IOException {
    Log.d(TAG, "getPhotoUrl url=" + webPageUrl);
    return getPageUri(webPageUrl, WEB_PAGE_IMAGE_URL_PATTERN);
  }

  /**
   * @param storyUrl The main story url -- e.g. http://www.tmz.com/2014/05/04/obama-president
   *          -wash-car-white-house-correspondents-dinner-secret-service/
   * @return
   * @throws IOException MP4 url for the main story url
   */
  public Uri getStoryUrl(String storyUrl) throws IOException {
    Log.d(TAG, "Finding video page for " + storyUrl);
    String videoPageUrl = getVideoPageUrl(storyUrl);
    Log.d(TAG, "Found video page " + videoPageUrl);
    if (videoPageUrl == null) {
      return null;
    }
    return getVideoUri(videoPageUrl);
  }

  private String getVideoPageUrl(String storyUrl) throws IOException {
    return getPageUrl(storyUrl, VIDEO_PAGE_URL_PATTERN);
  }

  private String getPageUrl(String link, Pattern p) throws IOException {
    Uri uri = getPageUri(link, p);
    return uri != null ? uri.toString() : null;
  }

  private Uri getPageUri(String link, Pattern p) throws IOException {
    URL url = new URL(link);
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    try {
      String line;
      while ((line = in.readLine()) != null) {
        Matcher m = p.matcher(line);
        if (m.find()) {
          String resultString = m.group(1);
          try {
            return Uri.parse(resultString);
          } catch (Exception ignored) {
          }
        }
      }
    } finally {
      in.close();
    }
    return null;
  }

  /**
   * @param storyUrl The video url -- e.g. www.tmz.com/videos/0_35wig9pj/
   * @return
   * @throws IOException MP4 url for the video story url
   */
  public Uri getVideoUri(String videoPageUrl) throws IOException {
    Log.d(TAG, "Finding video URI for " + videoPageUrl);
    Uri uri = getVideoUriInternal(videoPageUrl);
    Log.d(TAG, "Found video URI " + uri);
    return uri;
  }

  private Uri getVideoUriInternal(String videoPageUrl) throws IOException {
    URL url = new URL(videoPageUrl);
    BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
    try {
      Pattern p = VIDEO_URL_PATTERN;
      String line;
      while ((line = in.readLine()) != null) {
        Matcher m = p.matcher(line);
        if (m.find()) {
          String videoUrl = m.group(1);
          videoUrl = videoUrl.replaceAll("\\\\", "");
          try {
            return Uri.parse(videoUrl);
          } catch (Exception e) {
          }
        }
      }
    } finally {
      in.close();
    }
    return null;
  }
}




Java Source Code List

com.example.android.imagedownloader.ImageDownloader.java
com.jeffpalm.android.epg.AbstractEPGItem.java
com.jeffpalm.android.epg.AbstractEPGNode.java
com.jeffpalm.android.epg.EPGContentTest.java
com.jeffpalm.android.epg.EPGContent.java
com.jeffpalm.android.epg.EPGIndexTest.java
com.jeffpalm.android.epg.EPGIndex.java
com.jeffpalm.android.epg.EPGItemTestCase.java
com.jeffpalm.android.epg.EPGItem.java
com.jeffpalm.android.epg.EPGLinkItemTest.java
com.jeffpalm.android.epg.EPGLinkItem.java
com.jeffpalm.android.epg.EPGNode.java
com.jeffpalm.android.epg.EPGParserTest.java
com.jeffpalm.android.epg.EPGParser.java
com.jeffpalm.android.epg.EPGSectionTest.java
com.jeffpalm.android.epg.EPGSection.java
com.jeffpalm.android.epg.EPGTestUtil.java
com.jeffpalm.android.epg.EPG.java
com.jeffpalm.android.epg.app.DefaultOnActivityCreatedNotifier.java
com.jeffpalm.android.epg.app.EPGApplication.java
com.jeffpalm.android.epg.app.EPGReaderConstants.java
com.jeffpalm.android.epg.app.EPGReaderFragment.java
com.jeffpalm.android.epg.app.EPGReaderItemListFragment.java
com.jeffpalm.android.epg.app.EPGReaderPreferencesActivity.java
com.jeffpalm.android.epg.app.EPGReaderSharedPrefs.java
com.jeffpalm.android.epg.app.EPGReaderUrlFinder.java
com.jeffpalm.android.epg.app.EPGReaderUtil.java
com.jeffpalm.android.epg.app.Feature.java
com.jeffpalm.android.epg.app.FeedLoader.java
com.jeffpalm.android.epg.app.HeaderFragment.java
com.jeffpalm.android.epg.app.ItemListActivity.java
com.jeffpalm.android.epg.app.ItemListAdapter.java
com.jeffpalm.android.epg.app.ItemListFragment.java
com.jeffpalm.android.epg.app.NoContentFragment.java
com.jeffpalm.android.epg.app.OnActivityCreatedNotifier.java
com.jeffpalm.android.epg.app.PhotoGalleryAdapter.java
com.jeffpalm.android.epg.app.PhotoGalleryFragment.java
com.jeffpalm.android.epg.app.PhotoItemFragment.java
com.jeffpalm.android.epg.app.VideoItemFragment.java
com.jeffpalm.android.epg.app.WebItemFragment.java
com.jeffpalm.android.tmz.model.AbstractTMZItem.java
com.jeffpalm.android.tmz.model.AbstractTMZNode.java
com.jeffpalm.android.tmz.model.DefaultTMZAdapter.java
com.jeffpalm.android.tmz.model.TMZAdapter.java
com.jeffpalm.android.tmz.model.TMZContentCache.java
com.jeffpalm.android.tmz.model.TMZContentTest.java
com.jeffpalm.android.tmz.model.TMZContent.java
com.jeffpalm.android.tmz.model.TMZFactoryHelper.java
com.jeffpalm.android.tmz.model.TMZFactoryHolder.java
com.jeffpalm.android.tmz.model.TMZFactoryTest.java
com.jeffpalm.android.tmz.model.TMZFactory.java
com.jeffpalm.android.tmz.model.TMZIndexTest.java
com.jeffpalm.android.tmz.model.TMZIndexWrapperTest.java
com.jeffpalm.android.tmz.model.TMZIndexWrapper.java
com.jeffpalm.android.tmz.model.TMZIndex.java
com.jeffpalm.android.tmz.model.TMZItemTestCase.java
com.jeffpalm.android.tmz.model.TMZItem.java
com.jeffpalm.android.tmz.model.TMZLinkItemTest.java
com.jeffpalm.android.tmz.model.TMZLinkItem.java
com.jeffpalm.android.tmz.model.TMZNode.java
com.jeffpalm.android.tmz.model.TMZSectionTest.java
com.jeffpalm.android.tmz.model.TMZSection.java
com.jeffpalm.android.tmz.model.TMZTestCase.java
com.jeffpalm.android.tmz.model.TMZTestUtil.java
com.jeffpalm.android.tmz.model.TMZTest.java
com.jeffpalm.android.tmz.model.TMZWrapperTest.java
com.jeffpalm.android.tmz.model.TMZWrapper.java
com.jeffpalm.android.tmz.model.TMZ.java
com.jeffpalm.android.util.Asserts.java
com.jeffpalm.android.util.ExpandableValueTest.java
com.jeffpalm.android.util.ExpandableValue.java
com.jeffpalm.android.util.ShiftSetTest.java
com.jeffpalm.android.util.ShiftSet.java
com.jeffpalm.android.util.TMZUrlFinderTest.java
com.jeffpalm.android.util.UtilTest.java
com.jeffpalm.android.util.Util.java
com.jeffpalm.android.util.urls.DatabaseHandler.java
com.jeffpalm.android.util.urls.DatabaseHelper.java
com.jeffpalm.android.util.urls.StringInputStream.java
com.jeffpalm.android.util.urls.URLCache.java
com.jeffpalm.android.util.urls.WriteToDatabaseOnCloseInputStream.java