Skip to content

Re-introduce content language for YouTube #257

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -166,14 +166,13 @@ public CommentsExtractor getCommentsExtractor(ListLinkHandler urlIdHandler)

// https://www.youtube.com/picker_ajax?action_language_json=1
private static final List<Localization> SUPPORTED_LANGUAGES = Localization.listFrom(
"en-GB"
/*"af", "am", "ar", "az", "be", "bg", "bn", "bs", "ca", "cs", "da", "de",
"af", "am", "ar", "az", "be", "bg", "bn", "bs", "ca", "cs", "da", "de",
"el", "en", "en-GB", "es", "es-419", "es-US", "et", "eu", "fa", "fi", "fil", "fr",
"fr-CA", "gl", "gu", "hi", "hr", "hu", "hy", "id", "is", "it", "iw", "ja",
"ka", "kk", "km", "kn", "ko", "ky", "lo", "lt", "lv", "mk", "ml", "mn",
"mr", "ms", "my", "ne", "nl", "no", "pa", "pl", "pt", "pt-PT", "ro", "ru",
"si", "sk", "sl", "sq", "sr", "sr-Latn", "sv", "sw", "ta", "te", "th", "tr",
"uk", "ur", "uz", "vi", "zh-CN", "zh-HK", "zh-TW", "zu"*/
"uk", "ur", "uz", "vi", "zh-CN", "zh-HK", "zh-TW", "zu"
);

// https://www.youtube.com/picker_ajax?action_country_json=1
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
package org.schabi.newpipe.extractor.services.youtube.extractors;

import java.util.HashMap;

