Plugin develop problem

Discussion in 'OnlineVideos' started by sax, May 14, 2010.

  1. sax

    sax Portal Member

    Joined:
    March 26, 2010
    Messages:
    41
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    Slovenia Slovenia
    I want to make a plugin for Nova TV (Naslovnica - NOVA TV).
    I added the following items in OnlineVideoSites.xml .

    Code (Text):
    1.     <Site name="Videoteka NOVA" util="NovaTV" agecheck="false" enabled="true" lang="hr">
    2.       <Configuration>
    3.         <item key="dynamicCategoriesRegEx"><![CDATA[]]></item>
    4.         <item key="dynamicCategoryUrlDecoding"><![CDATA[False]]></item>
    5.         <item key="dynamicSubCategoryUrlDecoding"><![CDATA[False]]></item>
    6.         <item key="videoListRegEx"><![CDATA[\<div\sclass="thumb"\>.*?\<div\sclass="img"\>.*?\<img\ssrc="(?<imageUrl>[^"]+).*?\<h2\>\<a\shref="(?<VideoUrl>[^"]+)"\>(?<Title>[^<]+)]]></item>
    7.         <item key="videoUrlDecoding"><![CDATA[False]]></item>
    8.         <item key="nextPageRegEx"><![CDATA[\<span\sclass='next'\>\<a\shref='(?<NextUrl>[^']+)]]></item>
    9.         <item key="nextPageRegExUrlDecoding"><![CDATA[False]]></item>
    10.         <item key="prevPageRegEx"><![CDATA[\<span\sclass='previous'\>\<a\shref='(?<PreviousUrl>[^']+)]]></item>
    11.         <item key="prevPageRegExUrlDecoding"><![CDATA[False]]></item>
    12.         <item key="baseUrl"><![CDATA[http://videoteka.novatv.hr]]></item>
    13.         <item key="forceUTF8Encoding"><![CDATA[True]]></item>
    14.       </Configuration>
    15.       <Categories>
    16.         <Category xsi:type="RssLink" name="Informativne emisije ">http://videoteka.novatv.hr/pretraga?group=false&amp;go=Search&amp;keyword=&amp;date=&amp;parent_id=4&amp;channel=&amp;sbmt=Pretraga</Category>
    17.         <Category xsi:type="RssLink" name="Serije ">http://videoteka.novatv.hr/pretraga?group=false&amp;go=Search&amp;keyword=&amp;date=&amp;parent_id=6&amp;channel=&amp;sbmt=Pretraga</Category>
    18.         <Category xsi:type="RssLink" name="Mini TV ">http://videoteka.novatv.hr/pretraga?group=false&amp;go=Search&amp;keyword=&amp;date=&amp;parent_id=485&amp;channel=&amp;sbmt=Pretraga</Category>
    19.         <Category xsi:type="RssLink" name="Sport.dnevnik.hr">http://videoteka.novatv.hr/pretraga?type_id=27274&amp;parent_id=27274&amp;group=true&amp;order=date</Category>
    20.         <Category xsi:type="RssLink" name="Dnevnik.hr">http://videoteka.novatv.hr/pretraga?type_id=27263&amp;parent_id=27263&amp;group=true&amp;order=date</Category>
    21.         <Category xsi:type="RssLink" name="Zadovoljna.com.hr">http://videoteka.novatv.hr/pretraga?type_id=27270&amp;parent_id=27270&amp;group=true&amp;order=date</Category>
    22.         <Category xsi:type="RssLink" name="Showbizz">http://videoteka.novatv.hr/pretraga?type_id=30924&amp;parent_id=30924&amp;group=true&amp;order=date</Category>
    23.         <Category xsi:type="RssLink" name="Emisije i magazini ">http://videoteka.novatv.hr/pretraga?group=false&amp;go=Search&amp;keyword=&amp;date=&amp;parent_id=40878&amp;channel=&amp;sbmt=Pretraga</Category>
    24.         <Category xsi:type="RssLink" name="Svi videi ">http://videoteka.novatv.hr/pretraga?group=false&amp;go=Search&amp;keyword=&amp;date=&amp;parent_id=&amp;channel=&amp;sbmt=Pretraga</Category>
    25.       </Categories>
    26.     </Site>
    I create NovaTVUtil.cs class and added to the OnlineVideos\SiteUtilProjects\OnlineVideos.Sites.hioctane and build project.



    Class NovaTVUtil.cs:

    Code (Text):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Text;
    4. using System.Text.RegularExpressions;
    5.  
    6. namespace OnlineVideos.Sites
    7. {
    8.    
    9.     public class NovaTVUtil : GenericSiteUtil
    10.     {
    11.         private string URL_regEx = @"//user\strack\svariables.*?var\sut_section_id\s=\s""(?<ut_section_id>[^""]+).*?var\smedia_id\s=\s""(?<media_id>[^""]+).*?var\ssite_id\s=\s""(?<site_id>[^""]+).*?var\ssection_id\s=\s'(?<section_id>[^']+)";
    12.         private string URLFile_regEx = @"\<item\stype="".*?src=""(?<FileUrl>[^""]+).*?server=""(?<FileServer>[^""]+)";
    13.         private Regex regEx_URL;
    14.         private Regex regEx_URLFile;
    15.  
    16.         private string ut_section_id;
    17.         private string media_id;
    18.         private string site_id;
    19.         private string section_id;
    20.  
    21.         private string FileUrl;
    22.         private string FileServer;
    23.  
    24.  }
    25.         }
    26.  
    27.         public override String getUrl(VideoInfo video)
    28.         {
    29.             string data = GetWebData(video.VideoUrl);
    30.             regEx_URL = new Regex(URL_regEx, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
    31.             Match m = regEx_URL.Match(data);
    32.  
    33.             if (m.Success)
    34.             {
    35.                 ut_section_id = m.Groups["ut_section_id"].Value;
    36.                 media_id = m.Groups["media_id"].Value;
    37.                 site_id = m.Groups["site_id"].Value;
    38.                 section_id = m.Groups["section_id"].Value;
    39.             }
    40.  
    41.             data = GetWebData("http://dnevnik.hr/bin/player/?mod=serve&site_id=" + site_id + "&media_id=" + media_id +
    42.                 "&userad_id=&section_id=" + section_id);
    43.             regEx_URLFile = new Regex(URLFile_regEx, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
    44.             m = regEx_URLFile.Match(data);
    45.  
    46.             if (m.Success)
    47.             {
    48.                 FileUrl = m.Groups["FileUrl"].Value;
    49.                 FileServer = m.Groups["FileServer"].Value;
    50.                 data = "http://vid" + FileServer + ".dnevnik.hr/" + FileUrl + "-" + FileServer + ".flv";
    51.             }
    52.             return data;
    53.         }
    54.     }
    55. }
    When I run plugin, and select a video, function GetWebData (video.VideoUrl) returns me an error "The operation has timed out" and a popup message box: Error getting video playback from urls!
    In function getUrl (VideoInfo video) I get a regula video parameter (eg "http://videoteka.novatv.hr/multimedia/vijesti-nove-tv-459.html")
    Plugin sometimes works normally and display video, but mostly returns an error

    The error occurs in the class OnlineVideos\Plugin\Gui2UtilConnector.cs, in function Internal bool ExecuteInBackgroundAndWait (ThreadStart task, string taskdescription).

    Can anyone help me?

    THX SaX
     
  2. Google AdSense Guest Advertisement



    to hide all adverts.
  3. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,796
    Likes Received:
    752
    Location:
    Nuenen
    Ratings:
    +1,115 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
    When you open the urls that are used (in the getUrl method) in f.e. notepad, do they work correctly?
     
  4. sax

    sax Portal Member

    Joined:
    March 26, 2010
    Messages:
    41
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    Slovenia Slovenia
    What do you think with f.e. notepad?
    I've created a separate project, form with button and 2 textbox for testing HttpWebResponse function and work OK, but in onlinevideos plugin returns me an error "The operation has timed out".

    Code (Text):
    1. using System;
    2. using System.Collections.Generic;
    3. using System.ComponentModel;
    4. using System.Data;
    5. using System.Drawing;
    6. using System.Linq;
    7. using System.Text;
    8. using System.Windows.Forms;
    9. using System.Net;
    10. using System.IO;
    11.  
    12. namespace WindowsFormsApplication1
    13. {
    14.     public partial class Form1 : Form
    15.     {
    16.         public Form1()
    17.         {
    18.             InitializeComponent();
    19.         }
    20.  
    21.         private void button1_Click(object sender, EventArgs e)
    22.         {
    23.             string url=textBox2.Text;
    24.             textBox1.Text="";
    25.             HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
    26.             //request.UserAgent = OnlineVideoSettings.USERAGENT;
    27.             request.Accept = "*/*";
    28.             request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
    29.             HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    30.             Stream responseStream;
    31.             if (response.ContentEncoding.ToLower().Contains("gzip"))
    32.                 responseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
    33.             else if (response.ContentEncoding.ToLower().Contains("deflate"))
    34.                 responseStream = new System.IO.Compression.DeflateStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
    35.             else
    36.                 responseStream = response.GetResponseStream();
    37.             Encoding encoding = Encoding.UTF8;
    38.             encoding = Encoding.GetEncoding(response.CharacterSet.Trim(new char[] { ' ', '"' }));
    39.             using (StreamReader reader = new StreamReader(responseStream, encoding, true))
    40.             {
    41.                 string str = reader.ReadToEnd().Trim();
    42.                 textBox1.Text = str;
    43.             }
    44.            
    45.         }
    46.     }
    47. }
    48.  
     
  5. doskabouter
    • Premium Supporter

    doskabouter Community Plugin Dev

    Joined:
    September 27, 2009
    Messages:
    2,796
    Likes Received:
    752
    Location:
    Nuenen
    Ratings:
    +1,115 / 1
    Home Country:
    Netherlands Netherlands
    Show System Specs
    Well, I mostly use notepad to check if the url's are valid and don't require cookies/referrers/other options to get the html-results.
    Do you know which call to getwebdata results in the time-out? Note that when debugging the time-out should not occur because it's set to infinite.

    Are those time-outs easily reproducable, and always with the same video's?
     
  6. sax

    sax Portal Member

    Joined:
    March 26, 2010
    Messages:
    41
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    Slovenia Slovenia
    Thanks for the tip.

    I figured out that the problem is not in function GetWebData or in his url paramether.
    The problem is in videoListRegEx regular expression.
    If I change videoListRegEx to something else and in GetWebData ("http://videoteka.novatv.hr/multimedia/vijesti-nove-tv-456.html") give a fixed url address, then works OK.

    So, now i have to discover what is wrong with this
    Code (Text):
    1. \<div\sclass="thumb"\>.*?\<div\sclass="img"\>.*?\<img\ssrc="(?<imageUrl>[^"]+).*?\<h2\>\<a\shref="(?<VideoUrl>[^"]+)"\>(?<Title>[^<]+)
    regular expression if I use it on page Informativne emisije - NOVA TV
     
  7. offbyone
    • Team MediaPortal

    offbyone Development Group

    Joined:
    April 26, 2008
    Messages:
    3,981
    Likes Received:
    2,704
    Gender:
    Male
    Location:
    Stuttgart
    Ratings:
    +3,303 / 3
    Home Country:
    Germany Germany
    Show System Specs
    Don't do
    Code (Text):
    1. .*
    It matches too much and will most likely kill the regex engine, thus the timeout. Do the negative match instead:
    Code (Text):
    1. [^<]+<img
     
  8. sax

    sax Portal Member

    Joined:
    March 26, 2010
    Messages:
    41
    Likes Received:
    2
    Ratings:
    +2 / 0
    Home Country:
    Slovenia Slovenia
    Can you give me an example on this RegEx:
    \<div\sclass="thumb"\>.*?\<div\sclass="img"\>.*?\<img\ssrc="(?<imageUrl>[^"]+).*?\<h2\>\<a\shref="(?<VideoUrl>[^"]+)"\>(?<Title>[^<]+)


    html page:
    Informativne emisije - NOVA TV
     
  9. offbyone
    • Team MediaPortal

    offbyone Development Group

    Joined:
    April 26, 2008
    Messages:
    3,981
    Likes Received:
    2,704
    Gender:
    Male
    Location:
    Stuttgart
    Ratings:
    +3,303 / 3
    Home Country:
    Germany Germany
    Show System Specs
    Just match all that's inside the thumb div. Instead of the .* match the <a[^>]*> and so on (There's two a with each in img inside). I hope you are using some regex helper tool to test your regex easily.
     
  10. cane
    • Premium Supporter

    cane MP Donator

    Joined:
    October 20, 2007
    Messages:
    129
    Likes Received:
    24
    Location:
    Zagreb
    Ratings:
    +26 / 0
    Home Country:
    Croatia Croatia
    Show System Specs
    sax
    Would be awesome if manage to make it work.
     
  11. SilentException
    • Premium Supporter

    SilentException Retired Team Member

    Joined:
    October 27, 2008
    Messages:
    2,617
    Likes Received:
    1,125
    Gender:
    Male
    Location:
    Rijeka, Croatia
    Ratings:
    +1,129 / 0
    Home Country:
    Croatia Croatia
Loading...

Users Viewing Thread (Users: 0, Guests: 0)

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice
  • About The Project

    The vision of the MediaPortal project is to create a free open source media centre application, which supports all advanced media centre functions, and is accessible to all Windows users.

    In reaching this goal we are working every day to make sure our software is one of the best.

             

  • Support MediaPortal!

    The team works very hard to make sure the community is running the best HTPC-software. We give away MediaPortal for free but hosting and software is not for us.

    Care to support our work with a few bucks? We'd really appreciate it!