Plugin develop problem (1 Viewer)

sax

Portal Member
March 26, 2010
41
2
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
    3,562
    1,779
    Nuenen
    Netherlands Netherlands
    Country flag
    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
    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
    3,562
    1,779
    Nuenen
    Netherlands Netherlands
    Country flag
    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
    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,981
    3,703
    Stuttgart
    Germany Germany
    Country flag
    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
    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,981
    3,703
    Stuttgart
    Germany Germany
    Country flag
    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
    Croatia Croatia
    sax
    Would be awesome if manage to make it work.
     

    Users Who Are Viewing This Thread (Users: 0, Guests: 1)

    OP Similar threads Forum Replies Date
    morpheus_xx [WiP] "What's New" plugin for MP2 upgrades MediaPortal 2 5
    da3dsoul [Request] An MVP Plugin example for custom settings in MP2 Plugin Development 2
    da3dsoul MP2 Plugin - Getting Started (Directory Tree and Player) Plugin Development 27
    M Installing Plugins Newcomers Forum 2
    joecrow 1.25.0 Radio Time plugin fails after Resume from Sleep with MP 1.25 Bugreports 4
    P MP2: US user, OTA - can NOT get SchedulesDirect plugin to work on MP1 or MP2 --> how do I get OTA schedule? General 5
    E aktuelle englische Forums Webseite von - Showtime Plugin v3 Plugins & Erweiterungen 4
    mrmojo666 [Tv Server Plugin ]Direct Show Video Control Plugin 0.0.0.1 for Hauppauge PVR cards MediaPortal 1 Plugins 0
    joecrow MultiShortcut Plugin (Uavailable) in DWHD skin General Support 58
    vapourEyes Building TV Plugin General Development (no feature request here!) 49
    Golf4 Nach Windows-Updates läuft TV-Plugin nicht mehr Allgemeines Support- und Diskussionsforum 0
    joecrow How about a Launcher plugin for MP1? MediaPortal 1 6
    D [solved] TVServer Plugin must be missing something. General Development (no feature request here!) 1
    framug Nouveau plugin XmlTvFR pour récupérer le guide télé français Kazer / ZguideTv (WebEPGfr) 11
    emphatic Allow remote control mapping of all plugins Improvement Suggestions 0
    D Where should plugins be located on hard drive? General Support 0
    D how to disengage from one version of a plugin to use another Newcomers Forum 0
    cbr954rr How to disable a pre-configured plugin? General 2
    mrmojo666 [Plugin]Marantz Control Plugin 0.0.0.2 MediaPortal 1 Plugins 2
    mrmojo666 beginner: trying to write a plugin, need help to catch event General Development (no feature request here!) 3
    framug [Rejected] Fix PowerScheduler plugin for MP2 single seat Submit: Code Patches 9
    doskabouter [Question] Stale plugins Developer Discussions 9
    M MP1 stops responding after Starting Plugins General Support 14
    Terra LAVFilter Plugin cannot be updated (MP1.23) MediaPortal 1 Plugins 10
    L Mediaportal 1.21 and Windows 10: user schedules de-activated when powerscheduler plugin is selected General Support 1
    Similar threads

























    Top Bottom