xbmc / Official-Kodi-Remote-iOS

Full-featured remote control for XBMC Media Center. It features library browsing, now playing informations and a direct remote control.
Other
222 stars 104 forks source link

TF Feedback: bbcode not processed #369

Closed kambala-decapitator closed 1 year ago

kambala-decapitator commented 3 years ago

[B]-Tag from youtube display instead bold text.

@wutschel please check (dunno if you're subscribed to all new issues, that's why I ping you). Maybe that's not something Remote should take care of?

wutschel commented 3 years ago

I am following the new issues. For now I will not look into this topic, but if you have an idea how to solve this, don't hold back and share it. :)

kambala-decapitator commented 3 years ago

no idea where Youtube is even coming from. Is it an add-on?

wutschel commented 3 years ago

Yes, this is an Add-on.

wutschel commented 3 years ago

Should this be kept open? I am not planning to introduce handling BB code in the App.

wutschel commented 2 years ago

I guess this is again what was raised in an App review for version 1.10.1 (related to color codes shown).

kambala-decapitator commented 2 years ago

I guess this is again what was raised in an App review for version 1.10.1 (related to color codes shown).

I think you're right, as that feedback starts making sense in this context. Let's reopen.

wutschel commented 2 years ago

The code which needs to be changed is in DetailViewController.m in method (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath. -> title.text = item[@"label"];.

item[@"label"] needs to be processed into an attributed text and then handed over into something like title.attributedText = attributedText;. I gave it a try with html code and found it generally working. But I am not finding any good solution for the BBCode.

@kambala-decapitator: Can you help with this?

kambala-decapitator commented 2 years ago

I'd rather just strip BBCode tags with a regex or plain string search.

list of tags: https://www.bbcode.org/reference.php

but where are those strings coming from? the YT add-on or YT API?

wutschel commented 2 years ago

list of tags: https://www.bbcode.org/reference.php

Quite a long list. And as I am not sure what tags to support, I would need to go for all of them. Any recommended library we could use?

but where are those strings coming from? the YT add-on or YT API?

I don't know. But the last review/report in AppStore was not pointing to YouTube, so I assume this is also happening for other add-ons. Is the BBCode possibly added by Kodi when sharing the text via the API?

wutschel commented 2 years ago

I found something else in the code: In SettingsValuesViewController (which implements the Kodi UI settings) there are two lines of code which remove [B] and [/B] from the setting's description. So possibly even Kodi itself provides or provided in older versions such BBCode texts in few menus.

Could such bb code or html also come from scrapers?

kambala-decapitator commented 2 years ago

Quite a long list. And as I am not sure what tags to support, I would need to go for all of them. Any recommended library we could use?

you don't need to know the exact list to strip tags, I can write you an algorithm (in words) if you need guidance. Not aware of such libraries, but you could search.

If you don't wish to implement this at all, I can do then :)

Could such bb code or html also come from scrapers?

might be possible. You could also ask on the Kodi forums, maybe someone knows.

wutschel commented 2 years ago

If you don't wish to implement this at all, I can do then :)

That would be great. Your approach would be a method to convert BB code to html? Can this also cover the font type, color and size? From there it can be handled with existing iOS functionality as far as I can see.

wutschel commented 2 years ago

Very first and basic implementation: https://github.com/wutschel/Official-Kodi-Remote-iOS/commit/bdbe484a36dd9ffdae6cf0add4c55d0d6d55c43d.

Will show YouTube's first menu entry as bold -- which was the trigger for this issue. Will ignore html font colors to keep control over the colors (needed for Light/Dark Mode). Will maintain font family and size of the label.

kambala-decapitator commented 2 years ago

Your approach would be a method to convert BB code to html?

no, I'll simply strip the tags. Covering all possible tags for styling would be tedious.

Also, don't see a reason to convert to HTML first if you can apply styling to NSAttributedString directly. Actually, we can add support for a few basic tags like BIU and ignore all the rest.

wutschel commented 2 years ago

Agreed, keeping only BIU sounds reasonable. Yesterday I was playing with html/bb and figured I cannot allow to let colors/fonts be defined by bb/html as this conflicts with the Light/Dark setting and the layout in general.

But the bb/html code for this should be removed and only the text kept. For html this will work anyway, but for bb code this needs dedicated work for e.g. font colors, hyperlinks, etc.

Edit: To avoid getting into trouble when e.g.<h1>text</h1> headings are used which do not fit into the layout, we could decide to skip attributed text completely and simply use the string portion of the decoded html (attributedText.string). This simplifies the code a lot and still removes the html code. Only this is left:

// Generate an attributed string from the HTML
NSDictionary *options = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType};
NSAttributedString *attributedText = [[NSAttributedString alloc] initWithData:[text dataUsingEncoding:NSUTF8StringEncoding] options:options documentAttributes:NULL error:NULL];

// Set the string portion of attributedText to the text property of the UILabel
label.text = attributedText.string;
wutschel commented 1 year ago

Quite fast and stripping off all non-empty "<>" and "[]" brackets. Downside: Also things like "[OST]", "[2001]" or "[feat. Elvis]" would be removed.

(NSString*)stripRegEx:(NSString*)regExp text:(NSString*)textIn {
    NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regExp options:0 error:NULL];
    NSString *textOut = [regex stringByReplacingMatchesInString:textIn options:0 range:NSMakeRange(0, [textIn length]) withTemplate:@""];
    return textOut;
}

+ (NSString*)stripBBandHTML:(NSString*)text {
    NSString *textOut = text;

    // Strip html, non-empty <> brackets
    textOut = [Utilities stripRegEx:@"<[^>]+>" text:text];

    // Strip BB code, non-empty [] brackets
    textOut = [Utilities stripRegEx:@"\\[[^\\]]+\\]" text:textOut];

    //NSLog(@"%@ >> '%@'", text, textOut);
    return textOut;
}

Of course it is also possible to always scan for matches like "bla" and only keep bla. In this case I would need to run loops to handle nested commands.

wutschel commented 1 year ago

More targeted to towards real BB code is the following. This will keep the examples from my last post untouched.

// Strip BB code, [x] [/x], whereas x = b,u,i,s,center,url,img and spaces
textOut = [Utilities stripRegEx:@"\\[[\\s|/|b|u|i|s|center|url|img]+\\]" text:textOut];

// Strip BB code, [x=anything] [/x], whereas x = font,size,color,url and spaces
textOut = [Utilities stripRegEx:@"\\[[\\s|/|font|size|color|url]+[^\\]]+\\]" text:textOut];