SHARE
TWEET

GET-STREAM

a guest May 24th, 2013 2,342 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. # This is just a simple script to fetch the stream url from a program
  3. #
  4. # Licence WTPL - Do WTF you want with this, just dont remove this comment
  5. # Made for freak.no, by Sauu
  6. #
  7.  
  8. function getStream(){
  9.         local URL=$1
  10.  
  11.         if [[ $URL != *tv.nrk.no* ]]; then
  12.                 echo -e  "Invalid url. U Must provide a real URL!!"
  13.                 exit 1
  14.         fi
  15.  
  16.         echo -e "\e[01;32mTrying to find stream...\e[00m"
  17.         echo "This is Über fancy HTML-Parsing in bash!!"
  18.  
  19.         HTML=`curl $URL`
  20.  
  21.         # See if program has more than one part
  22.         STREAMS=`echo $HTML | awk '
  23.         /a href="#" class="p-link js-player"/ {
  24.                 gsub( ".*data-argument=\"", "" );
  25.                 gsub( "\".*", "" );
  26.                 print;
  27.         }
  28.         ' RS="[<>]"`
  29.  
  30.         if [[ -z $STREAMS ]]; then
  31.                 # Only one part
  32.  
  33.                 STREAMS=`echo $HTML | awk '
  34.                 /div id="playerelement"/ {
  35.                         gsub( ".*data-media=\"", "" );
  36.                         gsub( "\".*", "" );
  37.                         print;
  38.                 }
  39.                 ' RS="[<>]"`
  40.  
  41.                 # If stream is unable to be found,
  42.                 # make the user use "stream"
  43.                 if [ -z $STREAMS ]; then
  44.                         echo -e "Unable to find the fucking stream..."
  45.                         echo "Program not available, or not valid...."
  46.                         exit 1
  47.                 fi
  48.                 PARTS=false
  49.         else
  50.                 # Several parts
  51.                 PARTS=true
  52.         fi
  53.  
  54.         for STREAM in $STREAMS ; do
  55.                 # Make sure it is HLS, not flash
  56.                 # if it is flash, change url to HLS
  57.                 if [[ $STREAM == *manifest.f4m ]]; then
  58.                         #Replacing char(s)
  59.                         STREAM=`echo $STREAM | sed -e 's/z/i/g'`
  60.                         STREAM=`echo $STREAM | sed -e 's/manifest.f4m/master.m3u8/g'`
  61.                 fi
  62.  
  63.                 # See if the stream is the master playlist
  64.                 if [[ "$STREAM" == *master.m3u8 ]]; then
  65.                         STREAM=`echo $STREAM | sed -e "s/master.m3u8/index_4_av.m3u8/g"`
  66.  
  67.                 fi
  68.                 echo -e "\e[01;32mStream url:\e[00m"
  69.                 echo "${STREAM}"
  70.         done
  71.  
  72. }
  73.  
  74.  
  75. URL=$1
  76.  
  77. getStream $URL
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top