Plugin develop problem (1 Viewer)

sax

Portal Member
March 26, 2010
41
2
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:
    <Site name="Videoteka NOVA" util="NovaTV" agecheck="false" enabled="true" lang="hr">
      <Configuration>
        <item key="dynamicCategoriesRegEx"><![CDATA[]]></item>
        <item key="dynamicCategoryUrlDecoding"><![CDATA[False]]></item>
        <item key="dynamicSubCategoryUrlDecoding"><![CDATA[False]]></item>
        <item key="videoListRegEx"><![CDATA[\<div\sclass="thumb"\>.*?\<div\sclass="img"\>.*?\<img\ssrc="(?<imageUrl>[^"]+).*?\<h2\>\<a\shref="(?<VideoUrl>[^"]+)"\>(?<Title>[^<]+)]]></item>
        <item key="videoUrlDecoding"><![CDATA[False]]></item>
        <item key="nextPageRegEx"><![CDATA[\<span\sclass='next'\>\<a\shref='(?<NextUrl>[^']+)]]></item>
        <item key="nextPageRegExUrlDecoding"><![CDATA[False]]></item>
        <item key="prevPageRegEx"><![CDATA[\<span\sclass='previous'\>\<a\shref='(?<PreviousUrl>[^']+)]]></item>
        <item key="prevPageRegExUrlDecoding"><![CDATA[False]]></item>
        <item key="baseUrl"><![CDATA[http://videoteka.novatv.hr]]></item>
        <item key="forceUTF8Encoding"><![CDATA[True]]></item>
      </Configuration>
      <Categories>
        <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>
        <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>
        <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>
        <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>
        <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>
        <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>
        <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>
        <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>
        <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>
      </Categories>
    </Site>

I create NovaTVUtil.cs class and added to the OnlineVideos\SiteUtilProjects\OnlineVideos.Sites.hioctane and build project.

Class NovaTVUtil.cs:

Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;

namespace OnlineVideos.Sites
{
    
    public class NovaTVUtil : GenericSiteUtil
    {
        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>[^']+)";
        private string URLFile_regEx = @"\<item\stype="".*?src=""(?<FileUrl>[^""]+).*?server=""(?<FileServer>[^""]+)";
        private Regex regEx_URL;
        private Regex regEx_URLFile;

        private string ut_section_id;
        private string media_id;
        private string site_id;
        private string section_id;

        private string FileUrl;
        private string FileServer;

 }
        }

        public override String getUrl(VideoInfo video)
        {
            string data = GetWebData(video.VideoUrl);
            regEx_URL = new Regex(URL_regEx, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
            Match m = regEx_URL.Match(data);

            if (m.Success)
            {
                ut_section_id = m.Groups["ut_section_id"].Value;
                media_id = m.Groups["media_id"].Value;
                site_id = m.Groups["site_id"].Value;
                section_id = m.Groups["section_id"].Value;
            }

            data = GetWebData("http://dnevnik.hr/bin/player/?mod=serve&site_id=" + site_id + "&media_id=" + media_id +
                "&userad_id=&section_id=" + section_id);
            regEx_URLFile = new Regex(URLFile_regEx, RegexOptions.Compiled | RegexOptions.CultureInvariant | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace | RegexOptions.Singleline);
            m = regEx_URLFile.Match(data);

            if (m.Success)
            {
                FileUrl = m.Groups["FileUrl"].Value;
                FileServer = m.Groups["FileServer"].Value;
                data = "http://vid" + FileServer + ".dnevnik.hr/" + FileUrl + "-" + FileServer + ".flv";
            }
            return data;
        }
    }
}

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
 

doskabouter

Development Group
  • Team MediaPortal
  • September 27, 2009
    4,566
    2,938
    Nuenen
    Home Country
    Netherlands Netherlands
    When you open the urls that are used (in the getUrl method) in f.e. notepad, do they work correctly?
     

    sax

    Portal Member
    March 26, 2010
    41
    2
    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:
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.IO;
    
    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                string url=textBox2.Text;
                textBox1.Text="";
                HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
                //request.UserAgent = OnlineVideoSettings.USERAGENT;
                request.Accept = "*/*";
                request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip,deflate");
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                Stream responseStream;
                if (response.ContentEncoding.ToLower().Contains("gzip"))
                    responseStream = new System.IO.Compression.GZipStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                else if (response.ContentEncoding.ToLower().Contains("deflate"))
                    responseStream = new System.IO.Compression.DeflateStream(response.GetResponseStream(), System.IO.Compression.CompressionMode.Decompress);
                else
                    responseStream = response.GetResponseStream();
                Encoding encoding = Encoding.UTF8;
                encoding = Encoding.GetEncoding(response.CharacterSet.Trim(new char[] { ' ', '"' }));
                using (StreamReader reader = new StreamReader(responseStream, encoding, true))
                {
                    string str = reader.ReadToEnd().Trim();
                    textBox1.Text = str;
                }
                
            }
        }
    }
     

    doskabouter

    Development Group
  • Team MediaPortal
  • September 27, 2009
    4,566
    2,938
    Nuenen
    Home Country
    Netherlands Netherlands
    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?
     

    sax

    Portal Member
    March 26, 2010
    41
    2
    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:
    \<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
     

    offbyone

    Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    Don't do
    Code:
    .*
    It matches too much and will most likely kill the regex engine, thus the timeout. Do the negative match instead:
    Code:
    [^<]+<img
     

    sax

    Portal Member
    March 26, 2010
    41
    2
    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
     

    offbyone

    Development Group
  • Team MediaPortal
  • April 26, 2008
    3,989
    3,712
    Stuttgart
    Home Country
    Germany Germany
    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.
     

    cane

    MP Donator
  • Premium Supporter
  • October 20, 2007
    129
    48
    Zagreb
    Home Country
    Croatia Croatia
    sax
    Would be awesome if manage to make it work.
     

    Users who are viewing this thread

    Top Bottom