public class YoutubeAbbreviationSubCountMap {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add a JavaDoc for this class?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about the class name, too. I assume that these abbreviations can be used by other services, too. Is this correct? If yes, please move this file to the extractor utils.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it can be used if one wants to parse abbreviations from languages (and if some are missing for a service, it can easily be added).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the JavaDoc good?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, looks good. however, the class is not a map. we should rename it and change that part in the doc, too.


//should be safe until someone has 1 billion subscribers on YouTube
public static final HashMap<String, String> abbreviationSubscribersCount = new HashMap<>();
public static String englishMillionAbbreviation = "M";
public static String englishThousandAbbreviation = "K";
public static String tenThousandAbbreviation = "万";
public static String hundredThousandAbbreviation = "ল";
public static String tenMillionAbbreviation = "ক";
public static String hundredMillionAbbreviation = "億";

static {
abbreviationSubscribersCount.put(englishThousandAbbreviation, englishThousandAbbreviation); //az, iw, en
abbreviationSubscribersCount.put(englishMillionAbbreviation, englishMillionAbbreviation); //iw, en
abbreviationSubscribersCount.put(tenThousandAbbreviation, tenThousandAbbreviation);
abbreviationSubscribersCount.put(hundredMillionAbbreviation, hundredMillionAbbreviation);
abbreviationSubscribersCount.put(tenMillionAbbreviation, tenMillionAbbreviation);
abbreviationSubscribersCount.put(hundredMillionAbbreviation, hundredMillionAbbreviation);

abbreviationSubscribersCount.put(" k", englishThousandAbbreviation); //af
abbreviationSubscribersCount.put(" m", englishMillionAbbreviation); //af, is
abbreviationSubscribersCount.put(" ሺ", englishThousandAbbreviation); //am
abbreviationSubscribersCount.put(" ሜትር", englishMillionAbbreviation); //am
abbreviationSubscribersCount.put(" ألف", englishThousandAbbreviation); //ar
abbreviationSubscribersCount.put(" مليون", englishMillionAbbreviation); //ar
abbreviationSubscribersCount.put(" mln", englishMillionAbbreviation); //az, et, lt, nl, pl, sq, uz
abbreviationSubscribersCount.put(" тыс", englishThousandAbbreviation); //be, ru
abbreviationSubscribersCount.put(" млн", englishMillionAbbreviation); //be, bg, kk, ky, ru, uk
abbreviationSubscribersCount.put(" хил", englishThousandAbbreviation); //bg
abbreviationSubscribersCount.put(" হা", englishThousandAbbreviation); //bn
abbreviationSubscribersCount.put(" hilj", englishThousandAbbreviation); //bs, sr
abbreviationSubscribersCount.put(" mil", englishMillionAbbreviation); //bs, cs, hr, ro, sk, sr-Latn
abbreviationSubscribersCount.put("m", englishThousandAbbreviation); //ca
abbreviationSubscribersCount.put(" M", englishMillionAbbreviation); //ca, es, eu, and many more
abbreviationSubscribersCount.put(" tis", englishThousandAbbreviation); //cs, hr, sk, sl
abbreviationSubscribersCount.put(" mio", englishMillionAbbreviation); //da, sl
abbreviationSubscribersCount.put(" Mio", englishMillionAbbreviation); //de
abbreviationSubscribersCount.put(" χιλ", englishThousandAbbreviation); //el
abbreviationSubscribersCount.put(" εκ", englishMillionAbbreviation); //el
abbreviationSubscribersCount.put(" tuh", englishThousandAbbreviation); //et
abbreviationSubscribersCount.put(" هزار", englishThousandAbbreviation); //fa
abbreviationSubscribersCount.put(" میلیون", englishMillionAbbreviation); //fa
abbreviationSubscribersCount.put(" t", englishThousandAbbreviation); //fi
abbreviationSubscribersCount.put(" milj", englishMillionAbbreviation); //fi, lv
abbreviationSubscribersCount.put(" હજાર", englishThousandAbbreviation); //gu
abbreviationSubscribersCount.put(" हज़ार", englishThousandAbbreviation); //hi
abbreviationSubscribersCount.put(" E", englishThousandAbbreviation); //hu
abbreviationSubscribersCount.put(" հզր", englishThousandAbbreviation); //hy
abbreviationSubscribersCount.put(" մլն", englishMillionAbbreviation); //hy
abbreviationSubscribersCount.put(" rb", englishThousandAbbreviation); //id
abbreviationSubscribersCount.put(" jt", englishMillionAbbreviation); //id
abbreviationSubscribersCount.put(" þ", englishThousandAbbreviation); //is
abbreviationSubscribersCount.put(" Mln", englishMillionAbbreviation); //it
abbreviationSubscribersCount.put(" ათ", englishThousandAbbreviation); //ka
abbreviationSubscribersCount.put(" მლნ", englishMillionAbbreviation); //ka
abbreviationSubscribersCount.put(" мың", englishThousandAbbreviation); //kk
abbreviationSubscribersCount.put("ពាន់", englishThousandAbbreviation); //km
abbreviationSubscribersCount.put(" ពាន់", englishThousandAbbreviation); //km
abbreviationSubscribersCount.put(" លាន", englishMillionAbbreviation); //km
abbreviationSubscribersCount.put("ಸಾ", englishThousandAbbreviation); //kn
abbreviationSubscribersCount.put("ಮಿ", englishMillionAbbreviation); //kn
abbreviationSubscribersCount.put("천", englishThousandAbbreviation); //ko
abbreviationSubscribersCount.put(" миң", englishThousandAbbreviation); //ky
abbreviationSubscribersCount.put(" ກີບ", englishThousandAbbreviation); //lo
abbreviationSubscribersCount.put(" ພັນ", englishThousandAbbreviation); //lo
abbreviationSubscribersCount.put(" ລ້ານ", englishMillionAbbreviation); //lo
abbreviationSubscribersCount.put(" tūkst", englishThousandAbbreviation); //lt, lv
abbreviationSubscribersCount.put(" илј", englishThousandAbbreviation); //mk
abbreviationSubscribersCount.put(" мил", englishMillionAbbreviation); //mk, sr
abbreviationSubscribersCount.put(" мянга", englishThousandAbbreviation); //mn
abbreviationSubscribersCount.put(" сая", englishMillionAbbreviation); //mn
abbreviationSubscribersCount.put(" ह", englishThousandAbbreviation); //mr
abbreviationSubscribersCount.put("ထောင်", englishThousandAbbreviation); //my
abbreviationSubscribersCount.put("သန်း", englishMillionAbbreviation); //my
abbreviationSubscribersCount.put(" हजार", englishThousandAbbreviation); //ne
abbreviationSubscribersCount.put("k", englishThousandAbbreviation); //no
abbreviationSubscribersCount.put(" mill", englishMillionAbbreviation); //no
abbreviationSubscribersCount.put(" ਹਜ਼ਾਰ", englishThousandAbbreviation); //pa
abbreviationSubscribersCount.put(" tys", englishThousandAbbreviation); //pl
abbreviationSubscribersCount.put(" mi", englishMillionAbbreviation); //pt
abbreviationSubscribersCount.put(" K", englishThousandAbbreviation); //ro
abbreviationSubscribersCount.put("ද", englishThousandAbbreviation); //si
abbreviationSubscribersCount.put("මි", englishMillionAbbreviation); //si
abbreviationSubscribersCount.put(" mijë", englishThousandAbbreviation); //sq
abbreviationSubscribersCount.put(" хиљ", englishThousandAbbreviation); //sr-Latn
abbreviationSubscribersCount.put(" mn", englishMillionAbbreviation); //sv
abbreviationSubscribersCount.put("elfu ", englishThousandAbbreviation); //sw
abbreviationSubscribersCount.put("ஆ", englishThousandAbbreviation); //ta
abbreviationSubscribersCount.put("மி", englishMillionAbbreviation); //ta
abbreviationSubscribersCount.put("వే", englishThousandAbbreviation); //te
abbreviationSubscribersCount.put("మి", englishMillionAbbreviation); //te
abbreviationSubscribersCount.put(" พัน", englishThousandAbbreviation); //th
abbreviationSubscribersCount.put(" ล้าน", englishMillionAbbreviation); //th
abbreviationSubscribersCount.put(" B", englishThousandAbbreviation); //tr
abbreviationSubscribersCount.put(" Mn", englishMillionAbbreviation); //tr
abbreviationSubscribersCount.put(" тис", englishThousandAbbreviation); //uk
abbreviationSubscribersCount.put(" ہزار", englishThousandAbbreviation); //ur
abbreviationSubscribersCount.put(" ming", englishThousandAbbreviation); //uz
abbreviationSubscribersCount.put(" N", englishThousandAbbreviation); //vi
abbreviationSubscribersCount.put(" Tr", englishMillionAbbreviation); //vi

abbreviationSubscribersCount.put("만", tenThousandAbbreviation); //ko
abbreviationSubscribersCount.put("万", tenThousandAbbreviation); //ja, zh-CN
abbreviationSubscribersCount.put("萬", tenThousandAbbreviation); //zh-TW

abbreviationSubscribersCount.put(" লা", hundredThousandAbbreviation); //bn
abbreviationSubscribersCount.put(" લાખ", hundredThousandAbbreviation); //gu
abbreviationSubscribersCount.put(" लाख", hundredThousandAbbreviation); //hi, mr, ne
abbreviationSubscribersCount.put(" ਲੱਖ", hundredThousandAbbreviation); //pa
abbreviationSubscribersCount.put(" لاکھ", hundredThousandAbbreviation); //ur
abbreviationSubscribersCount.put("သိန်း", hundredThousandAbbreviation); //my
abbreviationSubscribersCount.put(" แสน", hundredThousandAbbreviation); //th

abbreviationSubscribersCount.put(" কো", tenMillionAbbreviation); //bn
abbreviationSubscribersCount.put(" કરોડ", tenMillionAbbreviation); //gu
abbreviationSubscribersCount.put(" क॰", tenMillionAbbreviation); //hi
abbreviationSubscribersCount.put(" कोटी", tenMillionAbbreviation); //mr
abbreviationSubscribersCount.put("ကုဋေ", tenMillionAbbreviation); //my
abbreviationSubscribersCount.put(" करोड", tenMillionAbbreviation); //ne
abbreviationSubscribersCount.put(" ਕਰੋੜ", tenMillionAbbreviation); //pa
abbreviationSubscribersCount.put(" کروڑ", tenMillionAbbreviation); //ur

abbreviationSubscribersCount.put("億", hundredMillionAbbreviation); //ja, zh-TW
abbreviationSubscribersCount.put("억", hundredMillionAbbreviation); //ko
abbreviationSubscribersCount.put("亿", hundredMillionAbbreviation); //zh-CN

abbreviationSubscribersCount.put(" م", englishMillionAbbreviation); //an
abbreviationSubscribersCount.put("ሜ", englishMillionAbbreviation); //am
abbreviationSubscribersCount.put(" М", englishMillionAbbreviation); //mk, narrow non-breaking space, ie U+202F

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,27 @@
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.schabi.newpipe.extractor.NewPipe;
import org.schabi.newpipe.extractor.StreamingService;
import org.schabi.newpipe.extractor.channel.ChannelExtractor;
import org.schabi.newpipe.extractor.downloader.Downloader;
import org.schabi.newpipe.extractor.downloader.Response;
import org.schabi.newpipe.extractor.exceptions.ExtractionException;
import org.schabi.newpipe.extractor.exceptions.ParsingException;
import org.schabi.newpipe.extractor.exceptions.ReCaptchaException;
import org.schabi.newpipe.extractor.linkhandler.ListLinkHandler;
import org.schabi.newpipe.extractor.localization.Localization;
import org.schabi.newpipe.extractor.localization.TimeAgoParser;
import org.schabi.newpipe.extractor.services.youtube.linkHandler.YoutubeParsingHelper;
import org.schabi.newpipe.extractor.stream.StreamInfoItem;
import org.schabi.newpipe.extractor.stream.StreamInfoItemsCollector;
import org.schabi.newpipe.extractor.utils.Parser;
import org.schabi.newpipe.extractor.utils.Utils;

import javax.annotation.Nonnull;
import java.io.IOException;

import static org.schabi.newpipe.extractor.utils.Utils.mixedNumberWordToLong;

/*
* Created by Christian Schabesberger on 25.07.16.
*
Expand Down Expand Up @@ -50,6 +54,10 @@ public class YoutubeChannelExtractor extends ChannelExtractor {

private Document doc;

public Document getDoc() {
return doc;
}

public YoutubeChannelExtractor(StreamingService service, ListLinkHandler linkHandler) {
super(service, linkHandler);
}
Expand Down Expand Up @@ -81,7 +89,8 @@ public String getUrl() throws ParsingException {
public String getId() throws ParsingException {
try {
return doc.select("meta[itemprop=\"channelId\"]").first().attr("content");
} catch (Exception ignored) {}
} catch (Exception ignored) {
}

// fallback method; does not work with channels that have no "Subscribe" button (e.g. EminemVEVO)
try {
Expand Down Expand Up @@ -137,19 +146,18 @@ public String getFeedUrl() throws ParsingException {

@Override
public long getSubscriberCount() throws ParsingException {

long subCount = -1;
final Element el = doc.select("span[class*=\"yt-subscription-button-subscriber-count\"]").first();
if (el != null) {
// If the element is null, the channel have the subscriber count disabled
String elTitle = el.attr("title");
try {
return Utils.mixedNumberWordToLong(elTitle);
subCount = mixedNumberWordToLong(elTitle, getExtractorLocalization());
} catch (NumberFormatException e) {
throw new ParsingException("Could not get subscriber count", e);
}
} else {
// If the element is null, the channel have the subscriber count disabled
return -1;
}
return subCount;
}

@Override
Expand Down Expand Up @@ -196,7 +204,7 @@ public InfoItemsPage<StreamInfoItem> getPage(String pageUrl) throws IOException,
}

private String getNextPageUrlFromAjaxPage(final JsonObject ajaxJson, final String pageUrl)
throws ParsingException {
throws ParsingException {
String loadMoreHtmlDataRaw = ajaxJson.getString("load_more_widget_html");
if (!loadMoreHtmlDataRaw.isEmpty()) {
return getNextPageUrlFrom(Jsoup.parse(loadMoreHtmlDataRaw, pageUrl));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import static org.schabi.newpipe.extractor.utils.JsonUtils.getString;

/*
* Created by Christian Schabesberger on 06.08.15.
*
Expand Down Expand Up @@ -107,8 +109,7 @@ public YoutubeStreamExtractor(StreamingService service, LinkHandler linkHandler)
public String getName() throws ParsingException {
assertPageFetched();
try {
return playerResponse.getObject("videoDetails").getString("title");

return getString(playerResponse.getObject("microformat").getObject("playerMicroformatRenderer").getObject("title"), "simpleText");
} catch (Exception e) {
// fallback HTML method
String name = null;
Expand Down Expand Up @@ -183,12 +184,10 @@ public String getThumbnailUrl() throws ParsingException {
public Description getDescription() throws ParsingException {
assertPageFetched();
try {
// first try to get html-formatted description
return new Description(parseHtmlAndGetFullLinks(doc.select("p[id=\"eow-description\"]").first().html()), Description.HTML);
return new Description(getString(playerResponse.getObject("microformat").getObject("playerMicroformatRenderer").getObject("description"), "simpleText"), Description.PLAIN_TEXT);
} catch (Exception e) {
try {
// fallback to raw non-html description
return new Description(playerResponse.getObject("videoDetails").getString("shortDescription"), Description.PLAIN_TEXT);
return new Description(parseHtmlAndGetFullLinks(doc.select("p[id=\"eow-description\"]").first().html()), Description.HTML);
} catch (Exception ignored) {
throw new ParsingException("Could not get the description", e);
}
Expand Down
Loading